@qikdev/sdk 1.0.6 → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qikdev/sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "Promise based Javascript SDK",
6
6
  "main": "./dist/main.js",
@@ -141,6 +141,15 @@ const QikSocket = function(qik, mode) {
141
141
 
142
142
  dispatcher.dispatch('connected', event);
143
143
 
144
+ // Replay every recorded subscription — frames broadcast before the
145
+ // connection opened were dropped, and reconnects need them resent.
146
+ Object.keys(channels).forEach(function(channel) {
147
+ broadcast({
148
+ action: 'subscribe',
149
+ channel,
150
+ });
151
+ });
152
+
144
153
  // startHeartbeat();
145
154
  }
146
155
 
@@ -181,6 +190,14 @@ const QikSocket = function(qik, mode) {
181
190
  }
182
191
 
183
192
  async function broadcast(data) {
193
+ // A socket that exists but isn't OPEN (CONNECTING, CLOSING or CLOSED)
194
+ // throws InvalidStateError on send. Drop the frame instead — subscribe
195
+ // frames are replayed from `channels` when the connection opens.
196
+ if (!socket || socket.readyState !== WebSocket.OPEN) {
197
+ service.debug ? console.log('[socket] - frame dropped, socket not open', data) : null;
198
+ return;
199
+ }
200
+
184
201
  socket.send(JSON.stringify(data));
185
202
  }
186
203
 
@@ -251,17 +268,10 @@ const QikSocket = function(qik, mode) {
251
268
  }
252
269
 
253
270
  service.debug ? console.log(`[socket] reconnecting...`) : null;
254
-
255
- // Reconnect all listeners
256
- const result = await service.connect();
257
-
258
- // Resubscribe to all previously connected channels
259
- const subscribedChannels = Object.keys(channels);
260
- subscribedChannels.forEach(function(channel) {
261
- service.subscribe(channel);
262
- })
263
271
 
264
- return result;
272
+ // Reconnect all listeners. Previously subscribed channels are replayed
273
+ // by socketOpened() the moment the connection opens.
274
+ return await service.connect();
265
275
  }
266
276
 
267
277
 
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "1.0.6";
1
+ export const version = "1.0.7";