@reactoo/watchtogether-sdk-js 2.7.38-beta.4 → 2.7.39
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/dist/watchtogether-sdk.js +71 -48
- package/dist/watchtogether-sdk.js.map +1 -1
- package/dist/watchtogether-sdk.min.js +2 -2
- package/example/index.html +2 -2
- package/package.json +1 -1
- package/src/models/iot.js +0 -10
- package/src/modules/wt-iot.js +6 -1
- package/src/modules/wt-room.js +80 -40
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @reactoo/watchtogether-sdk-js
|
|
3
|
-
* @version 2.7.38
|
|
3
|
+
* @version 2.7.38
|
|
4
4
|
*/
|
|
5
5
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
6
6
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
@@ -16744,11 +16744,9 @@ let iot = function () {
|
|
|
16744
16744
|
}
|
|
16745
16745
|
},
|
|
16746
16746
|
onError: () => {
|
|
16747
|
-
console.log('MQTT client error');
|
|
16748
16747
|
this.__privates.iot.log('MQTT client error');
|
|
16749
16748
|
},
|
|
16750
16749
|
onDisconnect: () => {
|
|
16751
|
-
console.log('MQTT client disconnect');
|
|
16752
16750
|
this.__privates.iot.log('MQTT client disconnect');
|
|
16753
16751
|
},
|
|
16754
16752
|
onInterrupt: () => {
|
|
@@ -16756,19 +16754,15 @@ let iot = function () {
|
|
|
16756
16754
|
this.iot.__updateCredentials();
|
|
16757
16755
|
}
|
|
16758
16756
|
interruptCount++;
|
|
16759
|
-
console.log('MQTT client interrupt');
|
|
16760
16757
|
this.__privates.iot.log('MQTT client interrupt');
|
|
16761
16758
|
},
|
|
16762
16759
|
onResume: () => {
|
|
16763
|
-
console.log('MQTT client resume');
|
|
16764
16760
|
this.__privates.iot.log('MQTT client resume');
|
|
16765
16761
|
},
|
|
16766
16762
|
onConnectionSuccess: () => {
|
|
16767
|
-
console.log('MQTT client connection_success');
|
|
16768
16763
|
this.__privates.iot.log('MQTT client connection_success');
|
|
16769
16764
|
},
|
|
16770
16765
|
onConnectionFailure: () => {
|
|
16771
|
-
console.log('MQTT client connection_failure');
|
|
16772
16766
|
this.__privates.iot.log('MQTT client connection_failure');
|
|
16773
16767
|
},
|
|
16774
16768
|
iotLogin: function () {
|
|
@@ -25546,7 +25540,11 @@ class Iot {
|
|
|
25546
25540
|
type: 'keep_alive',
|
|
25547
25541
|
timestamp: Date.now()
|
|
25548
25542
|
};
|
|
25549
|
-
|
|
25543
|
+
try {
|
|
25544
|
+
this.send(suitableTopic, testMessage);
|
|
25545
|
+
} catch (error) {
|
|
25546
|
+
this.log(`Keep-alive error: ${error.message}`);
|
|
25547
|
+
}
|
|
25550
25548
|
}
|
|
25551
25549
|
}
|
|
25552
25550
|
/* harmony default export */ __webpack_exports__["default"] = (Iot);
|
|
@@ -27169,13 +27167,13 @@ class RoomSession {
|
|
|
27169
27167
|
let directionDecision = 0;
|
|
27170
27168
|
if (((_p$webrtcStuff4 = p.webrtcStuff) === null || _p$webrtcStuff4 === void 0 ? void 0 : (_p$webrtcStuff4$stats = _p$webrtcStuff4.stats) === null || _p$webrtcStuff4$stats === void 0 ? void 0 : (_p$webrtcStuff4$stats2 = _p$webrtcStuff4$stats[mid]) === null || _p$webrtcStuff4$stats2 === void 0 ? void 0 : _p$webrtcStuff4$stats2.length) > this._upStatsLength) {
|
|
27171
27169
|
const upMedianStats = this._calculateMedianStats(p.webrtcStuff.stats[mid].slice(this._upStatsLength * -1));
|
|
27172
|
-
if ((upMedianStats === null || upMedianStats === void 0 ? void 0 : upMedianStats.
|
|
27170
|
+
if ((upMedianStats === null || upMedianStats === void 0 ? void 0 : upMedianStats.freezeDurationSinceLast) < this._upStatsLength * this._statsInterval * 0.33 / 1000 /* && upMedianStats?.freezeCountSinceLast < 3 */) {
|
|
27173
27171
|
directionDecision = 1;
|
|
27174
27172
|
}
|
|
27175
27173
|
}
|
|
27176
27174
|
if (((_p$webrtcStuff5 = p.webrtcStuff) === null || _p$webrtcStuff5 === void 0 ? void 0 : (_p$webrtcStuff5$stats = _p$webrtcStuff5.stats) === null || _p$webrtcStuff5$stats === void 0 ? void 0 : (_p$webrtcStuff5$stats2 = _p$webrtcStuff5$stats[mid]) === null || _p$webrtcStuff5$stats2 === void 0 ? void 0 : _p$webrtcStuff5$stats2.length) > this._downStatsLength) {
|
|
27177
27175
|
const downMedianStats = this._calculateMedianStats(p.webrtcStuff.stats[mid].slice(this._downStatsLength * -1));
|
|
27178
|
-
if ((downMedianStats === null || downMedianStats === void 0 ? void 0 : downMedianStats.
|
|
27176
|
+
if ((downMedianStats === null || downMedianStats === void 0 ? void 0 : downMedianStats.freezeDurationSinceLast) > this._downStatsLength * this._statsInterval * 0.33 / 1000 /* || downMedianStats?.freezeCountSinceLast > 5 || downMedianStats?.jitter > maxJitter(settingsForCurrentSubstream.maxFramerate) */) {
|
|
27179
27177
|
directionDecision = -1;
|
|
27180
27178
|
}
|
|
27181
27179
|
}
|
|
@@ -27587,10 +27585,6 @@ class RoomSession {
|
|
|
27587
27585
|
hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
|
|
27588
27586
|
});
|
|
27589
27587
|
};
|
|
27590
|
-
let mutedTimerId = {};
|
|
27591
|
-
let waitPeriod = 300; // ms
|
|
27592
|
-
let screenShareWaitPeriod = 5000; // ms
|
|
27593
|
-
|
|
27594
27588
|
event.track.onmute = ev => {
|
|
27595
27589
|
var _decodeJanusDisplay23, _decodeJanusDisplay24;
|
|
27596
27590
|
this._log('Remote track muted');
|
|
@@ -27611,34 +27605,6 @@ class RoomSession {
|
|
|
27611
27605
|
track: ev.target,
|
|
27612
27606
|
muted: true
|
|
27613
27607
|
});
|
|
27614
|
-
|
|
27615
|
-
// when a track is muted, we try to switch to lower quality substream, but not for screen sharing
|
|
27616
|
-
|
|
27617
|
-
if (!this.simulcast) {
|
|
27618
|
-
return;
|
|
27619
|
-
}
|
|
27620
|
-
const wPeriod = source.indexOf('screen') > -1 ? screenShareWaitPeriod : waitPeriod;
|
|
27621
|
-
if (!mutedTimerId[mid]) {
|
|
27622
|
-
mutedTimerId[mid] = setTimeout(() => {
|
|
27623
|
-
var _handle$webrtcStuff5, _handle$webrtcStuff5$;
|
|
27624
|
-
mutedTimerId[mid] = null;
|
|
27625
|
-
const simulcastConfigForSource = this._findSimulcastConfig(source, this.simulcastSettings);
|
|
27626
|
-
const simulcastMode = ((_handle$webrtcStuff5 = handle.webrtcStuff) === null || _handle$webrtcStuff5 === void 0 ? void 0 : (_handle$webrtcStuff5$ = _handle$webrtcStuff5.overriddenSimulcastMode[mid]) === null || _handle$webrtcStuff5$ === void 0 ? void 0 : _handle$webrtcStuff5$.mode) || (simulcastConfigForSource === null || simulcastConfigForSource === void 0 ? void 0 : simulcastConfigForSource.mode);
|
|
27627
|
-
const {
|
|
27628
|
-
simulcastBitrates
|
|
27629
|
-
} = handle.webrtcStuff.tracksMap.find(t => t.mid === mid) || {};
|
|
27630
|
-
|
|
27631
|
-
// track is gone
|
|
27632
|
-
if (!simulcastBitrates) {
|
|
27633
|
-
return;
|
|
27634
|
-
}
|
|
27635
|
-
const currentSubstream = handle.webrtcStuff.selectedSubstream[mid];
|
|
27636
|
-
if (!(simulcastMode === 'browserControlled') && ev.target.kind === 'video' && currentSubstream < simulcastBitrates.length - 1) {
|
|
27637
|
-
this._log('Attempting to down the quality due to track muted');
|
|
27638
|
-
this.selectSubStream(handle.handleId, currentSubstream + 1, undefined, mid, false).catch(reason => this._log(`Changing substream for mid: ${mid} failed. Reason: ${reason}`));
|
|
27639
|
-
}
|
|
27640
|
-
}, wPeriod);
|
|
27641
|
-
}
|
|
27642
27608
|
};
|
|
27643
27609
|
event.track.onunmute = ev => {
|
|
27644
27610
|
var _decodeJanusDisplay25, _decodeJanusDisplay26;
|
|
@@ -27646,10 +27612,6 @@ class RoomSession {
|
|
|
27646
27612
|
let transceiver = config.pc.getTransceivers().find(t => t.receiver.track === ev.target);
|
|
27647
27613
|
let mid = transceiver.mid || ev.target.id;
|
|
27648
27614
|
let source = Object.keys(config.streamMap).find(key => config.streamMap[key].includes(ev.target.id));
|
|
27649
|
-
if (mutedTimerId[mid]) {
|
|
27650
|
-
clearTimeout(mutedTimerId[mid]);
|
|
27651
|
-
mutedTimerId[mid] = null;
|
|
27652
|
-
}
|
|
27653
27615
|
this.emit('remoteTrackMuted', {
|
|
27654
27616
|
id: handle.handleId,
|
|
27655
27617
|
mid,
|
|
@@ -27968,6 +27930,61 @@ class RoomSession {
|
|
|
27968
27930
|
});
|
|
27969
27931
|
});
|
|
27970
27932
|
}
|
|
27933
|
+
_addSimulcastToSDP(sdp) {
|
|
27934
|
+
// Split SDP into lines
|
|
27935
|
+
let sdpLines = sdp.split('\n');
|
|
27936
|
+
|
|
27937
|
+
// Find the index of the video m-line
|
|
27938
|
+
let videoIndex = sdpLines.findIndex(line => line.startsWith('m=video'));
|
|
27939
|
+
if (videoIndex === -1) {
|
|
27940
|
+
// No video m-line found
|
|
27941
|
+
return sdp;
|
|
27942
|
+
}
|
|
27943
|
+
|
|
27944
|
+
// We need to insert the lines after the mid attribute
|
|
27945
|
+
// Find the index of the 'a=mid' line in the video section
|
|
27946
|
+
let midIndex = sdpLines.findIndex((line, index) => index > videoIndex && line.startsWith('a=mid:'));
|
|
27947
|
+
if (midIndex === -1) {
|
|
27948
|
+
// No 'a=mid' line found in video m-section
|
|
27949
|
+
return sdp;
|
|
27950
|
+
}
|
|
27951
|
+
|
|
27952
|
+
// Prepare the simulcast attributes
|
|
27953
|
+
const simulcastLines = ['a=rid:l recv', 'a=rid:m recv', 'a=rid:h recv', 'a=simulcast:recv l;m;h'];
|
|
27954
|
+
|
|
27955
|
+
// Prepare the extmap attributes for RID and Repaired RID
|
|
27956
|
+
const extmapId = sdpLines.reduce((maxId, line) => {
|
|
27957
|
+
const match = line.match(/a=extmap:(\d+)/);
|
|
27958
|
+
return match ? Math.max(maxId, parseInt(match[1])) : maxId;
|
|
27959
|
+
}, 0);
|
|
27960
|
+
const extmapLines = [`a=extmap:${extmapId + 1} urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id`, `a=extmap:${extmapId + 2} urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id`];
|
|
27961
|
+
|
|
27962
|
+
// Insert the extmap lines after the last existing extmap in the video section
|
|
27963
|
+
let lastExtmapIndex = midIndex;
|
|
27964
|
+
for (let i = midIndex + 1; i < sdpLines.length; i++) {
|
|
27965
|
+
if (sdpLines[i].startsWith('a=extmap:')) {
|
|
27966
|
+
lastExtmapIndex = i;
|
|
27967
|
+
} else if (sdpLines[i].startsWith('a=')) {
|
|
27968
|
+
// Reached another attribute
|
|
27969
|
+
break;
|
|
27970
|
+
}
|
|
27971
|
+
}
|
|
27972
|
+
|
|
27973
|
+
// Check if the attributes are already present
|
|
27974
|
+
const hasSimulcast = sdpLines.some(line => line.startsWith('a=simulcast'));
|
|
27975
|
+
const hasRidExtmap = sdpLines.some(line => line.includes('urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id'));
|
|
27976
|
+
if (!hasRidExtmap) {
|
|
27977
|
+
// Insert the extmap lines
|
|
27978
|
+
sdpLines.splice(lastExtmapIndex + 1, 0, ...extmapLines);
|
|
27979
|
+
}
|
|
27980
|
+
if (!hasSimulcast) {
|
|
27981
|
+
// Insert the simulcast lines after the 'a=mid' line
|
|
27982
|
+
sdpLines.splice(midIndex + 1, 0, ...simulcastLines);
|
|
27983
|
+
}
|
|
27984
|
+
|
|
27985
|
+
// Return the modified SDP
|
|
27986
|
+
return sdpLines.join('\n');
|
|
27987
|
+
}
|
|
27971
27988
|
_publishRemote(handleId, jsep) {
|
|
27972
27989
|
let handle = this._getHandle(handleId);
|
|
27973
27990
|
if (!handle) {
|
|
@@ -27981,6 +27998,12 @@ class RoomSession {
|
|
|
27981
27998
|
this._webrtc(handleId, true);
|
|
27982
27999
|
let config = handle.webrtcStuff;
|
|
27983
28000
|
if (jsep) {
|
|
28001
|
+
// Just For Debugging
|
|
28002
|
+
// Munge the SDP before setting the remote description
|
|
28003
|
+
// if (jsep && jsep.sdp) {
|
|
28004
|
+
// jsep.sdp = this._addSimulcastToSDP(jsep.sdp);
|
|
28005
|
+
// }
|
|
28006
|
+
|
|
27984
28007
|
return config.pc.setRemoteDescription(jsep).then(() => {
|
|
27985
28008
|
config.remoteSdp = jsep.sdp;
|
|
27986
28009
|
// Any trickle candidate we cached?
|
|
@@ -28824,9 +28847,9 @@ class RoomSession {
|
|
|
28824
28847
|
remoteUsersCache.forEach(r => {
|
|
28825
28848
|
const handle = this._getHandle(null, null, null, r.userId);
|
|
28826
28849
|
if (this._participantShouldSubscribe(r.userId)) {
|
|
28827
|
-
var _handle$
|
|
28850
|
+
var _handle$webrtcStuff5;
|
|
28828
28851
|
// todo: do a nicer flag to indicate inactive handle than just checking for pc
|
|
28829
|
-
if (!handle || !((_handle$
|
|
28852
|
+
if (!handle || !((_handle$webrtcStuff5 = handle.webrtcStuff) !== null && _handle$webrtcStuff5 !== void 0 && _handle$webrtcStuff5.pc)) {
|
|
28830
28853
|
this._log('Subscribing to ', r.userId);
|
|
28831
28854
|
this._createParticipant(r.userId, r.id).then(handle => {
|
|
28832
28855
|
this._updateParticipantsTrackData(handle.handleId, r.streams);
|