diff --git a/src/excalidraw-app/collab/Collab.tsx b/src/excalidraw-app/collab/Collab.tsx index 477efd1bf..e3f21aac7 100644 --- a/src/excalidraw-app/collab/Collab.tsx +++ b/src/excalidraw-app/collab/Collab.tsx @@ -374,10 +374,30 @@ class Collab extends PureComponent { } this.onPauseCollaborationChange(PauseCollaborationState.SYNCED); }; + + // Set timeout to fallback to fetch data from firebase this.fallbackResumeTimeout = setTimeout( fallbackResumeHandler, RESUME_FALLBACK_TIMEOUT, ); + + // When no users are in the room, we fallback to fetch data from firebase immediately and clear fallback timeout + this.portal.socket.on("first-in-room", () => { + if (this.portal.socket) { + this.portal.socket.off("first-in-room"); + } + + fallbackResumeHandler(); + + if (this.fallbackResumeTimeout) { + clearTimeout(this.fallbackResumeTimeout); + } + }); + } + + // Clear pause timeout if exists + if (this.pauseTimeoutId) { + clearTimeout(this.pauseTimeoutId); } break;