Skip to content

Commit

Permalink
Update publish-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 authored May 13, 2024
2 parents 411c589 + b014a69 commit 025ce5f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/hms-whiteboard/src/Whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function Whiteboard({ onMount, endpoint, token, zoomToContent, transparen
onMount={handleMount}
components={{ ErrorFallback }}
hideUi={editor?.getInstanceState()?.isReadonly}
initialState={editor?.getInstanceState()?.isReadonly ? 'hand' : 'select'}
/>
);
}
24 changes: 16 additions & 8 deletions packages/hms-whiteboard/src/hooks/StoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ interface OpenCallbacks<T> {
handleError: (error: Error) => void;
}

const WHITEBOARD_CLOSE_MESSAGE = 'client whiteboard close';

export class SessionStore<T> {
private storeClient: StoreClient;
private abortController = new AbortController();

constructor(endpoint: string, token: string) {
const transport = new GrpcWebFetchTransport({
Expand All @@ -21,10 +24,13 @@ export class SessionStore<T> {
}

async open({ handleOpen, handleChange, handleError }: OpenCallbacks<T>) {
const call = this.storeClient.open({
changeId: '',
select: [],
});
const call = this.storeClient.open(
{
changeId: '',
select: [],
},
{ abort: this.abortController.signal },
);
/**
* on open, get key count to call handleOpen with the pre-existing values from the store
* retry if getKeysCount is called before open call is completed
Expand Down Expand Up @@ -55,12 +61,14 @@ export class SessionStore<T> {
});

call.responses.onError(error => {
handleError(error);
if (error.message !== WHITEBOARD_CLOSE_MESSAGE) {
handleError(error);
}
});

call.status.then(status => {
console.log('SessionStoreClient open', status);
});
return () => {
this.abortController.abort(WHITEBOARD_CLOSE_MESSAGE);
};
}

set(key: string, value?: T) {
Expand Down
12 changes: 7 additions & 5 deletions packages/hms-whiteboard/src/hooks/useCollaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ export function useCollaboration({
};

// Open session and sync the session store changes to the store
sessionStore.open({
handleOpen,
handleChange,
handleError,
});
sessionStore
.open({
handleOpen,
handleChange,
handleError,
})
.then(unsub => unsubs.push(unsub));

// Sync store changes to the yjs doc
unsubs.push(
Expand Down
3 changes: 0 additions & 3 deletions packages/hms-whiteboard/src/hooks/useSetEditorPermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ export const useSetEditorPermissions = ({

const isReadonly = !permissions.includes('write');
editor?.updateInstanceState({ isReadonly });
if (isReadonly) {
editor?.setCurrentTool('hand');
}
}, [permissions, zoomToContent, editor]);
};

0 comments on commit 025ce5f

Please sign in to comment.