@reactoo/watchtogether-sdk-js 2.8.10 → 2.8.11
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
|
@@ -234,6 +234,7 @@ class RoomSession {
|
|
|
234
234
|
this.enableDtx = false;
|
|
235
235
|
this.simulcast = false;
|
|
236
236
|
|
|
237
|
+
|
|
237
238
|
this.defaultSimulcastSettings = {
|
|
238
239
|
"default" : {
|
|
239
240
|
mode: "controlled", // controlled, manual, browserControlled
|
|
@@ -274,7 +275,7 @@ class RoomSession {
|
|
|
274
275
|
this.sessionId = null;
|
|
275
276
|
this.apisecret = null;
|
|
276
277
|
this.ws = null;
|
|
277
|
-
|
|
278
|
+
this.wsOpen = false;
|
|
278
279
|
|
|
279
280
|
// helper flags
|
|
280
281
|
|
|
@@ -292,6 +293,7 @@ class RoomSession {
|
|
|
292
293
|
this.requestMuteStatusTimeout = 100;
|
|
293
294
|
this._statsInterval = 3000;
|
|
294
295
|
this._statsIntervalId = null;
|
|
296
|
+
this._sendMessageWebsocketTimeout = 30000;
|
|
295
297
|
this._sendMessageTimeout = 10000;
|
|
296
298
|
this._keepAlivePeriod = 25000;
|
|
297
299
|
this._longPollTimeout = 60000;
|
|
@@ -503,6 +505,7 @@ class RoomSession {
|
|
|
503
505
|
id,
|
|
504
506
|
userId,
|
|
505
507
|
role,
|
|
508
|
+
mid,
|
|
506
509
|
fullUserId: display,
|
|
507
510
|
constructId: this.constructId,
|
|
508
511
|
track: track,
|
|
@@ -542,6 +545,7 @@ class RoomSession {
|
|
|
542
545
|
role,
|
|
543
546
|
fullUserId: display,
|
|
544
547
|
constructId: this.constructId,
|
|
548
|
+
mid: null,
|
|
545
549
|
track: null,
|
|
546
550
|
source: null,
|
|
547
551
|
adding: false,
|
|
@@ -958,21 +962,36 @@ class RoomSession {
|
|
|
958
962
|
};
|
|
959
963
|
this._log(requestData);
|
|
960
964
|
const op = () => new Promise((resolve, reject) => {
|
|
965
|
+
|
|
961
966
|
let messageTimeoutId = null;
|
|
962
|
-
|
|
963
|
-
|
|
967
|
+
|
|
968
|
+
let cleanup = () => {
|
|
964
969
|
clearTimeout(messageTimeoutId);
|
|
970
|
+
this._abortController.signal.removeEventListener('abort', abortResponse);
|
|
965
971
|
this.ws.removeEventListener('message', parseResponse);
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
let abortResponse = () => {
|
|
975
|
+
cleanup();
|
|
966
976
|
reject({type: 'warning', id: 4, message: 'connection cancelled'})
|
|
967
977
|
};
|
|
968
978
|
|
|
979
|
+
// we may get multiple responses from parallel requests, so we need to make sure we only resolve the one we sent
|
|
980
|
+
|
|
969
981
|
let parseResponse = (event) => {
|
|
970
|
-
let json
|
|
982
|
+
let json;
|
|
983
|
+
try {
|
|
984
|
+
json = JSON.parse(event.data);
|
|
985
|
+
}
|
|
986
|
+
catch (e) {}
|
|
987
|
+
|
|
988
|
+
if(!json) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
|
|
971
992
|
let r_transaction = json['transaction'];
|
|
972
993
|
if (r_transaction === transaction && (!dontResolveOnAck || json['janus'] !== 'ack')) {
|
|
973
|
-
|
|
974
|
-
this._abortController.signal.removeEventListener('abort', abortResponse);
|
|
975
|
-
this.ws.removeEventListener('message', parseResponse);
|
|
994
|
+
cleanup();
|
|
976
995
|
if (json['janus'] === 'error') {
|
|
977
996
|
if (json?.error?.code == 403) {
|
|
978
997
|
this.disconnect();
|
|
@@ -989,20 +1008,23 @@ class RoomSession {
|
|
|
989
1008
|
this.ws.send(JSON.stringify(requestData));
|
|
990
1009
|
}
|
|
991
1010
|
resolve();
|
|
992
|
-
}
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
993
1013
|
if (this.ws && this.ws.readyState === 1) {
|
|
1014
|
+
|
|
994
1015
|
this.ws.addEventListener('message', parseResponse);
|
|
1016
|
+
|
|
995
1017
|
messageTimeoutId = setTimeout(() => {
|
|
996
|
-
|
|
997
|
-
this._abortController.signal.removeEventListener('abort', abortResponse);
|
|
1018
|
+
cleanup();
|
|
998
1019
|
reject({type: 'warning', id: 6, message: 'send timeout', data: requestData});
|
|
999
1020
|
}, this._sendMessageTimeout);
|
|
1021
|
+
|
|
1000
1022
|
this._abortController.signal.addEventListener('abort', abortResponse);
|
|
1023
|
+
|
|
1001
1024
|
this.ws.send(JSON.stringify(requestData));
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
// });
|
|
1025
|
+
}
|
|
1026
|
+
else {
|
|
1027
|
+
cleanup();
|
|
1006
1028
|
reject({type: 'warning', id: 7, message: 'No connection to WebSockets', data: requestData});
|
|
1007
1029
|
}
|
|
1008
1030
|
}
|
|
@@ -1012,11 +1034,52 @@ class RoomSession {
|
|
|
1012
1034
|
if (e.id === 4 ) {
|
|
1013
1035
|
return Promise.reject(e);
|
|
1014
1036
|
}
|
|
1015
|
-
else if(e.id === 7 &&
|
|
1016
|
-
|
|
1037
|
+
else if(e.id === 7 && this.isSupposeToBeConnected) {
|
|
1038
|
+
|
|
1039
|
+
return new Promise((resolve, reject) => {
|
|
1040
|
+
|
|
1041
|
+
let establishConnectionTimeoutId = null;
|
|
1042
|
+
|
|
1043
|
+
const cleanup = () => {
|
|
1044
|
+
clearTimeout(establishConnectionTimeoutId);
|
|
1045
|
+
this._abortController.signal.removeEventListener('abort', abort);
|
|
1046
|
+
this.off('webSocketsConnectionOpened', connection);
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
const connection = () => {
|
|
1050
|
+
cleanup();
|
|
1051
|
+
resolve(this.#sendWebsockets(request, ignoreResponse, dontResolveOnAck, retry - 1));
|
|
1052
|
+
};
|
|
1053
|
+
const timeout = () => {
|
|
1054
|
+
cleanup();
|
|
1055
|
+
reject({type: 'warning', id: 46, message: 'WebSocket connection did not open during wait period', data: requestData});
|
|
1056
|
+
};
|
|
1057
|
+
const abort = () => {
|
|
1058
|
+
cleanup();
|
|
1059
|
+
reject({type: 'warning', id: 47, message: 'WebSocket connection was aborted', data: requestData});
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
if(this.wsOpen) {
|
|
1064
|
+
|
|
1065
|
+
this._log('Retrying failed WebSocket request', requestData);
|
|
1066
|
+
|
|
1067
|
+
resolve(this.#sendWebsockets(request, ignoreResponse, dontResolveOnAck, retry - 1));
|
|
1068
|
+
}
|
|
1069
|
+
else {
|
|
1070
|
+
|
|
1071
|
+
this._log('Waiting for WebSocket connection to open before sending request', requestData);
|
|
1072
|
+
|
|
1073
|
+
this._abortController.signal.addEventListener('abort', abort);
|
|
1074
|
+
establishConnectionTimeoutId = setTimeout(timeout, this._sendMessageWebsocketTimeout);
|
|
1075
|
+
this.once('webSocketsConnectionOpened', connection);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
})
|
|
1079
|
+
|
|
1017
1080
|
}
|
|
1018
|
-
else if(retry > 0) {
|
|
1019
|
-
return this.#
|
|
1081
|
+
else if(retry > 0 && this.isSupposeToBeConnected) {
|
|
1082
|
+
return this.#sendWebsockets(request, ignoreResponse, dontResolveOnAck, retry - 1);
|
|
1020
1083
|
}
|
|
1021
1084
|
else {
|
|
1022
1085
|
return Promise.reject(e);
|
|
@@ -1059,6 +1122,9 @@ class RoomSession {
|
|
|
1059
1122
|
|
|
1060
1123
|
#connectionClosed() {
|
|
1061
1124
|
|
|
1125
|
+
this.wsOpen = false;
|
|
1126
|
+
this.emit('webSocketsConnectionClosed');
|
|
1127
|
+
|
|
1062
1128
|
if (!this.isConnected || this.isConnecting || this.isDisconnecting) {
|
|
1063
1129
|
return;
|
|
1064
1130
|
}
|
|
@@ -1137,7 +1203,12 @@ class RoomSession {
|
|
|
1137
1203
|
if (type === "trickle") {
|
|
1138
1204
|
let candidate = json["candidate"];
|
|
1139
1205
|
let config = handle.webrtcStuff;
|
|
1140
|
-
if (config.pc &&
|
|
1206
|
+
if (config.pc &&
|
|
1207
|
+
config.remoteSdp &&
|
|
1208
|
+
!config.isIceRestarting &&
|
|
1209
|
+
config.pc.iceConnectionState !== 'closed' &&
|
|
1210
|
+
config.pc.iceConnectionState !== 'failed' &&
|
|
1211
|
+
config.pc.iceConnectionState !== 'disconnected') {
|
|
1141
1212
|
|
|
1142
1213
|
if (!candidate || candidate.completed === true) {
|
|
1143
1214
|
config.pc.addIceCandidate(null).catch((e) => {
|
|
@@ -1735,6 +1806,10 @@ class RoomSession {
|
|
|
1735
1806
|
this.ws.addEventListener('message', this.__handleWsEventsBoundFn);
|
|
1736
1807
|
|
|
1737
1808
|
this.ws.onopen = () => {
|
|
1809
|
+
|
|
1810
|
+
this.wsOpen = true;
|
|
1811
|
+
this.emit('webSocketsConnectionOpened');
|
|
1812
|
+
|
|
1738
1813
|
this._abortController.signal.removeEventListener('abort', abortConnect);
|
|
1739
1814
|
if(!reclaim) {
|
|
1740
1815
|
this.#send({"janus": "create"})
|
|
@@ -2204,6 +2279,7 @@ class RoomSession {
|
|
|
2204
2279
|
}
|
|
2205
2280
|
this.emit('iceState', [handleId, handleId === this.#publisherHandle?.handleId, config.pc.iceConnectionState]);
|
|
2206
2281
|
};
|
|
2282
|
+
|
|
2207
2283
|
config.pc.onicecandidate = (event) => {
|
|
2208
2284
|
if (event.candidate == null || (adapter.browserDetails.browser === 'edge' && event.candidate.candidate.indexOf('endOfCandidates') > 0)) {
|
|
2209
2285
|
config.iceDone = true;
|
|
@@ -2456,8 +2532,8 @@ class RoomSession {
|
|
|
2456
2532
|
|
|
2457
2533
|
config.isIceRestarting = true;
|
|
2458
2534
|
|
|
2459
|
-
// removing this so we can cache ice candidates again
|
|
2460
|
-
config.remoteSdp = null;
|
|
2535
|
+
// // removing this so we can cache ice candidates again
|
|
2536
|
+
// config.remoteSdp = null;
|
|
2461
2537
|
|
|
2462
2538
|
if (this.handleId === handleId) {
|
|
2463
2539
|
this._log('Performing local ICE restart');
|
|
@@ -2651,6 +2727,9 @@ class RoomSession {
|
|
|
2651
2727
|
}
|
|
2652
2728
|
|
|
2653
2729
|
#publishRemote(handleId, jsep) {
|
|
2730
|
+
|
|
2731
|
+
console.log('picaaaa');
|
|
2732
|
+
|
|
2654
2733
|
let handle = this.#getHandle(handleId);
|
|
2655
2734
|
if (!handle) {
|
|
2656
2735
|
return Promise.reject({
|
|
@@ -2729,11 +2808,6 @@ class RoomSession {
|
|
|
2729
2808
|
if (!config.stream) {
|
|
2730
2809
|
return;
|
|
2731
2810
|
}
|
|
2732
|
-
|
|
2733
|
-
if(!this.id) {
|
|
2734
|
-
return;
|
|
2735
|
-
}
|
|
2736
|
-
|
|
2737
2811
|
let sourceTrackIds = (config.streamMap[this.id][source] || []);
|
|
2738
2812
|
let remainingTracks = [];
|
|
2739
2813
|
for(let i = 0; i < sourceTrackIds.length; i++) {
|
|
@@ -2804,7 +2878,7 @@ class RoomSession {
|
|
|
2804
2878
|
let existingTracks = [...(config.streamMap?.[this.id]?.[source] || [])];
|
|
2805
2879
|
|
|
2806
2880
|
if(stream?.getTracks().length) {
|
|
2807
|
-
if(!config.streamMap[this.id]) {
|
|
2881
|
+
if(!config.streamMap?.[this.id]) {
|
|
2808
2882
|
config.streamMap[this.id] = {};
|
|
2809
2883
|
}
|
|
2810
2884
|
config.streamMap[this.id][source] = stream?.getTracks()?.map(track => track.id) || [];
|
|
@@ -2824,8 +2898,8 @@ class RoomSession {
|
|
|
2824
2898
|
} catch (e) {
|
|
2825
2899
|
this._log(e);
|
|
2826
2900
|
}
|
|
2827
|
-
config
|
|
2828
|
-
config?.tracks
|
|
2901
|
+
config?.stream?.removeTrack(oldAudioStream);
|
|
2902
|
+
config?.tracks?.splice(oldAudioStreamIndex, 1);
|
|
2829
2903
|
}
|
|
2830
2904
|
|
|
2831
2905
|
// remove old video track related to this source
|