Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: whiteboard flicker by syncing instance state only on page change #2896

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading