MCPcopy
hub / github.com/tldraw/tldraw / handleServerEvent

Method handleServerEvent

packages/sync-core/src/lib/TLSyncClient.ts:773–808  ·  view source on GitHub ↗

Handle events received from the server

(event: TLSocketServerSentEvent<R>)

Source from the content-addressed store, hash-verified

771
772 /** Handle events received from the server */
773 private handleServerEvent(event: TLSocketServerSentEvent<R>) {
774 this.debug('received server event', event)
775 this.lastServerInteractionTimestamp = Date.now()
776 // always update the lastServerClock when it is present
777 switch (event.type) {
778 case 'connect':
779 this.didReconnect(event)
780 break
781 // legacy v4 events
782 case 'patch':
783 case 'push_result':
784 if (!this.isConnectedToRoom) break
785 this.incomingDiffBuffer.push(event)
786 this.scheduleRebase()
787 break
788 case 'data':
789 // wait for a connect to succeed before processing more events
790 if (!this.isConnectedToRoom) break
791 this.incomingDiffBuffer.push(...event.data)
792 this.scheduleRebase()
793 break
794 case 'incompatibility_error':
795 // legacy unrecoverable errors
796 console.error('incompatibility error is legacy and should no longer be sent by the server')
797 break
798 case 'pong':
799 // noop, we only use ping/pong to set lastSeverInteractionTimestamp
800 break
801 case 'custom':
802 this.onCustomMessageReceived?.call(null, event.data)
803 break
804
805 default:
806 exhaustiveSwitchError(event)
807 }
808 }
809
810 /**
811 * Closes the sync client and cleans up all resources.

Callers 1

constructorMethod · 0.95

Calls 6

debugMethod · 0.95
didReconnectMethod · 0.95
exhaustiveSwitchErrorFunction · 0.90
nowMethod · 0.80
errorMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected