Skip to content

Commit

Permalink
fix: whiteboard flicker by syncing instance state only on page change
Browse files Browse the repository at this point in the history
  • Loading branch information
eswarclynn authored May 15, 2024
1 parent b014a69 commit c14ce97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export class WhiteboardInteractivityCenter implements HMSWhiteboardInteractivity
for (const whiteboard of whiteboards.values()) {
if (whiteboard.url) {
const response = await this.transport.signal.getWhiteboard({ id: whiteboard.id });
const localPeer = this.store.getLocalPeer();
const isOwner = localPeer?.customerUserId === response.owner;
const open = isOwner
? localPeer.role?.permissions.whiteboard?.includes('admin')
: response.permissions.length > 0;
const newWhiteboard: HMSWhiteboard = {
...whiteboard,
id: response.id,
Expand All @@ -86,7 +91,7 @@ export class WhiteboardInteractivityCenter implements HMSWhiteboardInteractivity
addr: response.addr,
owner: response.owner,
permissions: response.permissions,
open: response.permissions.length > 0,
open,
};

this.store.setWhiteboard(newWhiteboard);
Expand Down
4 changes: 2 additions & 2 deletions packages/hms-whiteboard/src/hooks/StoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface OpenCallbacks<T> {
handleError: (error: Error) => void;
}

const WHITEBOARD_CLOSE_MESSAGE = 'client whiteboard close';
const WHITEBOARD_CLOSE_MESSAGE = 'client whiteboard abort';

export class SessionStore<T> {
private storeClient: StoreClient;
Expand Down Expand Up @@ -61,7 +61,7 @@ export class SessionStore<T> {
});

call.responses.onError(error => {
if (error.message !== WHITEBOARD_CLOSE_MESSAGE) {
if (!error.message.includes('abort')) {
handleError(error);
}
});
Expand Down
17 changes: 11 additions & 6 deletions packages/hms-whiteboard/src/hooks/useCollaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
HistoryEntry,
throttle,
TLAnyShapeUtilConstructor,
TLInstance,
TLINSTANCE_ID,
TLPage,
TLRecord,
TLStoreWithStatus,
Expand Down Expand Up @@ -196,12 +198,15 @@ export function useCollaboration({
if (!key.includes('instance')) {
return;
}
// full store sync
const instanceRecords = store
.allRecords()
.filter(record => FULL_SYNC_REQUIRED_RECORD_TYPES.includes(record.typeName));
for (const record of instanceRecords) {
sessionStore.set(record.id, record);
const newPage = editor?.getCurrentPage();

if (newPage?.id !== currentPage?.id) {
sessionStore.get(TLINSTANCE_ID).then(instance => {
if (instance) {
sessionStore?.set(instance.id, { ...instance, currentPageId: newPage?.id } as TLInstance);
}
});
setCurrentPage(newPage);
}
});
}, PAGES_DEBOUNCE_TIME),
Expand Down

0 comments on commit c14ce97

Please sign in to comment.