@supabase/realtime-js 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +165 -80
  2. package/dist/main/RealtimeChannel.d.ts +78 -56
  3. package/dist/main/RealtimeChannel.d.ts.map +1 -1
  4. package/dist/main/RealtimeChannel.js +32 -1
  5. package/dist/main/RealtimeChannel.js.map +1 -1
  6. package/dist/main/RealtimeClient.d.ts +12 -29
  7. package/dist/main/RealtimeClient.d.ts.map +1 -1
  8. package/dist/main/RealtimeClient.js +29 -2
  9. package/dist/main/RealtimeClient.js.map +1 -1
  10. package/dist/main/RealtimePresence.d.ts +14 -55
  11. package/dist/main/RealtimePresence.d.ts.map +1 -1
  12. package/dist/main/RealtimePresence.js +12 -0
  13. package/dist/main/RealtimePresence.js.map +1 -1
  14. package/dist/main/index.d.ts +2 -2
  15. package/dist/main/index.d.ts.map +1 -1
  16. package/dist/main/index.js.map +1 -1
  17. package/dist/main/lib/version.d.ts +1 -1
  18. package/dist/main/lib/version.js +1 -1
  19. package/dist/module/RealtimeChannel.d.ts +78 -56
  20. package/dist/module/RealtimeChannel.d.ts.map +1 -1
  21. package/dist/module/RealtimeChannel.js +32 -1
  22. package/dist/module/RealtimeChannel.js.map +1 -1
  23. package/dist/module/RealtimeClient.d.ts +12 -29
  24. package/dist/module/RealtimeClient.d.ts.map +1 -1
  25. package/dist/module/RealtimeClient.js +29 -2
  26. package/dist/module/RealtimeClient.js.map +1 -1
  27. package/dist/module/RealtimePresence.d.ts +14 -55
  28. package/dist/module/RealtimePresence.d.ts.map +1 -1
  29. package/dist/module/RealtimePresence.js +12 -0
  30. package/dist/module/RealtimePresence.js.map +1 -1
  31. package/dist/module/index.d.ts +2 -2
  32. package/dist/module/index.d.ts.map +1 -1
  33. package/dist/module/index.js.map +1 -1
  34. package/dist/module/lib/version.d.ts +1 -1
  35. package/dist/module/lib/version.js +1 -1
  36. package/package.json +1 -1
  37. package/src/RealtimeChannel.ts +109 -21
  38. package/src/RealtimeClient.ts +29 -3
  39. package/src/RealtimePresence.ts +20 -9
  40. package/src/index.ts +8 -0
  41. package/src/lib/version.ts +1 -1
package/README.md CHANGED
@@ -1,128 +1,213 @@
1
- # Realtime Client
1
+ <br />
2
+ <p align="center">
3
+ <a href="https://supabase.io">
4
+ <picture>
5
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/supabase/supabase/master/packages/common/assets/images/supabase-logo-wordmark--dark.svg">
6
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/supabase/supabase/master/packages/common/assets/images/supabase-logo-wordmark--light.svg">
7
+ <img alt="Supabase Logo" width="300" src="https://raw.githubusercontent.com/supabase/supabase/master/packages/common/assets/images/logo-preview.jpg">
8
+ </picture>
9
+ </a>
2
10
 
3
- Listens to changes in a PostgreSQL Database and via websockets.
11
+ <h1 align="center">Supabase Realtime Client</h1>
4
12
 
5
- This is for usage with Supabase [Realtime](https://github.com/supabase/realtime) server.
13
+ <h3 align="center">Send ephemeral messages with <b>Broadcast</b>, track and synchronize state with <b>Presence</b>, and listen to database changes with <b>Postgres Change Data Capture (CDC)</b>.</h3>
6
14
 
7
- ## Usage
15
+ <p align="center">
16
+ <a href="https://supabase.com/docs/guides/realtime">Guides</a>
17
+ ·
18
+ <a href="https://supabase.com/docs/reference/javascript">Reference Docs</a>
19
+ ·
20
+ <a href="https://multiplayer.dev">Multiplayer Demo</a>
21
+ </p>
22
+ </p>
8
23
 
9
- ### Creating a Socket connection
24
+ # Overview
10
25
 
11
- You can set up one connection to be used across the whole app.
26
+ This client enables you to use the following Supabase Realtime's features:
12
27
 
13
- ```js
14
- import { RealtimeClient } from '@supabase/realtime-js'
28
+ - **Broadcast**: send ephemeral messages from client to clients with minimal latency. Use cases include sharing cursor positions between users.
29
+ - **Presence**: track and synchronize shared state across clients with the help of CRDTs. Use cases include tracking which users are currently viewing a specific webpage.
30
+ - **Postgres Change Data Capture (CDC)**: listen for changes in your PostgreSQL database and send them to clients.
15
31
 
16
- var client = new RealtimeClient(process.env.REALTIME_URL)
17
- client.connect()
18
- ```
32
+ # Usage
19
33
 
20
- REALTIME_URL is `'ws://localhost:4000/socket'` when developing locally and `'wss://<project_ref>.supabase.co/realtime/v1'` when connecting to your Supabase project.
34
+ ## Installing the Package
21
35
 
22
- You can pass in your JWT If you have enabled JWT authorization in Supabase [Realtime](https://github.com/supabase/realtime) server.
36
+ ```bash
37
+ npm install @supabase/realtime-js
38
+ ```
39
+
40
+ ## Creating a Channel
23
41
 
24
42
  ```js
25
43
  import { RealtimeClient } from '@supabase/realtime-js'
26
44
 
27
- var client = new RealtimeClient(process.env.REALTIME_URL, {
28
- params: { apikey: 'token123' },
45
+ const client = new RealtimeClient(REALTIME_URL, {
46
+ params: {
47
+ apikey: API_KEY,
48
+ eventsPerSecond: 10,
49
+ },
29
50
  })
30
- client.connect()
31
- ```
32
51
 
33
- See [Realtime: Websocket Connection Authorization](https://github.com/supabase/realtime#websocket-connection-authorization) for more information.
52
+ const channel = client.channel('test-channel', {})
34
53
 
35
- ### Subscribing to events
54
+ channel.subscribe((status, err) => {
55
+ if (status === 'SUBSCRIBED') {
56
+ console.log('Connected!')
57
+ }
36
58
 
37
- You can listen to `INSERT`, `UPDATE`, `DELETE`, or all `*` events.
59
+ if (status === 'CHANNEL_ERROR') {
60
+ console.log(`There was an error subscribing to channel: ${err.message}`)
61
+ }
38
62
 
39
- You can subscribe to events on the whole database, schema, table, or individual columns using `channel()`. Channels are multiplexed over the Socket connection.
63
+ if (status === 'TIMED_OUT') {
64
+ console.log('Realtime server did not respond in time.')
65
+ }
40
66
 
41
- To join a channel, you must provide the `topic`, where a topic is either:
67
+ if (status === 'CLOSED') {
68
+ console.log('Realtime channel was unexpectedly closed.')
69
+ }
70
+ })
71
+ ```
72
+
73
+ ### Notes:
42
74
 
43
- - `realtime` - entire database
44
- - `realtime:{schema}` - where `{schema}` is the Postgres Schema
45
- - `realtime:{schema}:{table}` - where `{table}` is the Postgres table name
46
- - `realtime:{schema}:{table}:{col}=eq.{val}` - where `{col}` is the column name, and `{val}` is the value which you want to match
75
+ - `REALTIME_URL` is `'ws://localhost:4000/socket'` when developing locally and `'wss://<project_ref>.supabase.co/realtime/v1'` when connecting to your Supabase project.
76
+ - `API_KEY` is a JWT whose claims must contain `exp` and `role` (existing database role).
77
+ - Channel name can be any `string`.
78
+ - `eventsPerSecond`, or client-side rate limiting, enforces the number of events sent to the Realtime server uniformly spread across a second. The default is 10, which means that the client can send one event, whether that's **Broadcast**/**Presence**/**Postgres CDC**, every 100 milliseconds. You may change this as you see fit but note that the server's rate limiting will need to be updated accordingly. You can learn more about Realtime's rate limits here: https://supabase.com/docs/guides/realtime/rate-limits.
47
79
 
48
- **Examples**
80
+ ## Broadcast
81
+
82
+ Your client can send and receive messages based on the `event`.
49
83
 
50
84
  ```js
51
- // Listen to events on the entire database.
52
- var databaseChanges = client.channel('realtime:*')
53
- databaseChanges.on('*', (e) => console.log(e))
54
- databaseChanges.on('INSERT', (e) => console.log(e))
55
- databaseChanges.on('UPDATE', (e) => console.log(e))
56
- databaseChanges.on('DELETE', (e) => console.log(e))
57
- databaseChanges.subscribe()
58
-
59
- // Listen to events on a schema, using the format `realtime:{SCHEMA}`
60
- var publicSchema = client.channel('realtime:public')
61
- publicSchema.on('*', (e) => console.log(e))
62
- publicSchema.on('INSERT', (e) => console.log(e))
63
- publicSchema.on('UPDATE', (e) => console.log(e))
64
- publicSchema.on('DELETE', (e) => console.log(e))
65
- publicSchema.subscribe()
66
-
67
- // Listen to events on a table, using the format `realtime:{SCHEMA}:{TABLE}`
68
- var usersTable = client.channel('realtime:public:users')
69
- usersTable.on('*', (e) => console.log(e))
70
- usersTable.on('INSERT', (e) => console.log(e))
71
- usersTable.on('UPDATE', (e) => console.log(e))
72
- usersTable.on('DELETE', (e) => console.log(e))
73
- usersTable.subscribe()
74
-
75
- // Listen to events on a row, using the format `realtime:{SCHEMA}:{TABLE}:{COL}=eq.{VAL}`
76
- var rowChanges = client.channel('realtime:public:users:id=eq.1')
77
- rowChanges.on('*', (e) => console.log(e))
78
- rowChanges.on('INSERT', (e) => console.log(e))
79
- rowChanges.on('UPDATE', (e) => console.log(e))
80
- rowChanges.on('DELETE', (e) => console.log(e))
81
- rowChanges.subscribe()
85
+ // Setup...
86
+
87
+ const channel = client.channel('broadcast-test', { broadcast: { ack: false, self: false } })
88
+
89
+ channel.on('broadcast', { event: 'some-event' }, (payload) =>
90
+ console.log(payload)
91
+ )
92
+
93
+ channel.subscribe(async (status) => {
94
+ if (status === 'SUBSCRIBED') {
95
+ // Send message to other clients listening to 'broadcast-test' channel
96
+ await channel.send({
97
+ type: 'broadcast',
98
+ event: 'some-event',
99
+ payload: { hello: 'world' },
100
+ })
101
+ }
102
+ })
82
103
  ```
83
104
 
84
- **Removing a subscription**
105
+ ### Notes:
85
106
 
86
- You can unsubscribe from a topic using `channel.unsubscribe()`.
107
+ - Setting `ack` to `true` means that the `channel.send` promise will resolve once server replies with acknowledgement that it received the broadcast message request.
108
+ - Setting `self` to `true` means that the client will receive the broadcast message it sent out.
87
109
 
88
- **Disconnect the socket**
110
+ ## Presence
89
111
 
90
- Call `disconnect()` on the socket:
112
+ Your client can track and sync state that's stored in the channel.
91
113
 
92
114
  ```js
93
- let { error, data } = await client.disconnect()
115
+ // Setup...
116
+
117
+ const channel = client.channel('presence-test', { presence: { key: '' } })
118
+
119
+ channel.on('presence', { event: 'sync' }, () => {
120
+ console.log('Online users: ', channel.presenceState())
121
+ })
122
+
123
+ channel.on('presence', { event: 'join' }, ({ newPresences }) => {
124
+ console.log('New users have joined: ', newPresences)
125
+ })
126
+
127
+ channel.on('presence', { event: 'leave' }, ({ leftPresences }) => {
128
+ console.log('Users have left: ', newPresences)
129
+ })
130
+
131
+ channel.subscribe(async (status) => {
132
+ if (status === 'SUBSCRIBED') {
133
+ const status = await channel.track({ 'user_id': 1 })
134
+ console.log(status)
135
+ }
136
+ })
94
137
  ```
95
138
 
96
- **Duplicate Join Subscriptions**
139
+ ## Postgres CDC
97
140
 
98
- While the client may join any number of topics on any number of channels, the client may only hold a single subscription for each unique topic at any given time. When attempting to create a duplicate subscription, the server will close the existing channel, log a warning, and spawn a new channel for the topic. The client will have their `channel.onClose` callbacks fired for the existing channel, and the new
99
- channel join will have its receive hooks processed as normal.
141
+ Receive database changes on the client.
100
142
 
101
- **Channel Hooks**
143
+ ```js
144
+ // Setup...
145
+
146
+ const channel = client.channel('db-changes')
147
+
148
+ channel.on('postgres_changes', { event: '*', schema: 'public' }, (payload) => {
149
+ console.log('All changes in public schema: ', payload)
150
+ })
151
+
152
+ channel.on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'messages' }, (payload) => {
153
+ console.log('All inserts in messages table: ', payload)
154
+ })
155
+
156
+ channel.on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'users', filter: 'username=eq.Realtime' }, (payload) => {
157
+ console.log('All updates on users table when username is Realtime: ', payload)
158
+ })
159
+
160
+ channel.subscribe(async (status) => {
161
+ if (status === 'SUBSCRIBED') {
162
+ console.log('Ready to receive database changes!')
163
+ }
164
+ })
165
+ ```
166
+
167
+ ## Get All Channels
168
+
169
+ You can see all the channels that your client has instantiatied.
102
170
 
103
171
  ```js
104
- channel._onError(() => console.log('there was an error!'))
105
- channel._onClose(() => console.log('the channel has gone away gracefully'))
172
+ // Setup...
173
+
174
+ client.getChannels()
106
175
  ```
107
176
 
108
- - `onError` hooks are invoked if the socket connection drops, or the channel crashes on the server. In either case, a channel rejoin is attempted automatically in an exponential backoff manner.
109
- - `onClose` hooks are invoked only in two cases. 1) the channel explicitly closed on the server, or 2). The client explicitly closed, by calling `channel.unsubscribe()`
177
+ ## Cleanup
110
178
 
111
- **Subscription Hooks**
179
+ It is highly recommended that you clean up your channels after you're done with them.
180
+
181
+ - Remove a single channel
112
182
 
113
183
  ```js
114
- publicSchema
115
- .subscribe()
116
- .receive('ok', () => console.log('Connected.'))
117
- .receive('error', () => console.log('Failed.'))
118
- .receive('timeout', () => console.log('Timed out, retrying.'))
184
+ // Setup...
185
+
186
+ const channel = client.channel('some-channel-to-remove')
187
+
188
+ channel.subscribe()
189
+
190
+ client.removeChannel(channel)
191
+ ```
192
+
193
+ - Remove all channels
194
+
195
+ ```js
196
+ // Setup...
197
+
198
+ const channel1 = client.channel('a-channel-to-remove')
199
+ const channel2 = client.channel('another-channel-to-remove')
200
+
201
+ channel1.subscribe()
202
+ channel2.subscribe()
203
+
204
+ client.removeAllChannels()
119
205
  ```
120
206
 
121
207
  ## Credits
122
208
 
123
- - Original Node.js client was made by Mario Campa of [phoenix-channels](github.com/mcampa/phoenix-client).
124
- - API was made by authors of the [Phoenix Framework](http://www.phoenixframework.org/). See their website for complete list of authors.
209
+ This repo draws heavily from [phoenix-js](https://github.com/phoenixframework/phoenix/tree/master/assets/js/phoenix).
125
210
 
126
211
  ## License
127
212
 
128
- MIT. License is the same as [phoenix-channels](https://github.com/mcampa/phoenix-client) and [Phoenix Framework](https://phoenixframework.org/).
213
+ MIT.
@@ -7,7 +7,7 @@ export declare type RealtimeChannelOptions = {
7
7
  config: {
8
8
  /**
9
9
  * self option enables client to receive message it broadcast
10
- * ack option instructs server to acknowlege that broadcast message was received
10
+ * ack option instructs server to acknowledge that broadcast message was received
11
11
  */
12
12
  broadcast?: {
13
13
  self?: boolean;
@@ -21,17 +21,42 @@ export declare type RealtimeChannelOptions = {
21
21
  };
22
22
  };
23
23
  };
24
- export declare type RealtimePostgresChangesPayload<T extends {
25
- [key: string]: any;
26
- }> = {
24
+ declare type RealtimePostgresChangesPayloadBase = {
27
25
  schema: string;
28
26
  table: string;
29
27
  commit_timestamp: string;
30
- eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}` | `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}` | `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`;
31
- new: T | {};
32
- old: Partial<T> | {};
33
28
  errors: string[];
34
29
  };
30
+ export declare type RealtimePostgresInsertPayload<T extends {
31
+ [key: string]: any;
32
+ }> = RealtimePostgresChangesPayloadBase & {
33
+ eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}`;
34
+ new: T;
35
+ old: {};
36
+ };
37
+ export declare type RealtimePostgresUpdatePayload<T extends {
38
+ [key: string]: any;
39
+ }> = RealtimePostgresChangesPayloadBase & {
40
+ eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}`;
41
+ new: T;
42
+ old: Partial<T>;
43
+ };
44
+ export declare type RealtimePostgresDeletePayload<T extends {
45
+ [key: string]: any;
46
+ }> = RealtimePostgresChangesPayloadBase & {
47
+ eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`;
48
+ new: {};
49
+ old: Partial<T>;
50
+ };
51
+ export declare type RealtimePostgresChangesPayload<T extends {
52
+ [key: string]: any;
53
+ }> = RealtimePostgresInsertPayload<T> | RealtimePostgresUpdatePayload<T> | RealtimePostgresDeletePayload<T>;
54
+ export declare type RealtimePostgresChangesFilter<T extends string> = {
55
+ event: T;
56
+ schema: string;
57
+ table?: string;
58
+ filter?: string;
59
+ };
35
60
  export declare type RealtimeChannelSendResponse = 'ok' | 'timed out' | 'rate limited';
36
61
  export declare enum REALTIME_POSTGRES_CHANGES_LISTEN_EVENT {
37
62
  ALL = "*",
@@ -50,7 +75,13 @@ export declare enum REALTIME_SUBSCRIBE_STATES {
50
75
  CLOSED = "CLOSED",
51
76
  CHANNEL_ERROR = "CHANNEL_ERROR"
52
77
  }
78
+ /** A channel is the basic building block of Realtime
79
+ * and narrows the scope of data flow to subscribed clients.
80
+ * You can think of a channel as a chatroom where participants are able to see who's online
81
+ * and send and receive messages.
82
+ **/
53
83
  export default class RealtimeChannel {
84
+ /** Topic name can be any string. */
54
85
  topic: string;
55
86
  params: RealtimeChannelOptions;
56
87
  socket: RealtimeClient;
@@ -71,7 +102,10 @@ export default class RealtimeChannel {
71
102
  rejoinTimer: Timer;
72
103
  pushBuffer: Push[];
73
104
  presence: RealtimePresence;
74
- constructor(topic: string, params: RealtimeChannelOptions, socket: RealtimeClient);
105
+ constructor(
106
+ /** Topic name can be any string. */
107
+ topic: string, params: RealtimeChannelOptions, socket: RealtimeClient);
108
+ /** Subscribe registers your client with the server */
75
109
  subscribe(callback?: (status: `${REALTIME_SUBSCRIBE_STATES}`, err?: Error) => void, timeout?: number): RealtimeChannel;
76
110
  presenceState(): RealtimePresenceState;
77
111
  track(payload: {
@@ -82,6 +116,19 @@ export default class RealtimeChannel {
82
116
  untrack(opts?: {
83
117
  [key: string]: any;
84
118
  }): Promise<RealtimeChannelSendResponse>;
119
+ /**
120
+ * Creates an event handler that listens to changes
121
+ * @param type Realtime feature (broadcast, presence, or postgres_changes)
122
+ * @param filter Pre-defined and custom values specific to the Realtime feature
123
+ * @param filter.schema Database schema
124
+ * @param filter.event Event to listen to. If listening to postgres_changes type
125
+ * then this value is one of INSERT, UPDATE, DELETE, *
126
+ * @param filter.filter If listening to postgres_changes type then this value is used to specify
127
+ * the Postgres Changes filter (eq, neq, lt, lte, gt, or gte) and value to listen to
128
+ * @param filter.table If listening to postgres_changes type then this value is used to specify
129
+ * the database table to listen to
130
+ * @param callback Function to be invoked when event handler is triggered
131
+ */
85
132
  on(type: `${REALTIME_LISTEN_TYPES.BROADCAST}`, filter: {
86
133
  event: string;
87
134
  }, callback: (payload: {
@@ -90,16 +137,30 @@ export default class RealtimeChannel {
90
137
  [key: string]: any;
91
138
  }) => void): RealtimeChannel;
92
139
  on(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: {
93
- event: `${REALTIME_PRESENCE_LISTEN_EVENTS}`;
94
- }, callback: (payload: RealtimePresenceJoinPayload | RealtimePresenceLeavePayload | undefined) => void): RealtimeChannel;
140
+ event: `${REALTIME_PRESENCE_LISTEN_EVENTS.SYNC}`;
141
+ }, callback: () => void): RealtimeChannel;
142
+ on<T extends {
143
+ [key: string]: any;
144
+ }>(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: {
145
+ event: `${REALTIME_PRESENCE_LISTEN_EVENTS.JOIN}`;
146
+ }, callback: (payload: RealtimePresenceJoinPayload<T>) => void): RealtimeChannel;
147
+ on<T extends {
148
+ [key: string]: any;
149
+ }>(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: {
150
+ event: `${REALTIME_PRESENCE_LISTEN_EVENTS.LEAVE}`;
151
+ }, callback: (payload: RealtimePresenceLeavePayload<T>) => void): RealtimeChannel;
95
152
  on<T extends {
96
153
  [key: string]: any;
97
- }>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: {
98
- event: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT}`;
99
- schema: string;
100
- table?: string;
101
- filter?: string;
102
- }, callback: (payload: RealtimePostgresChangesPayload<T>) => void): RealtimeChannel;
154
+ }>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL}`>, callback: (payload: RealtimePostgresChangesPayload<T>) => void): RealtimeChannel;
155
+ on<T extends {
156
+ [key: string]: any;
157
+ }>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}`>, callback: (payload: RealtimePostgresInsertPayload<T>) => void): RealtimeChannel;
158
+ on<T extends {
159
+ [key: string]: any;
160
+ }>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}`>, callback: (payload: RealtimePostgresUpdatePayload<T>) => void): RealtimeChannel;
161
+ on<T extends {
162
+ [key: string]: any;
163
+ }>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`>, callback: (payload: RealtimePostgresDeletePayload<T>) => void): RealtimeChannel;
103
164
  send(payload: {
104
165
  type: string;
105
166
  [key: string]: any;
@@ -119,45 +180,6 @@ export default class RealtimeChannel {
119
180
  * channel.unsubscribe().receive("ok", () => alert("left!") )
120
181
  */
121
182
  unsubscribe(timeout?: number): Promise<'ok' | 'timed out' | 'error'>;
122
- _push(event: string, payload: {
123
- [key: string]: any;
124
- }, timeout?: number): Push;
125
- /**
126
- * Overridable message hook
127
- *
128
- * Receives all events for specialized message handling before dispatching to the channel callbacks.
129
- * Must return the payload, modified or unmodified.
130
- */
131
- _onMessage(_event: string, payload: any, _ref?: string): any;
132
- _isMember(topic: string): boolean;
133
- _joinRef(): string;
134
- _trigger(type: string, payload?: any, ref?: string): void;
135
- _isClosed(): boolean;
136
- _isJoined(): boolean;
137
- _isJoining(): boolean;
138
- _isLeaving(): boolean;
139
- _replyEventName(ref: string): string;
140
- _on(type: string, filter: {
141
- [key: string]: any;
142
- }, callback: Function): this;
143
- _off(type: string, filter: {
144
- [key: string]: any;
145
- }): this;
146
- private static isEqual;
147
- private _rejoinUntilConnected;
148
- /**
149
- * Registers a callback that will be executed when the channel closes.
150
- */
151
- private _onClose;
152
- /**
153
- * Registers a callback that will be executed when the channel encounteres an error.
154
- */
155
- private _onError;
156
- /**
157
- * Returns `true` if the socket is connected and the channel has been joined.
158
- */
159
- private _canPush;
160
- private _rejoin;
161
- private _getPayloadRecords;
162
183
  }
184
+ export {};
163
185
  //# sourceMappingURL=RealtimeChannel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RealtimeChannel.d.ts","sourceRoot":"","sources":["../../src/RealtimeChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,IAAI,MAAM,YAAY,CAAA;AAC7B,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C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REALTIME_SUBSCRIBE_STATES;
61
61
  REALTIME_SUBSCRIBE_STATES["CLOSED"] = "CLOSED";
62
62
  REALTIME_SUBSCRIBE_STATES["CHANNEL_ERROR"] = "CHANNEL_ERROR";
63
63
  })(REALTIME_SUBSCRIBE_STATES = exports.REALTIME_SUBSCRIBE_STATES || (exports.REALTIME_SUBSCRIBE_STATES = {}));
64
+ /** A channel is the basic building block of Realtime
65
+ * and narrows the scope of data flow to subscribed clients.
66
+ * You can think of a channel as a chatroom where participants are able to see who's online
67
+ * and send and receive messages.
68
+ **/
64
69
  class RealtimeChannel {
65
- constructor(topic, params = { config: {} }, socket) {
70
+ constructor(
71
+ /** Topic name can be any string. */
72
+ topic, params = { config: {} }, socket) {
66
73
  this.topic = topic;
67
74
  this.params = params;
68
75
  this.socket = socket;
@@ -110,6 +117,7 @@ class RealtimeChannel {
110
117
  });
111
118
  this.presence = new RealtimePresence_1.default(this);
112
119
  }
120
+ /** Subscribe registers your client with the server */
113
121
  subscribe(callback, timeout = this.timeout) {
114
122
  var _a, _b;
115
123
  if (this.joinedOnce) {
@@ -258,6 +266,7 @@ class RealtimeChannel {
258
266
  }
259
267
  });
260
268
  }
269
+ /** @internal */
261
270
  _push(event, payload, timeout = this.timeout) {
262
271
  if (!this.joinedOnce) {
263
272
  throw `tried to push '${event}' to '${this.topic}' before joining. Use channel.subscribe() before pushing events`;
@@ -277,16 +286,21 @@ class RealtimeChannel {
277
286
  *
278
287
  * Receives all events for specialized message handling before dispatching to the channel callbacks.
279
288
  * Must return the payload, modified or unmodified.
289
+ *
290
+ * @internal
280
291
  */
281
292
  _onMessage(_event, payload, _ref) {
282
293
  return payload;
283
294
  }
295
+ /** @internal */
284
296
  _isMember(topic) {
285
297
  return this.topic === topic;
286
298
  }
299
+ /** @internal */
287
300
  _joinRef() {
288
301
  return this.joinPush.ref;
289
302
  }
303
+ /** @internal */
290
304
  _trigger(type, payload, ref) {
291
305
  var _a, _b;
292
306
  const typeLower = type.toLocaleLowerCase();
@@ -347,21 +361,27 @@ class RealtimeChannel {
347
361
  });
348
362
  }
349
363
  }
364
+ /** @internal */
350
365
  _isClosed() {
351
366
  return this.state === constants_1.CHANNEL_STATES.closed;
352
367
  }
368
+ /** @internal */
353
369
  _isJoined() {
354
370
  return this.state === constants_1.CHANNEL_STATES.joined;
355
371
  }
372
+ /** @internal */
356
373
  _isJoining() {
357
374
  return this.state === constants_1.CHANNEL_STATES.joining;
358
375
  }
376
+ /** @internal */
359
377
  _isLeaving() {
360
378
  return this.state === constants_1.CHANNEL_STATES.leaving;
361
379
  }
380
+ /** @internal */
362
381
  _replyEventName(ref) {
363
382
  return `chan_reply_${ref}`;
364
383
  }
384
+ /** @internal */
365
385
  _on(type, filter, callback) {
366
386
  const typeLower = type.toLocaleLowerCase();
367
387
  const binding = {
@@ -377,6 +397,7 @@ class RealtimeChannel {
377
397
  }
378
398
  return this;
379
399
  }
400
+ /** @internal */
380
401
  _off(type, filter) {
381
402
  const typeLower = type.toLocaleLowerCase();
382
403
  this.bindings[typeLower] = this.bindings[typeLower].filter((bind) => {
@@ -386,6 +407,7 @@ class RealtimeChannel {
386
407
  });
387
408
  return this;
388
409
  }
410
+ /** @internal */
389
411
  static isEqual(obj1, obj2) {
390
412
  if (Object.keys(obj1).length !== Object.keys(obj2).length) {
391
413
  return false;
@@ -397,6 +419,7 @@ class RealtimeChannel {
397
419
  }
398
420
  return true;
399
421
  }
422
+ /** @internal */
400
423
  _rejoinUntilConnected() {
401
424
  this.rejoinTimer.scheduleTimeout();
402
425
  if (this.socket.isConnected()) {
@@ -405,22 +428,29 @@ class RealtimeChannel {
405
428
  }
406
429
  /**
407
430
  * Registers a callback that will be executed when the channel closes.
431
+ *
432
+ * @internal
408
433
  */
409
434
  _onClose(callback) {
410
435
  this._on(constants_1.CHANNEL_EVENTS.close, {}, callback);
411
436
  }
412
437
  /**
413
438
  * Registers a callback that will be executed when the channel encounteres an error.
439
+ *
440
+ * @internal
414
441
  */
415
442
  _onError(callback) {
416
443
  this._on(constants_1.CHANNEL_EVENTS.error, {}, (reason) => callback(reason));
417
444
  }
418
445
  /**
419
446
  * Returns `true` if the socket is connected and the channel has been joined.
447
+ *
448
+ * @internal
420
449
  */
421
450
  _canPush() {
422
451
  return this.socket.isConnected() && this._isJoined();
423
452
  }
453
+ /** @internal */
424
454
  _rejoin(timeout = this.timeout) {
425
455
  if (this._isLeaving()) {
426
456
  return;
@@ -429,6 +459,7 @@ class RealtimeChannel {
429
459
  this.state = constants_1.CHANNEL_STATES.joining;
430
460
  this.joinPush.resend(timeout);
431
461
  }
462
+ /** @internal */
432
463
  _getPayloadRecords(payload) {
433
464
  const records = {
434
465
  new: {},