Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class TextComponent implements AfterViewInit, OnDestroy {
private activePresenceSubscription?: Subscription;
private onDeleteSub?: Subscription;
private localSystemChangesSub?: Subscription;
private onlineSubscription?: Subscription;
private readonly DEFAULT_MODULES: any = {
toolbar: false,
keyboard: {
Expand Down Expand Up @@ -1213,6 +1214,23 @@ export class TextComponent implements AfterViewInit, OnDestroy {
// But if getText does not return, then we are showing a good message.
this.loadingState = 'offline-or-loading';
const textDoc = await this.projectService.getText(this._id);

// When the user appears offline, ensure that the user's ops are not sent to ShareDB by pausing sending.
// This will prevent the ViewModel's fixSegment offline-specific logic causing issues with a flaky connection.
this.onlineSubscription?.unsubscribe();
this.onlineSubscription = this.onlineStatusService.onlineStatus$
.pipe(quietTakeUntilDestroyed(this.destroyRef))
.subscribe(isOnline => {
if (isOnline) {
textDoc.adapter.resume();
} else {
textDoc.adapter.pause();
}
});
if (!this.onlineStatusService.isOnline) {
textDoc.adapter.pause();
}

this.loadingState = 'loading';
this.viewModel.bind(this._id, textDoc, this.subscribeToUpdates);
if (this.viewModel.isEmpty) this.loadingState = 'empty-viewModel';
Expand Down
2 changes: 2 additions & 0 deletions src/SIL.XForge.Scripture/ClientApp/src/typings/sharedb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ declare module 'sharedb/lib/client' {
whenNothingPending(callback: Callback): void;
hasWritePending(): boolean;
flush(): void;
pause(): void;
resume(): void;
previousSnapshot(): Snapshot;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class MemoryRealtimeDocAdapter implements RealtimeDocAdapter {
on: (_event: string, _handler: Function) => {},
off: (_event: string, _handler: Function) => {}
} as Presence;
paused: boolean = false;
submitSource: boolean = false;
subscribed: boolean = false;
version: number = -1;
Expand Down Expand Up @@ -127,6 +128,14 @@ export class MemoryRealtimeDocAdapter implements RealtimeDocAdapter {
return Promise.resolve();
}

pause(): void {
this.paused = true;
}

resume(): void {
this.paused = false;
}

subscribe(): Promise<void> {
this.subscribed = true;
return Promise.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface RealtimeDocAdapter {
exists(): Promise<boolean>;
delete(): Promise<void>;
updatePendingOps(ops: any[]): void;
pause(): void;
resume(): void;
previousSnapshot(): Promise<Snapshot>;

destroy(): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ export class SharedbRealtimeDocAdapter implements RealtimeDocAdapter {
this.doc.flush();
}

pause(): void {
this.doc.pause();
}

resume(): void {
this.doc.resume();
}

previousSnapshot(): Promise<DataSnapshot> {
return new Promise((resolve, reject) => {
this.doc.connection.fetchSnapshot(
Expand Down
Loading