Skip to content

Commit 9f95437

Browse files
[Feature] Set WebSocket as default (#256)
Co-authored-by: benitav <benitav@users.noreply.github.com>
1 parent bc483eb commit 9f95437

File tree

8 files changed

+33
-27
lines changed

8 files changed

+33
-27
lines changed

.changeset/nine-bulldogs-burn.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@powersync/react-native': minor
3+
'@powersync/web': minor
4+
---
5+
6+
Updated default streaming connection method to use WebSockets

demos/django-react-native-todolist/library/stores/system.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import '@azure/core-asynciterator-polyfill';
2+
import { AbstractPowerSyncDatabase, PowerSyncDatabase } from '@powersync/react-native';
23
import React from 'react';
3-
import { AbstractPowerSyncDatabase, PowerSyncDatabase, SyncStreamConnectionMethod } from '@powersync/react-native';
4-
import { AppSchema } from '../powersync/AppSchema';
54
import { DjangoConnector } from '../django/DjangoConnector';
5+
import { AppSchema } from '../powersync/AppSchema';
66

77
export class System {
88
djangoConnector: DjangoConnector;
@@ -21,7 +21,7 @@ export class System {
2121

2222
async init() {
2323
await this.powersync.init();
24-
await this.powersync.connect(this.djangoConnector, { connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET });
24+
await this.powersync.connect(this.djangoConnector);
2525
}
2626
}
2727

demos/react-native-supabase-todolist/library/powersync/system.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import '@azure/core-asynciterator-polyfill';
22

3+
import { PowerSyncDatabase } from '@powersync/react-native';
34
import React from 'react';
4-
import { PowerSyncDatabase, SyncStreamConnectionMethod } from '@powersync/react-native';
55
import { SupabaseStorageAdapter } from '../storage/SupabaseStorageAdapter';
66

7-
import { AppSchema } from './AppSchema';
8-
import { SupabaseConnector } from '../supabase/SupabaseConnector';
9-
import { KVStorage } from '../storage/KVStorage';
10-
import { PhotoAttachmentQueue } from './PhotoAttachmentQueue';
117
import { type AttachmentRecord } from '@powersync/attachments';
12-
import { AppConfig } from '../supabase/AppConfig';
138
import Logger from 'js-logger';
9+
import { KVStorage } from '../storage/KVStorage';
10+
import { AppConfig } from '../supabase/AppConfig';
11+
import { SupabaseConnector } from '../supabase/SupabaseConnector';
12+
import { AppSchema } from './AppSchema';
13+
import { PhotoAttachmentQueue } from './PhotoAttachmentQueue';
1414

1515
Logger.useDefaults();
1616

@@ -51,7 +51,7 @@ export class System {
5151

5252
async init() {
5353
await this.powersync.init();
54-
await this.powersync.connect(this.supabaseConnector, { connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET });
54+
await this.powersync.connect(this.supabaseConnector);
5555

5656
if (this.attachmentQueue) {
5757
await this.attachmentQueue.init();

demos/react-supabase-todolist/src/components/providers/SystemProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AppSchema } from '@/library/powersync/AppSchema';
33
import { SupabaseConnector } from '@/library/powersync/SupabaseConnector';
44
import { CircularProgress } from '@mui/material';
55
import { PowerSyncContext } from '@powersync/react';
6-
import { PowerSyncDatabase, SyncStreamConnectionMethod } from '@powersync/web';
6+
import { PowerSyncDatabase } from '@powersync/web';
77
import Logger from 'js-logger';
88
import React, { Suspense } from 'react';
99
import { NavigationPanelContextProvider } from '../navigation/NavigationPanelContext';
@@ -33,7 +33,7 @@ export const SystemProvider = ({ children }: { children: React.ReactNode }) => {
3333
const l = connector.registerListener({
3434
initialized: () => {},
3535
sessionStarted: () => {
36-
powerSync.connect(connector, {connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET});
36+
powerSync.connect(connector);
3737
}
3838
});
3939

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const DEFAULT_STREAMING_SYNC_OPTIONS = {
111111
};
112112

113113
export const DEFAULT_STREAM_CONNECTION_OPTIONS: Required<PowerSyncConnectionOptions> = {
114-
connectionMethod: SyncStreamConnectionMethod.HTTP,
114+
connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,
115115
params: {}
116116
};
117117

packages/react-native/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
_[PowerSync](https://www.powersync.com) is a Postgres-SQLite sync layer, which helps developers to create local-first real-time reactive apps that work seamlessly both online and offline._
88

9-
This package (`packages/react-native`) is the PowerSync SDK for React Native clients. It is an extension of `packages/common`. It connects to a PowerSync instance via HTTP streams (enabled by default) or WebSockets.
9+
This package (`packages/react-native`) is the PowerSync SDK for React Native clients. It is an extension of `packages/common`.
1010

1111
See a summary of features [here](https://docs.powersync.co/client-sdk-references/react-native-and-expo).
1212

packages/web/tests/utils/MockStreamOpenFactory.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import {
2-
PowerSyncBackendConnector,
3-
PowerSyncCredentials,
42
AbstractPowerSyncDatabase,
53
AbstractRemote,
6-
RemoteConnector,
74
AbstractStreamingSyncImplementation,
8-
PowerSyncDatabaseOptions,
9-
SyncStreamOptions,
5+
BSONImplementation,
106
DataStream,
7+
PowerSyncBackendConnector,
8+
PowerSyncCredentials,
9+
PowerSyncDatabaseOptions,
10+
RemoteConnector,
1111
StreamingSyncLine,
12-
BSONImplementation
12+
SyncStreamOptions
1313
} from '@powersync/common';
1414
import {
1515
PowerSyncDatabase,
16-
WebPowerSyncDatabaseOptions,
17-
WebStreamingSyncImplementation,
1816
WASQLitePowerSyncDatabaseOpenFactory,
19-
WebPowerSyncOpenFactoryOptions
17+
WebPowerSyncDatabaseOptions,
18+
WebPowerSyncOpenFactoryOptions,
19+
WebStreamingSyncImplementation
2020
} from '@powersync/web';
2121

2222
export class TestConnector implements PowerSyncBackendConnector {
@@ -84,7 +84,8 @@ export class MockRemote extends AbstractRemote {
8484
}
8585

8686
socketStream(options: SyncStreamOptions): Promise<DataStream<StreamingSyncLine>> {
87-
throw new Error('Method not implemented.');
87+
// For this test mock these are essentially the same
88+
return this.postStream(options);
8889
}
8990

9091
async postStream(options: SyncStreamOptions): Promise<DataStream<StreamingSyncLine>> {

tools/diagnostics-app/src/library/powersync/ConnectionManager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
BaseListener,
33
BaseObserver,
44
PowerSyncDatabase,
5-
SyncStreamConnectionMethod,
65
WebRemote,
76
WebStreamingSyncImplementation,
87
WebStreamingSyncImplementationOptions
@@ -75,7 +74,7 @@ if (connector.hasCredentials()) {
7574
}
7675

7776
export async function connect() {
78-
await sync.connect({ connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET });
77+
await sync.connect();
7978
if (!sync.syncStatus.connected) {
8079
// Disconnect but don't wait for it
8180
sync.disconnect();
@@ -91,7 +90,7 @@ export async function clearData() {
9190
await schemaManager.clear();
9291
await schemaManager.refreshSchema(db.database);
9392
if (connector.hasCredentials()) {
94-
await sync.connect({ connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET });
93+
await sync.connect();
9594
}
9695
}
9796

0 commit comments

Comments
 (0)