@supabase/realtime-js 1.3.6 → 1.4.3
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.
- package/dist/main/RealtimeClient.d.ts +0 -1
- package/dist/main/RealtimeClient.d.ts.map +1 -1
- package/dist/main/RealtimeClient.js +1 -1
- package/dist/main/RealtimeClient.js.map +1 -1
- package/dist/main/RealtimePresence.d.ts +92 -0
- package/dist/main/RealtimePresence.d.ts.map +1 -0
- package/dist/main/RealtimePresence.js +198 -0
- package/dist/main/RealtimePresence.js.map +1 -0
- package/dist/main/index.d.ts +2 -1
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +3 -1
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +1 -2
- package/dist/main/lib/version.js.map +1 -1
- package/dist/module/RealtimeClient.d.ts +0 -1
- package/dist/module/RealtimeClient.d.ts.map +1 -1
- package/dist/module/RealtimeClient.js +2 -2
- package/dist/module/RealtimeClient.js.map +1 -1
- package/dist/module/RealtimePresence.d.ts +92 -0
- package/dist/module/RealtimePresence.d.ts.map +1 -0
- package/dist/module/RealtimePresence.js +192 -0
- package/dist/module/RealtimePresence.js.map +1 -0
- package/dist/module/index.d.ts +2 -1
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +2 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +1 -2
- package/dist/module/lib/version.js.map +1 -1
- package/package.json +6 -4
- package/src/RealtimeClient.ts +4 -4
- package/src/RealtimePresence.ts +319 -0
- package/src/index.ts +2 -0
- package/src/lib/version.ts +1 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { PresenceOpts, PresenceOnJoinCallback, PresenceOnLeaveCallback } from 'phoenix';
|
|
2
|
+
import RealtimeSubscription from './RealtimeSubscription';
|
|
3
|
+
declare type Presence = {
|
|
4
|
+
presence_id: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
declare type PresenceState = {
|
|
8
|
+
[key: string]: Presence[];
|
|
9
|
+
};
|
|
10
|
+
declare type PresenceDiff = {
|
|
11
|
+
joins: PresenceState;
|
|
12
|
+
leaves: PresenceState;
|
|
13
|
+
};
|
|
14
|
+
declare type RawPresenceState = {
|
|
15
|
+
[key: string]: Record<'metas', {
|
|
16
|
+
phx_ref?: string;
|
|
17
|
+
phx_ref_prev?: string;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}[]>;
|
|
20
|
+
};
|
|
21
|
+
declare type RawPresenceDiff = {
|
|
22
|
+
joins: RawPresenceState;
|
|
23
|
+
leaves: RawPresenceState;
|
|
24
|
+
};
|
|
25
|
+
declare type PresenceChooser<T> = (key: string, presences: any) => T;
|
|
26
|
+
export default class RealtimePresence {
|
|
27
|
+
channel: RealtimeSubscription;
|
|
28
|
+
state: PresenceState;
|
|
29
|
+
pendingDiffs: RawPresenceDiff[];
|
|
30
|
+
joinRef: string | null;
|
|
31
|
+
caller: {
|
|
32
|
+
onJoin: PresenceOnJoinCallback;
|
|
33
|
+
onLeave: PresenceOnLeaveCallback;
|
|
34
|
+
onSync: () => void;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Initializes the Presence
|
|
38
|
+
* @param channel - The RealtimeSubscription
|
|
39
|
+
* @param opts - The options,
|
|
40
|
+
* for example `{events: {state: 'state', diff: 'diff'}}`
|
|
41
|
+
*/
|
|
42
|
+
constructor(channel: RealtimeSubscription, opts?: PresenceOpts);
|
|
43
|
+
/**
|
|
44
|
+
* Used to sync the list of presences on the server
|
|
45
|
+
* with the client's state. An optional `onJoin` and `onLeave` callback can
|
|
46
|
+
* be provided to react to changes in the client's local presences across
|
|
47
|
+
* disconnects and reconnects with the server.
|
|
48
|
+
*/
|
|
49
|
+
static syncState(currentState: PresenceState, newState: RawPresenceState | PresenceState, onJoin: PresenceOnJoinCallback, onLeave: PresenceOnLeaveCallback): PresenceState;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* Used to sync a diff of presence join and leave
|
|
53
|
+
* events from the server, as they happen. Like `syncState`, `syncDiff`
|
|
54
|
+
* accepts optional `onJoin` and `onLeave` callbacks to react to a user
|
|
55
|
+
* joining or leaving from a device.
|
|
56
|
+
*/
|
|
57
|
+
static syncDiff(state: PresenceState, diff: RawPresenceDiff | PresenceDiff, onJoin: PresenceOnJoinCallback, onLeave: PresenceOnLeaveCallback): PresenceState;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the array of presences, with selected metadata.
|
|
60
|
+
*/
|
|
61
|
+
static list<T = any>(presences: PresenceState, chooser: PresenceChooser<T> | undefined): T[];
|
|
62
|
+
private static map;
|
|
63
|
+
/**
|
|
64
|
+
* Remove 'metas' key
|
|
65
|
+
* Change 'phx_ref' to 'presence_id'
|
|
66
|
+
* Remove 'phx_ref' and 'phx_ref_prev'
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // returns {
|
|
70
|
+
* abc123: [
|
|
71
|
+
* { presence_id: '2', user_id: 1 },
|
|
72
|
+
* { presence_id: '3', user_id: 2 }
|
|
73
|
+
* ]
|
|
74
|
+
* }
|
|
75
|
+
* RealtimePresence.transformState({
|
|
76
|
+
* abc123: {
|
|
77
|
+
* metas: [
|
|
78
|
+
* { phx_ref: '2', phx_ref_prev: '1' user_id: 1 },
|
|
79
|
+
* { phx_ref: '3', user_id: 2 }
|
|
80
|
+
* ]
|
|
81
|
+
* }
|
|
82
|
+
* })
|
|
83
|
+
*/
|
|
84
|
+
private static transformState;
|
|
85
|
+
onJoin(callback: PresenceOnJoinCallback): void;
|
|
86
|
+
onLeave(callback: PresenceOnLeaveCallback): void;
|
|
87
|
+
onSync(callback: () => void): void;
|
|
88
|
+
list<T = any>(by?: PresenceChooser<T>): T[];
|
|
89
|
+
private inPendingSyncState;
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=RealtimePresence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealtimePresence.d.ts","sourceRoot":"","sources":["../../src/RealtimePresence.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAChB,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;AAEzD,aAAK,QAAQ,GAAG;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,CAAA;AAED,aAAK,aAAa,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAA;CAAE,CAAA;AAElD,aAAK,YAAY,GAAG;IAClB,KAAK,EAAE,aAAa,CAAA;IACpB,MAAM,EAAE,aAAa,CAAA;CACtB,CAAA;AAED,aAAK,gBAAgB,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CACnB,OAAO,EACP;QACE,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACnB,EAAE,CACJ,CAAA;CACF,CAAA;AAED,aAAK,eAAe,GAAG;IACrB,KAAK,EAAE,gBAAgB,CAAA;IACvB,MAAM,EAAE,gBAAgB,CAAA;CACzB,CAAA;AAED,aAAK,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC,CAAA;AAE5D,MAAM,CAAC,OAAO,OAAO,gBAAgB;IAoBhB,OAAO,EAAE,oBAAoB;IAnBhD,KAAK,EAAE,aAAa,CAAK;IACzB,YAAY,EAAE,eAAe,EAAE,CAAK;IACpC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAO;IAC7B,MAA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f/assets/js/phoenix/presence.js
|
|
3
|
+
License: https://github.com/phoenixframework/phoenix/blob/d344ec0a732ab4ee204215b31de69cf4be72e3bf/LICENSE.md
|
|
4
|
+
*/
|
|
5
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
6
|
+
export default class RealtimePresence {
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the Presence
|
|
9
|
+
* @param channel - The RealtimeSubscription
|
|
10
|
+
* @param opts - The options,
|
|
11
|
+
* for example `{events: {state: 'state', diff: 'diff'}}`
|
|
12
|
+
*/
|
|
13
|
+
constructor(channel, opts) {
|
|
14
|
+
this.channel = channel;
|
|
15
|
+
this.state = {};
|
|
16
|
+
this.pendingDiffs = [];
|
|
17
|
+
this.joinRef = null;
|
|
18
|
+
this.caller = {
|
|
19
|
+
onJoin: () => { },
|
|
20
|
+
onLeave: () => { },
|
|
21
|
+
onSync: () => { },
|
|
22
|
+
};
|
|
23
|
+
const events = (opts === null || opts === void 0 ? void 0 : opts.events) || {
|
|
24
|
+
state: 'presence_state',
|
|
25
|
+
diff: 'presence_diff',
|
|
26
|
+
};
|
|
27
|
+
this.channel.on(events.state, (newState) => {
|
|
28
|
+
const { onJoin, onLeave, onSync } = this.caller;
|
|
29
|
+
this.joinRef = this.channel.joinRef();
|
|
30
|
+
this.state = RealtimePresence.syncState(this.state, newState, onJoin, onLeave);
|
|
31
|
+
this.pendingDiffs.forEach((diff) => {
|
|
32
|
+
this.state = RealtimePresence.syncDiff(this.state, diff, onJoin, onLeave);
|
|
33
|
+
});
|
|
34
|
+
this.pendingDiffs = [];
|
|
35
|
+
onSync();
|
|
36
|
+
});
|
|
37
|
+
this.channel.on(events.diff, (diff) => {
|
|
38
|
+
const { onJoin, onLeave, onSync } = this.caller;
|
|
39
|
+
if (this.inPendingSyncState()) {
|
|
40
|
+
this.pendingDiffs.push(diff);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.state = RealtimePresence.syncDiff(this.state, diff, onJoin, onLeave);
|
|
44
|
+
onSync();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Used to sync the list of presences on the server
|
|
50
|
+
* with the client's state. An optional `onJoin` and `onLeave` callback can
|
|
51
|
+
* be provided to react to changes in the client's local presences across
|
|
52
|
+
* disconnects and reconnects with the server.
|
|
53
|
+
*/
|
|
54
|
+
static syncState(currentState, newState, onJoin, onLeave) {
|
|
55
|
+
const state = cloneDeep(currentState);
|
|
56
|
+
const transformedState = this.transformState(newState);
|
|
57
|
+
const joins = {};
|
|
58
|
+
const leaves = {};
|
|
59
|
+
this.map(state, (key, presences) => {
|
|
60
|
+
if (!transformedState[key]) {
|
|
61
|
+
leaves[key] = presences;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
this.map(transformedState, (key, newPresences) => {
|
|
65
|
+
const currentPresences = state[key];
|
|
66
|
+
if (currentPresences) {
|
|
67
|
+
const newPresenceIds = newPresences.map((m) => m.presence_id);
|
|
68
|
+
const curPresenceIds = currentPresences.map((m) => m.presence_id);
|
|
69
|
+
const joinedPresences = newPresences.filter((m) => curPresenceIds.indexOf(m.presence_id) < 0);
|
|
70
|
+
const leftPresences = currentPresences.filter((m) => newPresenceIds.indexOf(m.presence_id) < 0);
|
|
71
|
+
if (joinedPresences.length > 0) {
|
|
72
|
+
joins[key] = joinedPresences;
|
|
73
|
+
}
|
|
74
|
+
if (leftPresences.length > 0) {
|
|
75
|
+
leaves[key] = leftPresences;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
joins[key] = newPresences;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return this.syncDiff(state, { joins, leaves }, onJoin, onLeave);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* Used to sync a diff of presence join and leave
|
|
87
|
+
* events from the server, as they happen. Like `syncState`, `syncDiff`
|
|
88
|
+
* accepts optional `onJoin` and `onLeave` callbacks to react to a user
|
|
89
|
+
* joining or leaving from a device.
|
|
90
|
+
*/
|
|
91
|
+
static syncDiff(state, diff, onJoin, onLeave) {
|
|
92
|
+
const { joins, leaves } = {
|
|
93
|
+
joins: this.transformState(diff.joins),
|
|
94
|
+
leaves: this.transformState(diff.leaves),
|
|
95
|
+
};
|
|
96
|
+
if (!onJoin) {
|
|
97
|
+
onJoin = () => { };
|
|
98
|
+
}
|
|
99
|
+
if (!onLeave) {
|
|
100
|
+
onLeave = () => { };
|
|
101
|
+
}
|
|
102
|
+
this.map(joins, (key, newPresences) => {
|
|
103
|
+
const currentPresences = state[key];
|
|
104
|
+
state[key] = cloneDeep(newPresences);
|
|
105
|
+
if (currentPresences) {
|
|
106
|
+
const joinedPresenceIds = state[key].map((m) => m.presence_id);
|
|
107
|
+
const curPresences = currentPresences.filter((m) => joinedPresenceIds.indexOf(m.presence_id) < 0);
|
|
108
|
+
state[key].unshift(...curPresences);
|
|
109
|
+
}
|
|
110
|
+
onJoin(key, currentPresences, newPresences);
|
|
111
|
+
});
|
|
112
|
+
this.map(leaves, (key, leftPresences) => {
|
|
113
|
+
let currentPresences = state[key];
|
|
114
|
+
if (!currentPresences)
|
|
115
|
+
return;
|
|
116
|
+
const presenceIdsToRemove = leftPresences.map((m) => m.presence_id);
|
|
117
|
+
currentPresences = currentPresences.filter((m) => presenceIdsToRemove.indexOf(m.presence_id) < 0);
|
|
118
|
+
state[key] = currentPresences;
|
|
119
|
+
onLeave(key, currentPresences, leftPresences);
|
|
120
|
+
if (currentPresences.length === 0)
|
|
121
|
+
delete state[key];
|
|
122
|
+
});
|
|
123
|
+
return state;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns the array of presences, with selected metadata.
|
|
127
|
+
*/
|
|
128
|
+
static list(presences, chooser) {
|
|
129
|
+
if (!chooser) {
|
|
130
|
+
chooser = (_key, pres) => pres;
|
|
131
|
+
}
|
|
132
|
+
return this.map(presences, (key, presences) => chooser(key, presences));
|
|
133
|
+
}
|
|
134
|
+
static map(obj, func) {
|
|
135
|
+
return Object.getOwnPropertyNames(obj).map((key) => func(key, obj[key]));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Remove 'metas' key
|
|
139
|
+
* Change 'phx_ref' to 'presence_id'
|
|
140
|
+
* Remove 'phx_ref' and 'phx_ref_prev'
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* // returns {
|
|
144
|
+
* abc123: [
|
|
145
|
+
* { presence_id: '2', user_id: 1 },
|
|
146
|
+
* { presence_id: '3', user_id: 2 }
|
|
147
|
+
* ]
|
|
148
|
+
* }
|
|
149
|
+
* RealtimePresence.transformState({
|
|
150
|
+
* abc123: {
|
|
151
|
+
* metas: [
|
|
152
|
+
* { phx_ref: '2', phx_ref_prev: '1' user_id: 1 },
|
|
153
|
+
* { phx_ref: '3', user_id: 2 }
|
|
154
|
+
* ]
|
|
155
|
+
* }
|
|
156
|
+
* })
|
|
157
|
+
*/
|
|
158
|
+
static transformState(state) {
|
|
159
|
+
state = cloneDeep(state);
|
|
160
|
+
return Object.getOwnPropertyNames(state).reduce((newState, key) => {
|
|
161
|
+
const presences = state[key];
|
|
162
|
+
if ('metas' in presences) {
|
|
163
|
+
newState[key] = presences.metas.map((presence) => {
|
|
164
|
+
presence['presence_id'] = presence['phx_ref'];
|
|
165
|
+
delete presence['phx_ref'];
|
|
166
|
+
delete presence['phx_ref_prev'];
|
|
167
|
+
return presence;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
newState[key] = presences;
|
|
172
|
+
}
|
|
173
|
+
return newState;
|
|
174
|
+
}, {});
|
|
175
|
+
}
|
|
176
|
+
onJoin(callback) {
|
|
177
|
+
this.caller.onJoin = callback;
|
|
178
|
+
}
|
|
179
|
+
onLeave(callback) {
|
|
180
|
+
this.caller.onLeave = callback;
|
|
181
|
+
}
|
|
182
|
+
onSync(callback) {
|
|
183
|
+
this.caller.onSync = callback;
|
|
184
|
+
}
|
|
185
|
+
list(by) {
|
|
186
|
+
return RealtimePresence.list(this.state, by);
|
|
187
|
+
}
|
|
188
|
+
inPendingSyncState() {
|
|
189
|
+
return !this.joinRef || this.joinRef !== this.channel.joinRef();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=RealtimePresence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealtimePresence.js","sourceRoot":"","sources":["../../src/RealtimePresence.ts"],"names":[],"mappings":"AAAA;;;EAGE;AAEF,OAAO,SAAS,MAAM,kBAAkB,CAAA;AAsCxC,MAAM,CAAC,OAAO,OAAO,gBAAgB;IAcnC;;;;;OAKG;IACH,YAAmB,OAA6B,EAAE,IAAmB;QAAlD,YAAO,GAAP,OAAO,CAAsB;QAnBhD,UAAK,GAAkB,EAAE,CAAA;QACzB,iBAAY,GAAsB,EAAE,CAAA;QACpC,YAAO,GAAkB,IAAI,CAAA;QAC7B,WAAM,GAIF;YACF,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;YAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;YACjB,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;SACjB,CAAA;QASC,MAAM,MAAM,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,KAAI;YAC7B,KAAK,EAAE,gBAAgB;YACvB,IAAI,EAAE,eAAe;SACtB,CAAA;QAED,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,QAA0B,EAAE,EAAE;YAC3D,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;YAE/C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;YAErC,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC,SAAS,CACrC,IAAI,CAAC,KAAK,EACV,QAAQ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index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Transformers from './lib/transformers';
|
|
2
2
|
import RealtimeClient, { Options as RealtimeClientOptions } from './RealtimeClient';
|
|
3
3
|
import RealtimeSubscription from './RealtimeSubscription';
|
|
4
|
-
|
|
4
|
+
import RealtimePresence from './RealtimePresence';
|
|
5
|
+
export { RealtimeClient, RealtimeClientOptions, RealtimeSubscription, RealtimePresence, Transformers, };
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAA;AAClD,OAAO,cAAc,EAAE,EACrB,OAAO,IAAI,qBAAqB,EACjC,MAAM,kBAAkB,CAAA;AACzB,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAA;AAClD,OAAO,cAAc,EAAE,EACrB,OAAO,IAAI,qBAAqB,EACjC,MAAM,kBAAkB,CAAA;AACzB,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;AACzD,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,GACb,CAAA"}
|
package/dist/module/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Transformers from './lib/transformers';
|
|
2
2
|
import RealtimeClient from './RealtimeClient';
|
|
3
3
|
import RealtimeSubscription from './RealtimeSubscription';
|
|
4
|
-
|
|
4
|
+
import RealtimePresence from './RealtimePresence';
|
|
5
|
+
export { RealtimeClient, RealtimeSubscription, RealtimePresence, Transformers, };
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAA;AAClD,OAAO,cAEN,MAAM,kBAAkB,CAAA;AACzB,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAA;AAClD,OAAO,cAEN,MAAM,kBAAkB,CAAA;AACzB,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;AACzD,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EACL,cAAc,EAEd,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,GACb,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.3
|
|
1
|
+
export declare const version = "1.4.3";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oBAAoB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/realtime-js",
|
|
3
|
-
"version": "1.3
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Listen to realtime updates to your PostgreSQL database",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"realtime",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"clean": "rimraf dist docs",
|
|
27
27
|
"format": "prettier --write \"{src,test}/**/*.ts\"",
|
|
28
|
-
"build": "
|
|
28
|
+
"build": "run-s clean format build:*",
|
|
29
29
|
"build:main": "tsc -p tsconfig.json",
|
|
30
30
|
"build:module": "tsc -p tsconfig.module.json",
|
|
31
31
|
"mocha": "node -r esm node_modules/.bin/mocha ./test/**/*.js -r jsdom-global/register",
|
|
@@ -34,16 +34,18 @@
|
|
|
34
34
|
"docs:json": "typedoc --json docs/spec.json --mode modules --includeDeclarations --excludeExternals"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"
|
|
37
|
+
"lodash.clonedeep": "^4.5.0",
|
|
38
38
|
"websocket": "^1.0.34"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@babel/runtime": "^7.9.2",
|
|
42
|
+
"@types/lodash.clonedeep": "^4.5.6",
|
|
43
|
+
"@types/phoenix": "^1.5.4",
|
|
44
|
+
"@types/websocket": "^1.0.3",
|
|
42
45
|
"babel-preset-env": "^1.7.0",
|
|
43
46
|
"babel-register": "^6.26.0",
|
|
44
47
|
"eslint": "^7.0.0",
|
|
45
48
|
"esm": "^3.2.25",
|
|
46
|
-
"genversion": "^3.0.1",
|
|
47
49
|
"jsdom": "16.4.0",
|
|
48
50
|
"jsdom-global": "3.0.0",
|
|
49
51
|
"mocha": "^8.0.1",
|
package/src/RealtimeClient.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { w3cwebsocket } from 'websocket'
|
|
1
2
|
import {
|
|
2
3
|
VSN,
|
|
3
4
|
CHANNEL_EVENTS,
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
} from './lib/constants'
|
|
10
11
|
import Timer from './lib/timer'
|
|
11
12
|
import RealtimeSubscription from './RealtimeSubscription'
|
|
12
|
-
import { w3cwebsocket as WebSocket } from 'websocket'
|
|
13
13
|
import Serializer from './lib/serializer'
|
|
14
14
|
|
|
15
15
|
export type Options = {
|
|
@@ -40,7 +40,7 @@ export default class RealtimeClient {
|
|
|
40
40
|
headers?: { [key: string]: string } = DEFAULT_HEADERS
|
|
41
41
|
params?: { [key: string]: string } = {}
|
|
42
42
|
timeout: number = DEFAULT_TIMEOUT
|
|
43
|
-
transport: any =
|
|
43
|
+
transport: any = w3cwebsocket
|
|
44
44
|
heartbeatIntervalMs: number = 30000
|
|
45
45
|
longpollerTimeout: number = 20000
|
|
46
46
|
heartbeatTimer: ReturnType<typeof setInterval> | undefined = undefined
|
|
@@ -126,7 +126,7 @@ export default class RealtimeClient {
|
|
|
126
126
|
// this.conn.timeout = this.longpollerTimeout // TYPE ERROR
|
|
127
127
|
this.conn.binaryType = 'arraybuffer'
|
|
128
128
|
this.conn.onopen = () => this._onConnOpen()
|
|
129
|
-
this.conn.onerror = (error) => this._onConnError(error)
|
|
129
|
+
this.conn.onerror = (error) => this._onConnError(error as ErrorEvent)
|
|
130
130
|
this.conn.onmessage = (event) => this.onConnMessage(event)
|
|
131
131
|
this.conn.onclose = (event) => this._onConnClose(event)
|
|
132
132
|
}
|
|
@@ -371,7 +371,7 @@ export default class RealtimeClient {
|
|
|
371
371
|
this.stateChangeCallbacks.close.forEach((callback) => callback(event))
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
private _onConnError(error:
|
|
374
|
+
private _onConnError(error: ErrorEvent) {
|
|
375
375
|
this.log('transport', error.message)
|
|
376
376
|
this._triggerChanError()
|
|
377
377
|
this.stateChangeCallbacks.error.forEach((callback) => callback(error))
|