feat: submit scene to firebase on collab pause

This commit is contained in:
Arnošt Pleskot 2023-06-27 17:22:59 +02:00
parent a1d3350131
commit 62df03d78d
No known key found for this signature in database

View File

@ -324,10 +324,27 @@ class Collab extends PureComponent<Props, CollabState> {
fallbackResumeTimeout: null | ReturnType<typeof setTimeout> = null; fallbackResumeTimeout: null | ReturnType<typeof setTimeout> = null;
/**
* Handles the pause and resume states of a collaboration session.
* This function gets triggered when a change in the collaboration pause state is detected.
* Based on the state, the function carries out the following actions:
* 1. `PAUSED`: Saves the current scene to Firebase, disconnects the socket, and updates the scene to view mode.
* 2. `RESUMED`: Connects the socket, shows a toast message, sets a fallback to fetch data from Firebase, and resets the pause timeout if any.
* 3. `SYNCED`: Clears the fallback timeout if any, updates the collaboration pause state, and updates the scene to editing mode.
*
* @param state - The new state of the collaboration session. It is one of the values of `PauseCollaborationState` enum, which includes `PAUSED`, `RESUMED`, and `SYNCED`.
*/
onPauseCollaborationChange = (state: PauseCollaborationState) => { onPauseCollaborationChange = (state: PauseCollaborationState) => {
switch (state) { switch (state) {
case PauseCollaborationState.PAUSED: { case PauseCollaborationState.PAUSED: {
if (this.portal.socket) { if (this.portal.socket) {
// Save current scene to firebase
this.saveCollabRoomToFirebase(
getSyncableElements(
this.excalidrawAPI.getSceneElementsIncludingDeleted(),
),
);
this.portal.socket.disconnect(); this.portal.socket.disconnect();
this.portal.socketInitialized = false; this.portal.socketInitialized = false;
this.setIsCollaborationPaused(true); this.setIsCollaborationPaused(true);