@reactoo/watchtogether-sdk-js 2.7.86-beta.0 → 2.7.86-beta.1

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.7.86-beta.0",
3
+ "version": "2.7.86-beta.1",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "dist/watchtogether-sdk.min.js",
6
6
  "module": "dist/watchtogether-sdk.min.js",
@@ -264,11 +264,11 @@ class RoomSession {
264
264
  this.isVideoEnabled = false;
265
265
  this.isAudioEnabed = false;
266
266
  this._statsMaxLength = 31;
267
- this._upStatsLength = 30;
268
- this._downStatsLength = 5;
267
+ this._upStatsLength = 10;
268
+ this._downStatsLength = 2;
269
269
  this._statsTimeoutStopped = true;
270
270
  this._statsTimeoutId = null;
271
- this._statsInterval = 1000;
271
+ this._statsInterval = 3000;
272
272
  this._aqInterval = 2500;
273
273
  this._aqIntervalCounter = 0;
274
274
  this._aqIntervalDivisor = 4;
@@ -1641,16 +1641,13 @@ class RoomSession {
1641
1641
  }
1642
1642
  this._statsTimeoutStopped = false;
1643
1643
  const loop = () => {
1644
- let startTime = performance.now();
1645
- let endTime = null;
1646
1644
  this._getStats('video')
1647
1645
  .then(participantsStats => {
1648
- endTime = performance.now();
1649
1646
  this._parseVideoStats(participantsStats);
1650
1647
  })
1651
1648
  .finally(() => {
1652
1649
  if (!this._statsTimeoutStopped) {
1653
- this._statsTimeoutId = setTimeout(loop, this._statsInterval - Math.min((endTime - startTime), this._statsInterval));
1650
+ this._statsTimeoutId = setTimeout(loop, this._statsInterval);
1654
1651
  }
1655
1652
  })
1656
1653
  };
@@ -1792,10 +1789,12 @@ class RoomSession {
1792
1789
 
1793
1790
  _parseVideoStats(participantsStats) {
1794
1791
  for (const sourceStats of participantsStats) {
1792
+
1795
1793
  for (const participantStats of sourceStats) {
1796
- if (!participantStats?.handle || participantStats.handle.handleId === this.handleId) continue;
1797
1794
 
1798
- const handle = this._getHandle(participantStats.handle.handleId);
1795
+ if (!participantStats?.handleId || participantStats.handleId === this.handleId) continue;
1796
+
1797
+ const handle = this._getHandle(participantStats.handleId);
1799
1798
  if (!handle) continue;
1800
1799
 
1801
1800
  const mid = participantStats.mid;
@@ -1827,7 +1826,8 @@ class RoomSession {
1827
1826
  const defaultSelectedSubstream = handle.webrtcStuff?.overriddenSimulcastMode[mid]?.defaultSubstream ?? simulcastConfig?.defaultSubstream;
1828
1827
  const simulcastMode = handle.webrtcStuff?.overriddenSimulcastMode[mid]?.mode ?? simulcastConfig?.mode;
1829
1828
 
1830
- for (const report of participantStats.stats) {
1829
+ participantStats.stats.forEach(report => {
1830
+
1831
1831
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
1832
1832
  stats.framesPerSecond = report.framesPerSecond || 0;
1833
1833
  stats.framesDropped = report.framesDropped || 0;
@@ -1850,7 +1850,7 @@ class RoomSession {
1850
1850
  if (report.type === 'local-candidate') {
1851
1851
  stats.networkType = report.networkType;
1852
1852
  }
1853
- }
1853
+ });
1854
1854
 
1855
1855
  stats.selectedSubstream = handle.webrtcStuff.selectedSubstream[mid];
1856
1856
  stats.desiredSubstream = defaultSelectedSubstream;
@@ -1863,9 +1863,9 @@ class RoomSession {
1863
1863
  }
1864
1864
 
1865
1865
  this.emit('rtcStats', {
1866
- handleId: participantStats.handle.handleId,
1866
+ handleId: participantStats.handleId,
1867
1867
  stats,
1868
- userId: decodeJanusDisplay(participantStats.handle.userId)?.userId,
1868
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1869
1869
  source: participantStats.source,
1870
1870
  mid
1871
1871
  });
@@ -1946,33 +1946,82 @@ class RoomSession {
1946
1946
  //
1947
1947
  // }
1948
1948
 
1949
- _getStats(type = null) {
1950
- return Promise.all(this._participants.map(participant => {
1951
- let mediaTrack = [];
1952
- if (type === 'video') {
1953
- mediaTrack = participant?.webrtcStuff?.stream?.getVideoTracks() || [];
1954
- } else if (type === 'audio') {
1955
- mediaTrack = participant?.webrtcStuff?.stream?.getAudioTracks() || [];
1956
- }
1957
- if(type !== null ) {
1958
- const transceivers = participant?.webrtcStuff?.pc?.getTransceivers();
1959
- return Promise.all(mediaTrack.map(track => {
1960
- const source = Object.keys(participant.webrtcStuff.streamMap).find(s => participant.webrtcStuff.streamMap[s].find(t => t === track.id));
1961
- const mid = transceivers.find(t => t.receiver?.track?.id === track.id || t.sender?.track?.id === track.id)?.mid;
1962
- return participant.webrtcStuff.pc.getStats(track)
1963
- .then(r =>({stats: r, source, mid, handle: participant}))
1964
- .catch(e => Promise.reject({stats: null, error: e, handle: participant, source, mid}))
1965
- }))
1966
- }
1967
- else {
1968
- return participant?.webrtcStuff?.pc?.getStats(null)
1969
- .then(r => ({handle: participant, stats: r}))
1970
- .catch(e => Promise.reject({handle: participant, error: e}))
1971
- }
1972
- }))
1973
1949
 
1950
+ _getStats(type = null) {
1951
+ return this._participants.reduce((promise, participant) => {
1952
+ return promise.then(results => {
1953
+ let mediaTrack = [];
1954
+ if (type === 'video') {
1955
+ mediaTrack = participant?.webrtcStuff?.stream?.getVideoTracks() || [];
1956
+ } else if (type === 'audio') {
1957
+ mediaTrack = participant?.webrtcStuff?.stream?.getAudioTracks() || [];
1958
+ }
1974
1959
 
1975
- }
1960
+ if (type !== null) {
1961
+ const transceivers = participant?.webrtcStuff?.pc?.getTransceivers();
1962
+ return Promise.all(mediaTrack.map(track => {
1963
+ const source = Object.keys(participant.webrtcStuff.streamMap).find(s =>
1964
+ participant.webrtcStuff.streamMap[s].find(t => t === track.id)
1965
+ );
1966
+ const mid = transceivers.find(t =>
1967
+ t.receiver?.track?.id === track.id || t.sender?.track?.id === track.id
1968
+ )?.mid;
1969
+
1970
+ return participant.webrtcStuff.pc.getStats(track)
1971
+ .then(r => ({
1972
+ stats: r,
1973
+ source,
1974
+ mid,
1975
+ handleId: participant.handleId
1976
+ }))
1977
+ .catch(e => Promise.reject({
1978
+ stats: null,
1979
+ error: e,
1980
+ handleId: participant.handleId,
1981
+ source,
1982
+ mid
1983
+ }));
1984
+ })).then(participantResults => [...results, participantResults]);
1985
+ } else {
1986
+ return participant?.webrtcStuff?.pc?.getStats(null)
1987
+ .then(r => [...results, {
1988
+ handleId: participant.handleId,
1989
+ stats: r
1990
+ }])
1991
+ .catch(e => [...results, {
1992
+ handleId: participant.handleId,
1993
+ error: e
1994
+ }]);
1995
+ }
1996
+ });
1997
+ }, Promise.resolve([]));
1998
+ }
1999
+
2000
+ // _getStats(type = null) {
2001
+ // return Promise.all(this._participants.map(participant => {
2002
+ // let mediaTrack = [];
2003
+ // if (type === 'video') {
2004
+ // mediaTrack = participant?.webrtcStuff?.stream?.getVideoTracks() || [];
2005
+ // } else if (type === 'audio') {
2006
+ // mediaTrack = participant?.webrtcStuff?.stream?.getAudioTracks() || [];
2007
+ // }
2008
+ // if(type !== null ) {
2009
+ // const transceivers = participant?.webrtcStuff?.pc?.getTransceivers();
2010
+ // return Promise.all(mediaTrack.map(track => {
2011
+ // const source = Object.keys(participant.webrtcStuff.streamMap).find(s => participant.webrtcStuff.streamMap[s].find(t => t === track.id));
2012
+ // const mid = transceivers.find(t => t.receiver?.track?.id === track.id || t.sender?.track?.id === track.id)?.mid;
2013
+ // return participant.webrtcStuff.pc.getStats(track)
2014
+ // .then(r =>({stats: r, source, mid, handleId: participant.handleId}))
2015
+ // .catch(e => Promise.reject({stats: null, error: e,handleId: participant.handleId, source, mid}))
2016
+ // }))
2017
+ // }
2018
+ // else {
2019
+ // return participant?.webrtcStuff?.pc?.getStats(null)
2020
+ // .then(r => ({handleId: participant.handleId, stats: r}))
2021
+ // .catch(e => Promise.reject({ handleId: participant.handleId, error: e}))
2022
+ // }
2023
+ // }))
2024
+ // }
1976
2025
 
1977
2026
  _resetStats(handleId, mid) {
1978
2027
  let handle = this._getHandle(handleId);