@reactoo/watchtogether-sdk-js 2.6.47 → 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
package/src/modules/wt-room.js
CHANGED
|
@@ -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
|
-
},
|
|
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]);
|
|
@@ -1669,6 +1678,10 @@ class RoomSession {
|
|
|
1669
1678
|
return Promise.resolve(null);
|
|
1670
1679
|
}
|
|
1671
1680
|
|
|
1681
|
+
if(config.pc.signalingState === 'stable') {
|
|
1682
|
+
//TODO
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1672
1685
|
return config.pc.setRemoteDescription(jsep)
|
|
1673
1686
|
.then(() => {
|
|
1674
1687
|
config.remoteSdp = jsep.sdp;
|
|
@@ -1686,6 +1699,9 @@ class RoomSession {
|
|
|
1686
1699
|
}
|
|
1687
1700
|
// Done
|
|
1688
1701
|
return true;
|
|
1702
|
+
})
|
|
1703
|
+
.catch((e) => {
|
|
1704
|
+
return Promise.reject({type: 'warning', id: 32, message: 'rtc peer', data: [handleId, e]});
|
|
1689
1705
|
});
|
|
1690
1706
|
} else {
|
|
1691
1707
|
return Promise.reject({type: 'warning', id: 22, message: 'rtc peer', data: [handleId, 'invalid jsep']});
|
|
@@ -1699,12 +1715,6 @@ class RoomSession {
|
|
|
1699
1715
|
return;
|
|
1700
1716
|
}
|
|
1701
1717
|
var config = handle.webrtcStuff;
|
|
1702
|
-
|
|
1703
|
-
if(config.pc.signalingState === 'stable') {
|
|
1704
|
-
this._log('ICE restart not needed');
|
|
1705
|
-
return;
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
1718
|
if (this.handleId === handleId) {
|
|
1709
1719
|
this._log('Performing local ICE restart');
|
|
1710
1720
|
let hasAudio = !!(config.stream && config.stream.getAudioTracks().length > 0);
|
|
@@ -1717,7 +1727,7 @@ class RoomSession {
|
|
|
1717
1727
|
return this.sendMessage(handleId, {
|
|
1718
1728
|
body: {"request": "configure", "audio": hasAudio, "video": hasVideo, "data": true, ...(this.recordingFilename ? {filename: this.recordingFilename} : {})},
|
|
1719
1729
|
jsep
|
|
1720
|
-
});
|
|
1730
|
+
}, false, false, 5);
|
|
1721
1731
|
})
|
|
1722
1732
|
.then(r => {
|
|
1723
1733
|
this._log('ICE restart success');
|
|
@@ -1729,7 +1739,7 @@ class RoomSession {
|
|
|
1729
1739
|
this._log('Performing remote ICE restart', handleId);
|
|
1730
1740
|
return this.sendMessage(handleId, {
|
|
1731
1741
|
body: {"request": "configure", "restart": true}
|
|
1732
|
-
}).then(() => {
|
|
1742
|
+
}, false, false, 5).then(() => {
|
|
1733
1743
|
}).catch(() => {});
|
|
1734
1744
|
}
|
|
1735
1745
|
|