dwelle 2 سال پیش
والد
کامیت
0fe79f8819
3فایلهای تغییر یافته به همراه21 افزوده شده و 8 حذف شده
  1. 1 1
      src/excalidraw-app/app_constants.ts
  2. 17 7
      src/excalidraw-app/collab/Collab.tsx
  3. 3 0
      src/excalidraw-app/collab/Portal.tsx

+ 1 - 1
src/excalidraw-app/app_constants.ts

@@ -7,7 +7,7 @@ export const SYNC_FULL_SCENE_INTERVAL_MS = 20000;
 export const SYNC_BROWSER_TABS_TIMEOUT = 50;
 export const SYNC_BROWSER_TABS_TIMEOUT = 50;
 export const CURSOR_SYNC_TIMEOUT = 33; // ~30fps
 export const CURSOR_SYNC_TIMEOUT = 33; // ~30fps
 export const DELETED_ELEMENT_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
 export const DELETED_ELEMENT_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
-export const PAUSE_COLLABORATION_TIMEOUT = 30000;
+export const PAUSE_COLLABORATION_TIMEOUT = 2000;
 export const RESUME_FALLBACK_TIMEOUT = 5000;
 export const RESUME_FALLBACK_TIMEOUT = 5000;
 
 
 export const FILE_UPLOAD_MAX_BYTES = 3 * 1024 * 1024; // 3 MiB
 export const FILE_UPLOAD_MAX_BYTES = 3 * 1024 * 1024; // 3 MiB

+ 17 - 7
src/excalidraw-app/collab/Collab.tsx

@@ -207,10 +207,13 @@ class Collab extends PureComponent<Props, CollabState> {
     window.removeEventListener(EVENT.BEFORE_UNLOAD, this.beforeUnload);
     window.removeEventListener(EVENT.BEFORE_UNLOAD, this.beforeUnload);
     window.removeEventListener(EVENT.UNLOAD, this.onUnload);
     window.removeEventListener(EVENT.UNLOAD, this.onUnload);
     window.removeEventListener(EVENT.POINTER_MOVE, this.onPointerMove);
     window.removeEventListener(EVENT.POINTER_MOVE, this.onPointerMove);
-    window.removeEventListener(
-      EVENT.VISIBILITY_CHANGE,
-      this.onVisibilityChange,
-    );
+    // window.removeEventListener(
+    //   EVENT.VISIBILITY_CHANGE,
+    //   this.onVisibilityChange,
+    // );
+    window.removeEventListener(EVENT.BLUR, this.onVisibilityChange);
+    window.removeEventListener(EVENT.FOCUS, this.onVisibilityChange);
+
     if (this.activeIntervalId) {
     if (this.activeIntervalId) {
       window.clearInterval(this.activeIntervalId);
       window.clearInterval(this.activeIntervalId);
       this.activeIntervalId = null;
       this.activeIntervalId = null;
@@ -364,6 +367,7 @@ class Collab extends PureComponent<Props, CollabState> {
           this.portal.socket.connect();
           this.portal.socket.connect();
           this.portal.socket.emit(WS_SCENE_EVENT_TYPES.INIT);
           this.portal.socket.emit(WS_SCENE_EVENT_TYPES.INIT);
 
 
+          console.log("setting toast");
           this.excalidrawAPI.setToast({
           this.excalidrawAPI.setToast({
             message: t("toast.reconnectRoomServer"),
             message: t("toast.reconnectRoomServer"),
             duration: Infinity,
             duration: Infinity,
@@ -433,6 +437,7 @@ class Collab extends PureComponent<Props, CollabState> {
           this.excalidrawAPI.updateScene({
           this.excalidrawAPI.updateScene({
             appState: { viewModeEnabled: false },
             appState: { viewModeEnabled: false },
           });
           });
+          console.log("resetting toast");
           this.excalidrawAPI.setToast(null);
           this.excalidrawAPI.setToast(null);
           this.excalidrawAPI.scrollToContent();
           this.excalidrawAPI.scrollToContent();
         }
         }
@@ -700,6 +705,7 @@ class Collab extends PureComponent<Props, CollabState> {
     );
     );
 
 
     this.portal.socket.on("first-in-room", async () => {
     this.portal.socket.on("first-in-room", async () => {
+      console.log("first in room");
       if (this.portal.socket) {
       if (this.portal.socket) {
         this.portal.socket.off("first-in-room");
         this.portal.socket.off("first-in-room");
       }
       }
@@ -841,7 +847,9 @@ class Collab extends PureComponent<Props, CollabState> {
   };
   };
 
 
   private onVisibilityChange = () => {
   private onVisibilityChange = () => {
-    if (document.hidden) {
+    // if (document.hidden) {
+    console.log("VIS CHANGE");
+    if (!document.hasFocus()) {
       if (this.idleTimeoutId) {
       if (this.idleTimeoutId) {
         window.clearTimeout(this.idleTimeoutId);
         window.clearTimeout(this.idleTimeoutId);
         this.idleTimeoutId = null;
         this.idleTimeoutId = null;
@@ -883,8 +891,10 @@ class Collab extends PureComponent<Props, CollabState> {
   };
   };
 
 
   private initializeIdleDetector = () => {
   private initializeIdleDetector = () => {
-    document.addEventListener(EVENT.POINTER_MOVE, this.onPointerMove);
-    document.addEventListener(EVENT.VISIBILITY_CHANGE, this.onVisibilityChange);
+    // document.addEventListener(EVENT.POINTER_MOVE, this.onPointerMove);
+    // document.addEventListener(EVENT.VISIBILITY_CHANGE, this.onVisibilityChange);
+    window.addEventListener(EVENT.BLUR, this.onVisibilityChange);
+    window.addEventListener(EVENT.FOCUS, this.onVisibilityChange);
   };
   };
 
 
   setCollaborators(sockets: string[]) {
   setCollaborators(sockets: string[]) {

+ 3 - 0
src/excalidraw-app/collab/Portal.tsx

@@ -34,6 +34,8 @@ class Portal {
 
 
   open(socket: SocketIOClient.Socket, id: string, key: string) {
   open(socket: SocketIOClient.Socket, id: string, key: string) {
     this.socket = socket;
     this.socket = socket;
+    // @ts-ignore
+    window.socket = socket;
     this.roomId = id;
     this.roomId = id;
     this.roomKey = key;
     this.roomKey = key;
 
 
@@ -62,6 +64,7 @@ class Portal {
 
 
     // Initialize socket listeners
     // Initialize socket listeners
     this.socket.on("init-room", () => {
     this.socket.on("init-room", () => {
+      console.log("join room");
       if (this.socket) {
       if (this.socket) {
         this.socket.emit("join-room", this.roomId);
         this.socket.emit("join-room", this.roomId);
         trackEvent("share", "room joined");
         trackEvent("share", "room joined");