@reactoo/watchtogether-sdk-js 2.7.38 → 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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @reactoo/watchtogether-sdk-js
3
- * @version 2.7.38-beta.3
3
+ * @version 2.7.38
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
6
6
  if(typeof exports === 'object' && typeof module === 'object')
@@ -27167,13 +27167,13 @@ class RoomSession {
27167
27167
  let directionDecision = 0;
27168
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) {
27169
27169
  const upMedianStats = this._calculateMedianStats(p.webrtcStuff.stats[mid].slice(this._upStatsLength * -1));
27170
- if ((upMedianStats === null || upMedianStats === void 0 ? void 0 : upMedianStats.framesPerSecond) >= Math.floor(((settingsForCurrentSubstream === null || settingsForCurrentSubstream === void 0 ? void 0 : settingsForCurrentSubstream.maxFramerate) || 30) * 0.7) && (upMedianStats === null || upMedianStats === void 0 ? void 0 : upMedianStats.freezeDurationSinceLast) < this._upStatsLength * this._statsInterval * 0.33 / 1000 /* && upMedianStats?.freezeCountSinceLast < 3 */) {
27170
+ if ((upMedianStats === null || upMedianStats === void 0 ? void 0 : upMedianStats.freezeDurationSinceLast) < this._upStatsLength * this._statsInterval * 0.33 / 1000 /* && upMedianStats?.freezeCountSinceLast < 3 */) {
27171
27171
  directionDecision = 1;
27172
27172
  }
27173
27173
  }
27174
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) {
27175
27175
  const downMedianStats = this._calculateMedianStats(p.webrtcStuff.stats[mid].slice(this._downStatsLength * -1));
27176
- if ((downMedianStats === null || downMedianStats === void 0 ? void 0 : downMedianStats.framesPerSecond) < Math.floor(((settingsForCurrentSubstream === null || settingsForCurrentSubstream === void 0 ? void 0 : settingsForCurrentSubstream.maxFramerate) || 30) * 0.7) || (downMedianStats === null || downMedianStats === void 0 ? void 0 : downMedianStats.freezeDurationSinceLast) > this._downStatsLength * this._statsInterval * 0.33 / 1000 /* || downMedianStats?.freezeCountSinceLast > 5 || downMedianStats?.jitter > maxJitter(settingsForCurrentSubstream.maxFramerate) */) {
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) */) {
27177
27177
  directionDecision = -1;
27178
27178
  }
27179
27179
  }
@@ -27585,10 +27585,6 @@ class RoomSession {
27585
27585
  hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)
27586
27586
  });
27587
27587
  };
27588
- let mutedTimerId = {};
27589
- let waitPeriod = 300; // ms
27590
- let screenShareWaitPeriod = 5000; // ms
27591
-
27592
27588
  event.track.onmute = ev => {
27593
27589
  var _decodeJanusDisplay23, _decodeJanusDisplay24;
27594
27590
  this._log('Remote track muted');
@@ -27609,34 +27605,6 @@ class RoomSession {
27609
27605
  track: ev.target,
27610
27606
  muted: true
27611
27607
  });
27612
-
27613
- // when a track is muted, we try to switch to lower quality substream, but not for screen sharing
27614
-
27615
- if (!this.simulcast) {
27616
- return;
27617
- }
27618
- const wPeriod = source.indexOf('screen') > -1 ? screenShareWaitPeriod : waitPeriod;
27619
- if (!mutedTimerId[mid]) {
27620
- mutedTimerId[mid] = setTimeout(() => {
27621
- var _handle$webrtcStuff5, _handle$webrtcStuff5$;
27622
- mutedTimerId[mid] = null;
27623
- const simulcastConfigForSource = this._findSimulcastConfig(source, this.simulcastSettings);
27624
- 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);
27625
- const {
27626
- simulcastBitrates
27627
- } = handle.webrtcStuff.tracksMap.find(t => t.mid === mid) || {};
27628
-
27629
- // track is gone
27630
- if (!simulcastBitrates) {
27631
- return;
27632
- }
27633
- const currentSubstream = handle.webrtcStuff.selectedSubstream[mid];
27634
- if (!(simulcastMode === 'browserControlled') && ev.target.kind === 'video' && currentSubstream < simulcastBitrates.length - 1) {
27635
- this._log('Attempting to down the quality due to track muted');
27636
- this.selectSubStream(handle.handleId, currentSubstream + 1, undefined, mid, false).catch(reason => this._log(`Changing substream for mid: ${mid} failed. Reason: ${reason}`));
27637
- }
27638
- }, wPeriod);
27639
- }
27640
27608
  };
27641
27609
  event.track.onunmute = ev => {
27642
27610
  var _decodeJanusDisplay25, _decodeJanusDisplay26;
@@ -27644,10 +27612,6 @@ class RoomSession {
27644
27612
  let transceiver = config.pc.getTransceivers().find(t => t.receiver.track === ev.target);
27645
27613
  let mid = transceiver.mid || ev.target.id;
27646
27614
  let source = Object.keys(config.streamMap).find(key => config.streamMap[key].includes(ev.target.id));
27647
- if (mutedTimerId[mid]) {
27648
- clearTimeout(mutedTimerId[mid]);
27649
- mutedTimerId[mid] = null;
27650
- }
27651
27615
  this.emit('remoteTrackMuted', {
27652
27616
  id: handle.handleId,
27653
27617
  mid,
@@ -27966,6 +27930,61 @@ class RoomSession {
27966
27930
  });
27967
27931
  });
27968
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
+ }
27969
27988
  _publishRemote(handleId, jsep) {
27970
27989
  let handle = this._getHandle(handleId);
27971
27990
  if (!handle) {
@@ -27979,6 +27998,12 @@ class RoomSession {
27979
27998
  this._webrtc(handleId, true);
27980
27999
  let config = handle.webrtcStuff;
27981
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
+
27982
28007
  return config.pc.setRemoteDescription(jsep).then(() => {
27983
28008
  config.remoteSdp = jsep.sdp;
27984
28009
  // Any trickle candidate we cached?
@@ -28822,9 +28847,9 @@ class RoomSession {
28822
28847
  remoteUsersCache.forEach(r => {
28823
28848
  const handle = this._getHandle(null, null, null, r.userId);
28824
28849
  if (this._participantShouldSubscribe(r.userId)) {
28825
- var _handle$webrtcStuff6;
28850
+ var _handle$webrtcStuff5;
28826
28851
  // todo: do a nicer flag to indicate inactive handle than just checking for pc
28827
- if (!handle || !((_handle$webrtcStuff6 = handle.webrtcStuff) !== null && _handle$webrtcStuff6 !== void 0 && _handle$webrtcStuff6.pc)) {
28852
+ if (!handle || !((_handle$webrtcStuff5 = handle.webrtcStuff) !== null && _handle$webrtcStuff5 !== void 0 && _handle$webrtcStuff5.pc)) {
28828
28853
  this._log('Subscribing to ', r.userId);
28829
28854
  this._createParticipant(r.userId, r.id).then(handle => {
28830
28855
  this._updateParticipantsTrackData(handle.handleId, r.streams);