Skip to content

Commit

Permalink
fix: add delay to reopen whiteboard
Browse files Browse the repository at this point in the history
  • Loading branch information
eswarclynn committed May 16, 2024
1 parent 734b6da commit 1c73cfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/hms-whiteboard/src/hooks/useCollaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { DEFAULT_STORE } from './default_store';
import { useSessionStore } from './useSessionStore';
import { useSetEditorPermissions } from './useSetEditorPermissions';
import { CURRENT_PAGE_KEY, PAGES_DEBOUNCE_TIME, SHAPES_THROTTLE_TIME } from '../utils';
import { CURRENT_PAGE_KEY, OPEN_DELAY, PAGES_DEBOUNCE_TIME, SHAPES_THROTTLE_TIME } from '../utils';

// mandatory record types required for initialisation of the whiteboard and for a full remote sync
const FULL_SYNC_REQUIRED_RECORD_TYPES: TLRecord['typeName'][] = [
Expand Down Expand Up @@ -121,13 +121,17 @@ export function useCollaboration({
};

// Open session and sync the session store changes to the store
sessionStore
.open({
handleOpen,
handleChange,
handleError,
})
.then(unsub => unsubs.push(unsub));
// On opening, closing and reopening whiteboard with no delay(in case of role change), the session store server needs time to cleanup on the close before opening again
// so there is a delay here before opening the connection
setTimeout(() => {
sessionStore
.open({
handleOpen,
handleChange,
handleError,
})
.then(unsub => unsubs.push(unsub));
}, OPEN_DELAY);

// Sync store changes to the yjs doc
unsubs.push(
Expand Down
1 change: 1 addition & 0 deletions packages/hms-whiteboard/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export default function decodeJWT(token?: string) {
export const CURRENT_PAGE_KEY = 'currentPage';
export const SHAPES_THROTTLE_TIME = 11;
export const PAGES_DEBOUNCE_TIME = 200;
export const OPEN_DELAY = 100;

0 comments on commit 1c73cfa

Please sign in to comment.