@reactoo/watchtogether-sdk-js 2.6.48 → 2.6.49

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": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.6.48",
3
+ "version": "2.6.49",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -2,7 +2,7 @@
2
2
 
3
3
  import adapter from 'webrtc-adapter';
4
4
  import emitter from './wt-emitter';
5
- import {decodeJanusDisplay, generateUUID} from "./wt-utils";
5
+ import {decodeJanusDisplay, generateUUID, wait} from "./wt-utils";
6
6
 
7
7
  class Room {
8
8
 
@@ -305,12 +305,12 @@ class RoomSession {
305
305
  }
306
306
  }
307
307
 
308
- sendMessage(handleId, message = {body: 'Example Body'}, dontWait = false, dontResolveOnAck = false) {
308
+ sendMessage(handleId, message = {body: 'Example Body'}, dontWait = false, dontResolveOnAck = false, retry = 0) {
309
309
  return this._send({
310
310
  "janus": "message",
311
311
  "handle_id": handleId,
312
312
  ...message
313
- }, dontWait, dontResolveOnAck)
313
+ }, dontWait, dontResolveOnAck, retry)
314
314
  .then(json => {
315
315
  if (json && json["janus"] === "success") {
316
316
  let plugindata = json["plugindata"] || {};
@@ -328,19 +328,17 @@ class RoomSession {
328
328
  })
329
329
  }
330
330
 
331
- _send(request = {}, ignoreResponse = false, dontResolveOnAck = false) {
331
+ _send(request = {}, ignoreResponse = false, dontResolveOnAck = false, retry = 0) {
332
+
332
333
  let transaction = RoomSession.randomString(12);
333
334
  let requestData = {
334
335
  ...request,
335
336
  transaction,
336
337
  token: this.token, ...((this.sessionId && {'session_id': this.sessionId}) || {})
337
338
  };
338
-
339
339
  this._log(requestData);
340
-
341
- return new Promise((resolve, reject) => {
340
+ const op = () => new Promise((resolve, reject) => {
342
341
  let messageTimeoutId = null;
343
-
344
342
  let abortResponse = () => {
345
343
  this._abortController.signal.removeEventListener('abort', abortResponse);
346
344
  clearTimeout(messageTimeoutId);
@@ -371,18 +369,14 @@ class RoomSession {
371
369
  this.ws.send(JSON.stringify(requestData));
372
370
  }
373
371
  resolve();
374
-
375
372
  } else {
376
373
  if (this.ws && this.ws.readyState === 1) {
377
-
378
374
  this.ws.addEventListener('message', parseResponse);
379
-
380
375
  messageTimeoutId = setTimeout(() => {
381
376
  this.ws.removeEventListener('message', parseResponse);
382
377
  this._abortController.signal.removeEventListener('abort', abortResponse);
383
378
  reject({type: 'warning', id: 3, message: 'send timeout', data: requestData});
384
- }, 10000);
385
-
379
+ }, 5000);
386
380
  this._abortController.signal.addEventListener('abort', abortResponse);
387
381
  this.ws.send(JSON.stringify(requestData));
388
382
  } else {
@@ -390,6 +384,21 @@ class RoomSession {
390
384
  }
391
385
  }
392
386
  })
387
+
388
+ return op().catch(e => {
389
+ if (e.id === 17) {
390
+ return Promise.reject(e);
391
+ }
392
+ else if(e.id === 29 && retry > 0) {
393
+ return wait(5000).then(() => this._send(request, ignoreResponse, dontResolveOnAck, retry - 1));
394
+ }
395
+ else if(retry > 0) {
396
+ return this._send(request, ignoreResponse, dontResolveOnAck, retry - 1);
397
+ }
398
+ else {
399
+ return Promise.reject(e);
400
+ }
401
+ })
393
402
  }
394
403
 
395
404
  _connectionClosed() {
@@ -1070,7 +1079,6 @@ class RoomSession {
1070
1079
  .then(json => {
1071
1080
  this.sessionId = json["session_id"] ? json["session_id"] : json.data["id"];
1072
1081
  this._startKeepAlive();
1073
- this._participants.map(p => this._iceRestart(p.handleId))
1074
1082
  this.isReclaiming = false;
1075
1083
  this.emit('joining', false);
1076
1084
  this._retries = 0;
@@ -1361,7 +1369,7 @@ class RoomSession {
1361
1369
  "janus": "trickle",
1362
1370
  "candidate": candidate,
1363
1371
  "handle_id": handleId
1364
- })
1372
+ }, false, false, 5)
1365
1373
  }
1366
1374
 
1367
1375
  _webrtc(handleId, enableOntrack = false) {
@@ -1429,6 +1437,7 @@ class RoomSession {
1429
1437
  };
1430
1438
  config.pc.oniceconnectionstatechange = () => {
1431
1439
  if (config.pc.iceConnectionState === 'failed') {
1440
+ this._log('iceConnectionState failed');
1432
1441
  this._iceRestart(handleId);
1433
1442
  }
1434
1443
  this.emit('iceState', [handleId, handleId === this.handleId, config.pc.iceConnectionState]);
@@ -1706,7 +1715,6 @@ class RoomSession {
1706
1715
  return;
1707
1716
  }
1708
1717
  var config = handle.webrtcStuff;
1709
-
1710
1718
  if (this.handleId === handleId) {
1711
1719
  this._log('Performing local ICE restart');
1712
1720
  let hasAudio = !!(config.stream && config.stream.getAudioTracks().length > 0);
@@ -1719,7 +1727,7 @@ class RoomSession {
1719
1727
  return this.sendMessage(handleId, {
1720
1728
  body: {"request": "configure", "audio": hasAudio, "video": hasVideo, "data": true, ...(this.recordingFilename ? {filename: this.recordingFilename} : {})},
1721
1729
  jsep
1722
- });
1730
+ }, false, false, 5);
1723
1731
  })
1724
1732
  .then(r => {
1725
1733
  this._log('ICE restart success');
@@ -1731,7 +1739,7 @@ class RoomSession {
1731
1739
  this._log('Performing remote ICE restart', handleId);
1732
1740
  return this.sendMessage(handleId, {
1733
1741
  body: {"request": "configure", "restart": true}
1734
- }).then(() => {
1742
+ }, false, false, 5).then(() => {
1735
1743
  }).catch(() => {});
1736
1744
  }
1737
1745