diff --git a/backend/src/realtime/realtime-note/realtime-user-status-adapter.spec.ts b/backend/src/realtime/realtime-note/realtime-user-status-adapter.spec.ts index 192e37349..1cf4c9de0 100644 --- a/backend/src/realtime/realtime-note/realtime-user-status-adapter.spec.ts +++ b/backend/src/realtime/realtime-note/realtime-user-status-adapter.spec.ts @@ -146,10 +146,10 @@ describe('realtime user status adapter', () => { 'sendMessage', ); - messageTransporterLoggedIn1.startSendingOfReadyRequests(); - messageTransporterLoggedIn2.startSendingOfReadyRequests(); - messageTransporterGuest.startSendingOfReadyRequests(); - messageTransporterDecline.startSendingOfReadyRequests(); + messageTransporterLoggedIn1.markAsReady(); + messageTransporterLoggedIn2.markAsReady(); + messageTransporterGuest.markAsReady(); + messageTransporterDecline.markAsReady(); jest.advanceTimersByTime(500); }); diff --git a/backend/src/realtime/websocket/websocket.gateway.ts b/backend/src/realtime/websocket/websocket.gateway.ts index 9750d7c8a..d92c5bf17 100644 --- a/backend/src/realtime/websocket/websocket.gateway.ts +++ b/backend/src/realtime/websocket/websocket.gateway.ts @@ -106,7 +106,7 @@ export class WebsocketGateway implements OnGatewayConnection { realtimeNote.addClient(connection); - websocketTransporter.startSendingOfReadyRequests(); + websocketTransporter.markAsReady(); } catch (error: unknown) { this.logger.error( `Error occurred while initializing: ${(error as Error).message}`, diff --git a/commons/src/message-transporters/message-transporter.ts b/commons/src/message-transporters/message-transporter.ts index 5a01a9602..cd20d8664 100644 --- a/commons/src/message-transporters/message-transporter.ts +++ b/commons/src/message-transporters/message-transporter.ts @@ -212,9 +212,12 @@ export class MessageTransporter extends EventEmitter2 { * Marks the transporter as ready for communication and starts sending of ready requests to the other side. * This method should be called after all preparations are done and messages can be processed. */ - public startSendingOfReadyRequests(): void { + public markAsReady(): void { this.thisSideReady = true + this.startSendingOfReadyRequests() + } + private startSendingOfReadyRequests(): void { this.readyInterval = setInterval(() => { this.sendMessage({ type: MessageType.READY_REQUEST diff --git a/commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts b/commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts index a2ae091b7..b55cc8c38 100644 --- a/commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts +++ b/commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts @@ -180,10 +180,10 @@ describe('y-doc-sync-adapter', () => { messageTransporterServerTo1.setAdapter(transporterAdapterServerTo1) messageTransporterServerTo2.setAdapter(transporterAdapterServerTo2) - messageTransporterClient1.startSendingOfReadyRequests() - messageTransporterClient2.startSendingOfReadyRequests() - messageTransporterServerTo1.startSendingOfReadyRequests() - messageTransporterServerTo2.startSendingOfReadyRequests() + messageTransporterClient1.markAsReady() + messageTransporterClient2.markAsReady() + messageTransporterServerTo1.markAsReady() + messageTransporterServerTo2.markAsReady() jest.advanceTimersByTime(1000) diff --git a/frontend/src/components/editor-page/editor-pane/editor-pane.tsx b/frontend/src/components/editor-page/editor-pane/editor-pane.tsx index d26852762..eea665e24 100644 --- a/frontend/src/components/editor-page/editor-pane/editor-pane.tsx +++ b/frontend/src/components/editor-page/editor-pane/editor-pane.tsx @@ -135,7 +135,7 @@ export const EditorPane: React.FC = ({ scrollState, onScroll, o const mayEdit = useMayEdit() useEffect(() => { - const listener = messageTransporter.doAsSoonAsConnected(() => messageTransporter.startSendingOfReadyRequests()) + const listener = messageTransporter.doAsSoonAsConnected(() => messageTransporter.markAsReady()) return () => { listener.off() }