@reactoo/watchtogether-sdk-js 2.6.48 → 2.6.50

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.50",
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() {
@@ -478,10 +487,10 @@ class RoomSession {
478
487
  } else if (type === "webrtcup") {
479
488
  //none universal
480
489
  } else if (type === "hangup") {
481
- this._log('hangup on', handle.handleId);
490
+ this._log('hangup on', handle.handleId, handle.handleId === this.handleId, json);
482
491
  this._removeParticipant(handle.handleId, null, false);
483
492
  } else if (type === "detached") {
484
- this._log('detached on', handle.handleId);
493
+ this._log('detached on', handle.handleId, handle.handleId === this.handleId, json);
485
494
  this._removeParticipant(handle.handleId, null, true);
486
495
  } else if (type === "media") {
487
496
  this._log('Media event:', handle.handleId, json["type"], json["receiving"], json["mid"]);
@@ -490,6 +499,7 @@ class RoomSession {
490
499
  } else if (type === "event") {
491
500
  //none universal
492
501
  } else if (type === 'timeout') {
502
+ this._log('ws timeout', json);
493
503
  this.ws.close(3504, "Gateway timeout");
494
504
  } else if (type === 'success' || type === 'error') {
495
505
  // we're capturing those elsewhere
@@ -697,6 +707,7 @@ class RoomSession {
697
707
 
698
708
  if (jsep !== undefined && jsep !== null) {
699
709
 
710
+ console.log(msg)
700
711
  if (this.sessiontype === 'reactooroom') {
701
712
  this._webrtcPeer(this.handleId, jsep)
702
713
  .catch(err => {
@@ -895,6 +906,7 @@ class RoomSession {
895
906
  dtmfSender: null,
896
907
  trickle: true,
897
908
  iceDone: false,
909
+ isIceRestarting: false
898
910
  };
899
911
 
900
912
  if (handleId === this.handleId) {
@@ -945,6 +957,7 @@ class RoomSession {
945
957
  dtmfSender: null,
946
958
  trickle: true,
947
959
  iceDone: false,
960
+ isIceRestarting: false
948
961
  }
949
962
  };
950
963
  this._participants.push(handle);
@@ -1070,7 +1083,6 @@ class RoomSession {
1070
1083
  .then(json => {
1071
1084
  this.sessionId = json["session_id"] ? json["session_id"] : json.data["id"];
1072
1085
  this._startKeepAlive();
1073
- this._participants.map(p => this._iceRestart(p.handleId))
1074
1086
  this.isReclaiming = false;
1075
1087
  this.emit('joining', false);
1076
1088
  this._retries = 0;
@@ -1361,7 +1373,7 @@ class RoomSession {
1361
1373
  "janus": "trickle",
1362
1374
  "candidate": candidate,
1363
1375
  "handle_id": handleId
1364
- })
1376
+ }, false, false, 5)
1365
1377
  }
1366
1378
 
1367
1379
  _webrtc(handleId, enableOntrack = false) {
@@ -1429,6 +1441,7 @@ class RoomSession {
1429
1441
  };
1430
1442
  config.pc.oniceconnectionstatechange = () => {
1431
1443
  if (config.pc.iceConnectionState === 'failed') {
1444
+ this._log('iceConnectionState failed');
1432
1445
  this._iceRestart(handleId);
1433
1446
  }
1434
1447
  this.emit('iceState', [handleId, handleId === this.handleId, config.pc.iceConnectionState]);
@@ -1707,6 +1720,13 @@ class RoomSession {
1707
1720
  }
1708
1721
  var config = handle.webrtcStuff;
1709
1722
 
1723
+ // Already restarting;
1724
+ if (config.isIceRestarting) {
1725
+ return;
1726
+ }
1727
+
1728
+ config.isIceRestarting = true;
1729
+
1710
1730
  if (this.handleId === handleId) {
1711
1731
  this._log('Performing local ICE restart');
1712
1732
  let hasAudio = !!(config.stream && config.stream.getAudioTracks().length > 0);
@@ -1719,20 +1739,27 @@ class RoomSession {
1719
1739
  return this.sendMessage(handleId, {
1720
1740
  body: {"request": "configure", "audio": hasAudio, "video": hasVideo, "data": true, ...(this.recordingFilename ? {filename: this.recordingFilename} : {})},
1721
1741
  jsep
1722
- });
1742
+ }, false, false, 5);
1723
1743
  })
1724
1744
  .then(r => {
1745
+ config.isIceRestarting = false;
1725
1746
  this._log('ICE restart success');
1726
1747
  })
1727
1748
  .catch((e) => {
1749
+ config.isIceRestarting = false;
1728
1750
  this.emit('error', {type: 'warning', id: 28, message: 'iceRestart failed', data: e});
1729
1751
  });
1730
1752
  } else {
1731
1753
  this._log('Performing remote ICE restart', handleId);
1732
1754
  return this.sendMessage(handleId, {
1733
1755
  body: {"request": "configure", "restart": true}
1756
+ }, false, false, 5).then(() => {
1734
1757
  }).then(() => {
1735
- }).catch(() => {});
1758
+ config.isIceRestarting = false;
1759
+ this._log('ICE restart success');
1760
+ }).catch(() => {
1761
+ config.isIceRestarting = false;
1762
+ });
1736
1763
  }
1737
1764
 
1738
1765
  }
@@ -1872,6 +1899,13 @@ class RoomSession {
1872
1899
  "sdp": response.sdp
1873
1900
  };
1874
1901
 
1902
+ if(response.e2ee)
1903
+ jsep.e2ee = true;
1904
+ if(response.rid_order === "hml" || response.rid_order === "lmh")
1905
+ jsep.rid_order = response.rid_order;
1906
+ if(response.force_relay)
1907
+ jsep.force_relay = true;
1908
+
1875
1909
  return _p.then(() => jsep)
1876
1910
  }, (e) => {
1877
1911
  return Promise.reject({type: 'warning', id: 25, message: methodName, data: [handleId, e]})