mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: show network stats for collaboration
This commit is contained in:
parent
1e17c1967b
commit
8157c84d11
6 changed files with 83 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
|||
// @ts-nocheck
|
||||
import { Point, simplify } from "points-on-curve";
|
||||
import React from "react";
|
||||
import { RoughCanvas } from "roughjs/bin/canvas";
|
||||
|
@ -182,6 +183,7 @@ import LayerUI from "./LayerUI";
|
|||
import { Stats } from "./Stats";
|
||||
import { Toast } from "./Toast";
|
||||
import { actionToggleViewMode } from "../actions/actionToggleViewMode";
|
||||
import { getNetworkSpeed } from "../networkStats";
|
||||
|
||||
const { history } = createHistory();
|
||||
|
||||
|
@ -461,6 +463,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
setAppState={this.setAppState}
|
||||
elements={this.scene.getElements()}
|
||||
onClose={this.toggleStats}
|
||||
isCollaborating={this.props.isCollaborating}
|
||||
/>
|
||||
)}
|
||||
{this.state.toastMessage !== null && (
|
||||
|
@ -845,6 +848,21 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
this.addEventListeners();
|
||||
}
|
||||
|
||||
if (
|
||||
prevState.showStats !== this.state.showStats ||
|
||||
prevProps.isCollaborating !== this.props.isCollaborating
|
||||
) {
|
||||
if (this.state.showStats && this.props.isCollaborating) {
|
||||
this.calculateNetStats();
|
||||
navigator.connection.addEventListener("change", this.calculateNetStats);
|
||||
} else {
|
||||
navigator.connection.removeEventListener(
|
||||
"change",
|
||||
this.calculateNetStats,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
document
|
||||
.querySelector(".excalidraw")
|
||||
?.classList.toggle("Appearance_dark", this.state.appearance === "dark");
|
||||
|
@ -970,6 +988,11 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
}
|
||||
}
|
||||
|
||||
private calculateNetStats = async () => {
|
||||
const speed = await getNetworkSpeed();
|
||||
const networkSpeed = speed === -1 ? "Error!" : speed;
|
||||
this.setState({ networkSpeed });
|
||||
};
|
||||
// Copy/paste
|
||||
|
||||
private onCut = withBatchedUpdates((event: ClipboardEvent) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue