| 363 | * @public |
| 364 | */ |
| 365 | export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>> { |
| 366 | /** The last clock time from the most recent server update */ |
| 367 | private lastServerClock = -1 |
| 368 | private lastServerInteractionTimestamp = Date.now() |
| 369 | |
| 370 | /** The queue of in-flight push requests that have not yet been acknowledged by the server */ |
| 371 | private pendingPushRequests: TLPushRequest<R>[] = [] |
| 372 | private unsentChanges: { |
| 373 | nextDiff?: RecordsDiff<R> |
| 374 | nextPresence?: R | null |
| 375 | } = { nextDiff: undefined, nextPresence: undefined } |
| 376 | |
| 377 | /** |
| 378 | * The diff of 'unconfirmed', 'optimistic' changes that have been made locally by the user if we |
| 379 | * take this diff, reverse it, and apply that to the store, our store will match exactly the most |
| 380 | * recent state of the server that we know about |
| 381 | */ |
| 382 | private speculativeChanges: RecordsDiff<R> = { |
| 383 | added: {} as any, |
| 384 | updated: {} as any, |
| 385 | removed: {} as any, |
| 386 | } |
| 387 | |
| 388 | private disposables: Array<() => void> = [] |
| 389 | |
| 390 | /** Separate scheduler instance for network sync operations */ |
| 391 | private readonly fpsScheduler: FpsScheduler |
| 392 | |
| 393 | /** Send any unsent push requests to the server */ |
| 394 | private readonly sendUnsentChanges: { |
| 395 | (): void |
| 396 | cancel?(): void |
| 397 | } |
| 398 | |
| 399 | /** Schedule a rebase operation */ |
| 400 | private readonly scheduleRebase: { |
| 401 | (): void |
| 402 | cancel?(): void |
| 403 | } |
| 404 | |
| 405 | /** @internal */ |
| 406 | readonly store: S |
| 407 | /** @internal */ |
| 408 | readonly socket: TLPersistentClientSocket<TLSocketClientSentEvent<R>, TLSocketServerSentEvent<R>> |
| 409 | |
| 410 | /** @internal */ |
| 411 | readonly presenceState: Signal<R | null> | undefined |
| 412 | /** @internal */ |
| 413 | readonly presenceMode: Signal<TLPresenceMode> | undefined |
| 414 | |
| 415 | // isOnline is true when we have an open socket connection and we have |
| 416 | // established a connection with the server room (i.e. we have received a 'connect' message) |
| 417 | /** @internal */ |
| 418 | isConnectedToRoom = false |
| 419 | |
| 420 | /** |
| 421 | * The client clock is essentially a counter for push requests Each time a push request is created |
| 422 | * the clock is incremented. This clock is sent with the push request to the server, and the |
nothing calls this directly
no test coverage detected
searching dependent graphs…