Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update connectivity status #19

Merged
merged 2 commits into from
Oct 31, 2023
Merged
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
6 changes: 6 additions & 0 deletions .changeset/fair-planes-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@journeyapps/powersync-sdk-react-native': patch
'@journeyapps/powersync-sdk-common': patch
---

Use default timeout in post streaming warning message. Update connectivity status on streaming messages.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ export abstract class AbstractStreamingSyncImplementation extends BaseObserver<S

private isUploadingCrud: boolean;

protected _isConnected: boolean;

constructor(options: AbstractStreamingSyncImplementationOptions) {
super();
this.options = { ...DEFAULT_STREAMING_SYNC_OPTIONS, ...options };
this.isUploadingCrud = false;
this._isConnected = false;
}

get lastSyncedAt() {
Expand All @@ -68,6 +71,10 @@ export abstract class AbstractStreamingSyncImplementation extends BaseObserver<S
return this.options.logger!;
}

get isConnected() {
return this._isConnected;
}
Comment on lines +74 to +76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a getter instead of reporting the state directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way it's read only


abstract obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;

async hasCompletedSync() {
Expand Down Expand Up @@ -163,6 +170,9 @@ export abstract class AbstractStreamingSyncImplementation extends BaseObserver<S
},
signal
)) {
// A connection is active and messages are being received
this.updateSyncStatus(true);

if (isStreamingSyncCheckpoint(line)) {
targetCheckpoint = line.checkpoint;
const bucketsToDelete = new Set<string>(bucketSet);
Expand Down Expand Up @@ -289,7 +299,13 @@ export abstract class AbstractStreamingSyncImplementation extends BaseObserver<S
}

private updateSyncStatus(connected: boolean, lastSyncedAt?: Date) {
const takeSnapShot = () => [this._isConnected, this._lastSyncedAt?.valueOf()];

const previousValues = takeSnapShot();
this._lastSyncedAt = lastSyncedAt ?? this.lastSyncedAt;
this.iterateListeners((cb) => cb.statusChanged?.(new SyncStatus(connected, this.lastSyncedAt)));
this._isConnected = connected;
if (!_.isEqual(previousValues, takeSnapShot())) {
this.iterateListeners((cb) => cb.statusChanged?.(new SyncStatus(this.isConnected, this.lastSyncedAt)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export class ReactNativeRemote extends AbstractRemote {
Platform.OS == 'android'
? setTimeout(() => {
this.logger.warn(
`HTTP Streaming POST is taking longer than 30 seconds to resolve. If using a debug build, please ensure Flipper Network plugin is disabled.`
`HTTP Streaming POST is taking longer than ${Math.ceil(
STREAMING_POST_TIMEOUT_MS / 1000
)} seconds to resolve. If using a debug build, please ensure Flipper Network plugin is disabled.`
);
}, STREAMING_POST_TIMEOUT_MS)
: null;
Expand Down
Loading