@whereby.com/media 1.17.4 → 1.17.6

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/index.cjs CHANGED
@@ -493,6 +493,8 @@ const getPeerConnectionIndex = (pc) => { var _a; return (_a = peerConnectionData
493
493
  const setPeerConnectionsForTests = (pcs) => (peerConnections = pcs);
494
494
 
495
495
  const pcDataByPc = new WeakMap();
496
+ let numMissingTrackSsrcLookups = 0;
497
+ let numFailedTrackSsrcLookups = 0;
496
498
  const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConnections().map((pc) => __awaiter(void 0, void 0, void 0, function* () {
497
499
  let pcData = pcDataByPc.get(pc);
498
500
  if (!pcData) {
@@ -540,6 +542,7 @@ const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConne
540
542
  });
541
543
  });
542
544
  missingSsrcs.forEach((ssrc) => {
545
+ numMissingTrackSsrcLookups++;
543
546
  if (!pcData.ssrcToTrackId[ssrc]) {
544
547
  pcData.ssrcToTrackId[ssrc] = "?" + ssrc;
545
548
  }
@@ -547,7 +550,13 @@ const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConne
547
550
  }
548
551
  return [pc, report, pcData];
549
552
  }
550
- catch (ex) {
553
+ catch (e) {
554
+ rtcStats.sendEvent("trackSsrcLookupFailed", {
555
+ name: e === null || e === void 0 ? void 0 : e.name,
556
+ cause: e === null || e === void 0 ? void 0 : e.cause,
557
+ message: e === null || e === void 0 ? void 0 : e.message,
558
+ });
559
+ numFailedTrackSsrcLookups++;
551
560
  return [pc, [], pcData];
552
561
  }
553
562
  })));
@@ -704,7 +713,7 @@ function collectStats(state, { logger, interval }, immediate) {
704
713
  });
705
714
  });
706
715
  removeNonUpdatedStats(state.statsByView, state.lastUpdateTime);
707
- Object.entries(defaultViewStats.candidatePairs).forEach(([cpKey, cp]) => {
716
+ Object.entries((defaultViewStats === null || defaultViewStats === void 0 ? void 0 : defaultViewStats.candidatePairs) || {}).forEach(([cpKey, cp]) => {
708
717
  const active = cp.lastRtcStatsTime === state.lastUpdateTime;
709
718
  cp.active = active;
710
719
  if (!active) {
@@ -800,6 +809,8 @@ const getStats = () => {
800
809
  const getNumFailedStatsReports = () => {
801
810
  return STATE.numFailedStatsReports;
802
811
  };
812
+ const getNumMissingTrackSsrcLookups = () => numMissingTrackSsrcLookups;
813
+ const getNumFailedTrackSsrcLookups = () => numFailedTrackSsrcLookups;
803
814
  const getUpdatedStats = () => { var _a; return (_a = STATE.currentMonitor) === null || _a === void 0 ? void 0 : _a.getUpdatedStats(); };
804
815
  const setClientProvider = (provider) => (STATE.getClients = provider);
805
816
  function startStatsMonitor(state, { interval, logger }) {
@@ -1773,7 +1784,7 @@ const badNetworkIssueDetector = {
1773
1784
  id: "bad-network",
1774
1785
  enabled: ({ hasLiveTrack, ssrcs }) => hasLiveTrack && ssrcs.length > 0,
1775
1786
  check: ({ client, clients, kind, ssrcs }) => {
1776
- const hasPositiveBitrate = ssrcs.some((ssrc) => ssrc.bitrate > 0);
1787
+ const hasPositiveBitrate = ssrcs.some((ssrc) => ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0) > 0);
1777
1788
  if (!hasPositiveBitrate && client.isLocalClient && kind === "video") {
1778
1789
  const remoteClients = clients.filter((c) => !c.isLocalClient);
1779
1790
  if (remoteClients.length > 0) {
@@ -1785,10 +1796,10 @@ const badNetworkIssueDetector = {
1785
1796
  return false;
1786
1797
  }
1787
1798
  return (ssrc0.bitrate === 0 ||
1788
- ssrc0.lossRatio > 0.03 ||
1799
+ (ssrc0.lossRatio || 0) > 0.03 ||
1789
1800
  (ssrc0.fractionLost || 0) > 0.03 ||
1790
- (!client.isPresentation && kind === "video" && ssrc0.bitrate < 30000) ||
1791
- (ssrc0.direction === "in" && ssrc0.pliRate > 2));
1801
+ (!client.isPresentation && kind === "video" && !!(ssrc0 === null || ssrc0 === void 0 ? void 0 : ssrc0.bitrate) && ssrc0.bitrate < 30000) ||
1802
+ (ssrc0.direction === "in" && !!ssrc0.pliRate && ssrc0.pliRate > 2));
1792
1803
  },
1793
1804
  };
1794
1805
  const dryTrackIssueDetector = {
@@ -1797,7 +1808,7 @@ const dryTrackIssueDetector = {
1797
1808
  check: ({ client, clients, ssrcs }) => {
1798
1809
  let hasPositiveBitrate = false;
1799
1810
  ssrcs.forEach((ssrc) => {
1800
- hasPositiveBitrate = hasPositiveBitrate || ssrc.bitrate > 0;
1811
+ hasPositiveBitrate = hasPositiveBitrate || ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0) > 0;
1801
1812
  });
1802
1813
  if (!hasPositiveBitrate && client.isLocalClient) {
1803
1814
  const remoteClients = clients.filter((c) => !c.isLocalClient);
@@ -1843,17 +1854,19 @@ const issueDetectors = [
1843
1854
  typeof (stats === null || stats === void 0 ? void 0 : stats.tracks) === "object" &&
1844
1855
  Object.keys(stats.tracks).length > 1);
1845
1856
  },
1846
- check: ({ stats: { tracks } }) => {
1857
+ check: ({ stats }) => {
1858
+ if (!stats)
1859
+ return false;
1847
1860
  const jitter = {
1848
1861
  audio: 0,
1849
1862
  video: 0,
1850
1863
  };
1851
- Object.values(tracks)
1864
+ Object.values(stats.tracks)
1852
1865
  .flatMap((t) => Object.values(t.ssrcs))
1853
1866
  .forEach((ssrc) => {
1854
- if (ssrc.kind === "audio" && ssrc.jitter > jitter.audio)
1867
+ if (ssrc.kind === "audio" && !!ssrc.jitter && ssrc.jitter > jitter.audio)
1855
1868
  jitter.audio = ssrc.jitter;
1856
- if (ssrc.kind === "video" && ssrc.jitter > jitter.video)
1869
+ if (ssrc.kind === "video" && !!ssrc.jitter && ssrc.jitter > jitter.video)
1857
1870
  jitter.video = ssrc.jitter;
1858
1871
  });
1859
1872
  const diff = Math.abs(jitter.audio * 1000 - jitter.video * 1000);
@@ -1879,13 +1892,21 @@ const issueDetectors = [
1879
1892
  },
1880
1893
  {
1881
1894
  id: "quality-limitation-bw",
1882
- enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && stats,
1883
- check: ({ stats }) => !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "bandwidth")),
1895
+ enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && !!stats,
1896
+ check: ({ stats }) => {
1897
+ if (!stats)
1898
+ return false;
1899
+ return !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "bandwidth"));
1900
+ },
1884
1901
  },
1885
1902
  {
1886
1903
  id: "quality-limitation-cpu",
1887
- enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && stats,
1888
- check: ({ stats }) => !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "cpu")),
1904
+ enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && !!stats,
1905
+ check: ({ stats }) => {
1906
+ if (!stats)
1907
+ return false;
1908
+ return !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "cpu"));
1909
+ },
1889
1910
  },
1890
1911
  {
1891
1912
  id: "high-plirate",
@@ -1933,13 +1954,13 @@ const issueDetectors = [
1933
1954
  id: "cpu-pressure-serious",
1934
1955
  global: true,
1935
1956
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
1936
- check: ({ stats }) => stats.pressure.state === "serious",
1957
+ check: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) === "serious"; },
1937
1958
  },
1938
1959
  {
1939
1960
  id: "cpu-pressure-critical",
1940
1961
  global: true,
1941
1962
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
1942
- check: ({ stats }) => stats.pressure.state === "critical",
1963
+ check: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) === "critical"; },
1943
1964
  },
1944
1965
  {
1945
1966
  id: "concealed",
@@ -1973,17 +1994,17 @@ const metrics = [
1973
1994
  {
1974
1995
  id: "bitrate",
1975
1996
  enabled: ({ hasLiveTrack, track, ssrc0 }) => hasLiveTrack && !!track && !!ssrc0,
1976
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + ssrc.bitrate, 0),
1997
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0), 0),
1977
1998
  },
1978
1999
  {
1979
2000
  id: "pixelrate",
1980
2001
  enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
1981
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + (ssrc.fps || 0) * (ssrc.width || 0) * (ssrc.height || 0), 0),
2002
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + (ssrc.fps || 0) * (ssrc.width || 0) * (ssrc.height || 0), 0),
1982
2003
  },
1983
2004
  {
1984
2005
  id: "height",
1985
- enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
1986
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((max, ssrc) => Math.max(max, ssrc.fps > 0 ? ssrc.height : 0), 0),
2006
+ enabled: ({ hasLiveTrack, track, trackStats, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!trackStats && !!track && !!ssrc0 && !!ssrc0.height,
2007
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((max, ssrc) => Math.max(max, ssrc.fps > 0 ? ssrc.height : 0), 0),
1987
2008
  },
1988
2009
  {
1989
2010
  id: "sourceHeight",
@@ -2026,19 +2047,19 @@ const metrics = [
2026
2047
  id: "cpu-pressure",
2027
2048
  global: true,
2028
2049
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
2029
- value: ({ stats }) => ({ nominal: 0.25, fair: 0.5, serious: 0.75, critical: 1 })[stats.pressure.state] || 0,
2050
+ value: ({ stats }) => { var _a; return ({ nominal: 0.25, fair: 0.5, serious: 0.75, critical: 1 })[((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) || ""] || 0; },
2030
2051
  },
2031
2052
  {
2032
2053
  id: "turn-usage",
2033
2054
  global: true,
2034
- enabled: ({ stats }) => !!Object.values(stats.candidatePairs).length,
2035
- value: ({ stats }) => Object.values(stats.candidatePairs).some((cp) => cp.usingTurn),
2055
+ enabled: ({ stats }) => !!Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).length,
2056
+ value: ({ stats }) => Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).some((cp) => cp.usingTurn),
2036
2057
  },
2037
2058
  {
2038
2059
  id: "turn-tls-usage",
2039
2060
  global: true,
2040
- enabled: ({ stats }) => !!Object.values(stats.candidatePairs).length,
2041
- value: ({ stats }) => Object.values(stats.candidatePairs).some((cp) => cp.turnProtocol === "tls"),
2061
+ enabled: ({ stats }) => !!Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).length,
2062
+ value: ({ stats }) => Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).some((cp) => cp.turnProtocol === "tls"),
2042
2063
  },
2043
2064
  {
2044
2065
  id: "concealment",
@@ -2073,7 +2094,7 @@ const metrics = [
2073
2094
  {
2074
2095
  id: "qpf",
2075
2096
  enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
2076
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + (ssrc.qpf || 0), 0),
2097
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + (ssrc.qpf || 0), 0),
2077
2098
  },
2078
2099
  ];
2079
2100
  let aggregatedMetrics;
@@ -4925,7 +4946,8 @@ class P2pRtcManager {
4925
4946
  if (!session.publicHostCandidateSeen &&
4926
4947
  !session.relayCandidateSeen &&
4927
4948
  !session.serverReflexiveCandidateSeen) {
4928
- this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED_3SEC);
4949
+ if (pc.iceConnectionState !== "connected" || pc.iceConnectionState !== "completed")
4950
+ this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED_3SEC);
4929
4951
  }
4930
4952
  }, ICE_PUBLIC_IP_GATHERING_TIMEOUT);
4931
4953
  break;
@@ -4995,7 +5017,9 @@ class P2pRtcManager {
4995
5017
  });
4996
5018
  if (!session.publicHostCandidateSeen &&
4997
5019
  !session.relayCandidateSeen &&
4998
- !session.serverReflexiveCandidateSeen) {
5020
+ !session.serverReflexiveCandidateSeen &&
5021
+ pc.iceConnectionState !== "connected" &&
5022
+ pc.iceConnectionState !== "completed") {
4999
5023
  this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED);
5000
5024
  }
5001
5025
  if (session.ipv6HostCandidateSeen) {
@@ -7006,6 +7030,8 @@ exports.getIssuesAndMetrics = getIssuesAndMetrics;
7006
7030
  exports.getMediaConstraints = getMediaConstraints;
7007
7031
  exports.getMediaSettings = getMediaSettings;
7008
7032
  exports.getNumFailedStatsReports = getNumFailedStatsReports;
7033
+ exports.getNumFailedTrackSsrcLookups = getNumFailedTrackSsrcLookups;
7034
+ exports.getNumMissingTrackSsrcLookups = getNumMissingTrackSsrcLookups;
7009
7035
  exports.getOptimalBitrate = getOptimalBitrate;
7010
7036
  exports.getPeerConnectionIndex = getPeerConnectionIndex;
7011
7037
  exports.getStats = getStats;
package/dist/index.d.cts CHANGED
@@ -101,20 +101,32 @@ declare class Logger {
101
101
  debug(...params: any[]): void;
102
102
  }
103
103
 
104
+ interface PressureObserver {
105
+ observe: (source: string, options: {
106
+ sampleInterval: number;
107
+ }) => Promise<undefined>;
108
+ unobserve: (source: string) => undefined;
109
+ }
110
+ type PressureRecord = {
111
+ source: string;
112
+ state: string;
113
+ time: number;
114
+ };
115
+
104
116
  interface StatsMonitor {
105
117
  getUpdatedStats: () => Promise<Record<string, ViewStats> | undefined>;
106
118
  stop: () => void;
107
119
  }
108
120
  interface StatsSubscription {
109
- onUpdatedStats: (statsByView: any, clients: any) => void;
121
+ onUpdatedStats: (statsByView: Record<string, ViewStats>, clients: any) => void;
110
122
  }
111
123
  interface StatsMonitorState {
112
124
  currentMonitor: StatsMonitor | null;
113
125
  getClients: () => any[];
114
- lastPressureObserverRecord?: any;
126
+ lastPressureObserverRecord?: PressureRecord;
115
127
  lastUpdateTime: number;
116
128
  nextTimeout?: number;
117
- pressureObserver?: any;
129
+ pressureObserver?: PressureObserver;
118
130
  statsByView: Record<string, ViewStats>;
119
131
  subscriptions: StatsSubscription[];
120
132
  numFailedStatsReports: number;
@@ -131,7 +143,7 @@ interface TrackStats {
131
143
  interface ViewStats {
132
144
  startTime?: number;
133
145
  updated?: number;
134
- pressure?: number | null;
146
+ pressure?: PressureRecord | null;
135
147
  candidatePairs?: any;
136
148
  tracks: Record<string, TrackStats>;
137
149
  }
@@ -184,6 +196,8 @@ declare const getStats: () => {
184
196
  [x: string]: ViewStats;
185
197
  };
186
198
  declare const getNumFailedStatsReports: () => number;
199
+ declare const getNumMissingTrackSsrcLookups: () => number;
200
+ declare const getNumFailedTrackSsrcLookups: () => number;
187
201
  declare const getUpdatedStats: () => Promise<Record<string, ViewStats> | undefined> | undefined;
188
202
  declare const setClientProvider: (provider: any) => any;
189
203
  declare function subscribeStats(subscription: StatsSubscription, options?: StatsMonitorOptions, state?: StatsMonitorState): {
@@ -1568,4 +1582,4 @@ declare class RtcStream {
1568
1582
  static getTypeFromId(id: string): string;
1569
1583
  }
1570
1584
 
1571
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutGroupJoinedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
1585
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutGroupJoinedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
package/dist/index.d.mts CHANGED
@@ -101,20 +101,32 @@ declare class Logger {
101
101
  debug(...params: any[]): void;
102
102
  }
103
103
 
104
+ interface PressureObserver {
105
+ observe: (source: string, options: {
106
+ sampleInterval: number;
107
+ }) => Promise<undefined>;
108
+ unobserve: (source: string) => undefined;
109
+ }
110
+ type PressureRecord = {
111
+ source: string;
112
+ state: string;
113
+ time: number;
114
+ };
115
+
104
116
  interface StatsMonitor {
105
117
  getUpdatedStats: () => Promise<Record<string, ViewStats> | undefined>;
106
118
  stop: () => void;
107
119
  }
108
120
  interface StatsSubscription {
109
- onUpdatedStats: (statsByView: any, clients: any) => void;
121
+ onUpdatedStats: (statsByView: Record<string, ViewStats>, clients: any) => void;
110
122
  }
111
123
  interface StatsMonitorState {
112
124
  currentMonitor: StatsMonitor | null;
113
125
  getClients: () => any[];
114
- lastPressureObserverRecord?: any;
126
+ lastPressureObserverRecord?: PressureRecord;
115
127
  lastUpdateTime: number;
116
128
  nextTimeout?: number;
117
- pressureObserver?: any;
129
+ pressureObserver?: PressureObserver;
118
130
  statsByView: Record<string, ViewStats>;
119
131
  subscriptions: StatsSubscription[];
120
132
  numFailedStatsReports: number;
@@ -131,7 +143,7 @@ interface TrackStats {
131
143
  interface ViewStats {
132
144
  startTime?: number;
133
145
  updated?: number;
134
- pressure?: number | null;
146
+ pressure?: PressureRecord | null;
135
147
  candidatePairs?: any;
136
148
  tracks: Record<string, TrackStats>;
137
149
  }
@@ -184,6 +196,8 @@ declare const getStats: () => {
184
196
  [x: string]: ViewStats;
185
197
  };
186
198
  declare const getNumFailedStatsReports: () => number;
199
+ declare const getNumMissingTrackSsrcLookups: () => number;
200
+ declare const getNumFailedTrackSsrcLookups: () => number;
187
201
  declare const getUpdatedStats: () => Promise<Record<string, ViewStats> | undefined> | undefined;
188
202
  declare const setClientProvider: (provider: any) => any;
189
203
  declare function subscribeStats(subscription: StatsSubscription, options?: StatsMonitorOptions, state?: StatsMonitorState): {
@@ -1568,4 +1582,4 @@ declare class RtcStream {
1568
1582
  static getTypeFromId(id: string): string;
1569
1583
  }
1570
1584
 
1571
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutGroupJoinedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
1585
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutGroupJoinedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
package/dist/index.d.ts CHANGED
@@ -101,20 +101,32 @@ declare class Logger {
101
101
  debug(...params: any[]): void;
102
102
  }
103
103
 
104
+ interface PressureObserver {
105
+ observe: (source: string, options: {
106
+ sampleInterval: number;
107
+ }) => Promise<undefined>;
108
+ unobserve: (source: string) => undefined;
109
+ }
110
+ type PressureRecord = {
111
+ source: string;
112
+ state: string;
113
+ time: number;
114
+ };
115
+
104
116
  interface StatsMonitor {
105
117
  getUpdatedStats: () => Promise<Record<string, ViewStats> | undefined>;
106
118
  stop: () => void;
107
119
  }
108
120
  interface StatsSubscription {
109
- onUpdatedStats: (statsByView: any, clients: any) => void;
121
+ onUpdatedStats: (statsByView: Record<string, ViewStats>, clients: any) => void;
110
122
  }
111
123
  interface StatsMonitorState {
112
124
  currentMonitor: StatsMonitor | null;
113
125
  getClients: () => any[];
114
- lastPressureObserverRecord?: any;
126
+ lastPressureObserverRecord?: PressureRecord;
115
127
  lastUpdateTime: number;
116
128
  nextTimeout?: number;
117
- pressureObserver?: any;
129
+ pressureObserver?: PressureObserver;
118
130
  statsByView: Record<string, ViewStats>;
119
131
  subscriptions: StatsSubscription[];
120
132
  numFailedStatsReports: number;
@@ -131,7 +143,7 @@ interface TrackStats {
131
143
  interface ViewStats {
132
144
  startTime?: number;
133
145
  updated?: number;
134
- pressure?: number | null;
146
+ pressure?: PressureRecord | null;
135
147
  candidatePairs?: any;
136
148
  tracks: Record<string, TrackStats>;
137
149
  }
@@ -184,6 +196,8 @@ declare const getStats: () => {
184
196
  [x: string]: ViewStats;
185
197
  };
186
198
  declare const getNumFailedStatsReports: () => number;
199
+ declare const getNumMissingTrackSsrcLookups: () => number;
200
+ declare const getNumFailedTrackSsrcLookups: () => number;
187
201
  declare const getUpdatedStats: () => Promise<Record<string, ViewStats> | undefined> | undefined;
188
202
  declare const setClientProvider: (provider: any) => any;
189
203
  declare function subscribeStats(subscription: StatsSubscription, options?: StatsMonitorOptions, state?: StatsMonitorState): {
@@ -1568,4 +1582,4 @@ declare class RtcStream {
1568
1582
  static getTypeFromId(id: string): string;
1569
1583
  }
1570
1584
 
1571
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutGroupJoinedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
1585
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutGroupJoinedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
package/dist/index.mjs CHANGED
@@ -472,6 +472,8 @@ const getPeerConnectionIndex = (pc) => { var _a; return (_a = peerConnectionData
472
472
  const setPeerConnectionsForTests = (pcs) => (peerConnections = pcs);
473
473
 
474
474
  const pcDataByPc = new WeakMap();
475
+ let numMissingTrackSsrcLookups = 0;
476
+ let numFailedTrackSsrcLookups = 0;
475
477
  const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConnections().map((pc) => __awaiter(void 0, void 0, void 0, function* () {
476
478
  let pcData = pcDataByPc.get(pc);
477
479
  if (!pcData) {
@@ -519,6 +521,7 @@ const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConne
519
521
  });
520
522
  });
521
523
  missingSsrcs.forEach((ssrc) => {
524
+ numMissingTrackSsrcLookups++;
522
525
  if (!pcData.ssrcToTrackId[ssrc]) {
523
526
  pcData.ssrcToTrackId[ssrc] = "?" + ssrc;
524
527
  }
@@ -526,7 +529,13 @@ const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConne
526
529
  }
527
530
  return [pc, report, pcData];
528
531
  }
529
- catch (ex) {
532
+ catch (e) {
533
+ rtcStats.sendEvent("trackSsrcLookupFailed", {
534
+ name: e === null || e === void 0 ? void 0 : e.name,
535
+ cause: e === null || e === void 0 ? void 0 : e.cause,
536
+ message: e === null || e === void 0 ? void 0 : e.message,
537
+ });
538
+ numFailedTrackSsrcLookups++;
530
539
  return [pc, [], pcData];
531
540
  }
532
541
  })));
@@ -683,7 +692,7 @@ function collectStats(state, { logger, interval }, immediate) {
683
692
  });
684
693
  });
685
694
  removeNonUpdatedStats(state.statsByView, state.lastUpdateTime);
686
- Object.entries(defaultViewStats.candidatePairs).forEach(([cpKey, cp]) => {
695
+ Object.entries((defaultViewStats === null || defaultViewStats === void 0 ? void 0 : defaultViewStats.candidatePairs) || {}).forEach(([cpKey, cp]) => {
687
696
  const active = cp.lastRtcStatsTime === state.lastUpdateTime;
688
697
  cp.active = active;
689
698
  if (!active) {
@@ -779,6 +788,8 @@ const getStats = () => {
779
788
  const getNumFailedStatsReports = () => {
780
789
  return STATE.numFailedStatsReports;
781
790
  };
791
+ const getNumMissingTrackSsrcLookups = () => numMissingTrackSsrcLookups;
792
+ const getNumFailedTrackSsrcLookups = () => numFailedTrackSsrcLookups;
782
793
  const getUpdatedStats = () => { var _a; return (_a = STATE.currentMonitor) === null || _a === void 0 ? void 0 : _a.getUpdatedStats(); };
783
794
  const setClientProvider = (provider) => (STATE.getClients = provider);
784
795
  function startStatsMonitor(state, { interval, logger }) {
@@ -1752,7 +1763,7 @@ const badNetworkIssueDetector = {
1752
1763
  id: "bad-network",
1753
1764
  enabled: ({ hasLiveTrack, ssrcs }) => hasLiveTrack && ssrcs.length > 0,
1754
1765
  check: ({ client, clients, kind, ssrcs }) => {
1755
- const hasPositiveBitrate = ssrcs.some((ssrc) => ssrc.bitrate > 0);
1766
+ const hasPositiveBitrate = ssrcs.some((ssrc) => ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0) > 0);
1756
1767
  if (!hasPositiveBitrate && client.isLocalClient && kind === "video") {
1757
1768
  const remoteClients = clients.filter((c) => !c.isLocalClient);
1758
1769
  if (remoteClients.length > 0) {
@@ -1764,10 +1775,10 @@ const badNetworkIssueDetector = {
1764
1775
  return false;
1765
1776
  }
1766
1777
  return (ssrc0.bitrate === 0 ||
1767
- ssrc0.lossRatio > 0.03 ||
1778
+ (ssrc0.lossRatio || 0) > 0.03 ||
1768
1779
  (ssrc0.fractionLost || 0) > 0.03 ||
1769
- (!client.isPresentation && kind === "video" && ssrc0.bitrate < 30000) ||
1770
- (ssrc0.direction === "in" && ssrc0.pliRate > 2));
1780
+ (!client.isPresentation && kind === "video" && !!(ssrc0 === null || ssrc0 === void 0 ? void 0 : ssrc0.bitrate) && ssrc0.bitrate < 30000) ||
1781
+ (ssrc0.direction === "in" && !!ssrc0.pliRate && ssrc0.pliRate > 2));
1771
1782
  },
1772
1783
  };
1773
1784
  const dryTrackIssueDetector = {
@@ -1776,7 +1787,7 @@ const dryTrackIssueDetector = {
1776
1787
  check: ({ client, clients, ssrcs }) => {
1777
1788
  let hasPositiveBitrate = false;
1778
1789
  ssrcs.forEach((ssrc) => {
1779
- hasPositiveBitrate = hasPositiveBitrate || ssrc.bitrate > 0;
1790
+ hasPositiveBitrate = hasPositiveBitrate || ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0) > 0;
1780
1791
  });
1781
1792
  if (!hasPositiveBitrate && client.isLocalClient) {
1782
1793
  const remoteClients = clients.filter((c) => !c.isLocalClient);
@@ -1822,17 +1833,19 @@ const issueDetectors = [
1822
1833
  typeof (stats === null || stats === void 0 ? void 0 : stats.tracks) === "object" &&
1823
1834
  Object.keys(stats.tracks).length > 1);
1824
1835
  },
1825
- check: ({ stats: { tracks } }) => {
1836
+ check: ({ stats }) => {
1837
+ if (!stats)
1838
+ return false;
1826
1839
  const jitter = {
1827
1840
  audio: 0,
1828
1841
  video: 0,
1829
1842
  };
1830
- Object.values(tracks)
1843
+ Object.values(stats.tracks)
1831
1844
  .flatMap((t) => Object.values(t.ssrcs))
1832
1845
  .forEach((ssrc) => {
1833
- if (ssrc.kind === "audio" && ssrc.jitter > jitter.audio)
1846
+ if (ssrc.kind === "audio" && !!ssrc.jitter && ssrc.jitter > jitter.audio)
1834
1847
  jitter.audio = ssrc.jitter;
1835
- if (ssrc.kind === "video" && ssrc.jitter > jitter.video)
1848
+ if (ssrc.kind === "video" && !!ssrc.jitter && ssrc.jitter > jitter.video)
1836
1849
  jitter.video = ssrc.jitter;
1837
1850
  });
1838
1851
  const diff = Math.abs(jitter.audio * 1000 - jitter.video * 1000);
@@ -1858,13 +1871,21 @@ const issueDetectors = [
1858
1871
  },
1859
1872
  {
1860
1873
  id: "quality-limitation-bw",
1861
- enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && stats,
1862
- check: ({ stats }) => !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "bandwidth")),
1874
+ enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && !!stats,
1875
+ check: ({ stats }) => {
1876
+ if (!stats)
1877
+ return false;
1878
+ return !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "bandwidth"));
1879
+ },
1863
1880
  },
1864
1881
  {
1865
1882
  id: "quality-limitation-cpu",
1866
- enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && stats,
1867
- check: ({ stats }) => !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "cpu")),
1883
+ enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && !!stats,
1884
+ check: ({ stats }) => {
1885
+ if (!stats)
1886
+ return false;
1887
+ return !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "cpu"));
1888
+ },
1868
1889
  },
1869
1890
  {
1870
1891
  id: "high-plirate",
@@ -1912,13 +1933,13 @@ const issueDetectors = [
1912
1933
  id: "cpu-pressure-serious",
1913
1934
  global: true,
1914
1935
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
1915
- check: ({ stats }) => stats.pressure.state === "serious",
1936
+ check: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) === "serious"; },
1916
1937
  },
1917
1938
  {
1918
1939
  id: "cpu-pressure-critical",
1919
1940
  global: true,
1920
1941
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
1921
- check: ({ stats }) => stats.pressure.state === "critical",
1942
+ check: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) === "critical"; },
1922
1943
  },
1923
1944
  {
1924
1945
  id: "concealed",
@@ -1952,17 +1973,17 @@ const metrics = [
1952
1973
  {
1953
1974
  id: "bitrate",
1954
1975
  enabled: ({ hasLiveTrack, track, ssrc0 }) => hasLiveTrack && !!track && !!ssrc0,
1955
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + ssrc.bitrate, 0),
1976
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0), 0),
1956
1977
  },
1957
1978
  {
1958
1979
  id: "pixelrate",
1959
1980
  enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
1960
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + (ssrc.fps || 0) * (ssrc.width || 0) * (ssrc.height || 0), 0),
1981
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + (ssrc.fps || 0) * (ssrc.width || 0) * (ssrc.height || 0), 0),
1961
1982
  },
1962
1983
  {
1963
1984
  id: "height",
1964
- enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
1965
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((max, ssrc) => Math.max(max, ssrc.fps > 0 ? ssrc.height : 0), 0),
1985
+ enabled: ({ hasLiveTrack, track, trackStats, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!trackStats && !!track && !!ssrc0 && !!ssrc0.height,
1986
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((max, ssrc) => Math.max(max, ssrc.fps > 0 ? ssrc.height : 0), 0),
1966
1987
  },
1967
1988
  {
1968
1989
  id: "sourceHeight",
@@ -2005,19 +2026,19 @@ const metrics = [
2005
2026
  id: "cpu-pressure",
2006
2027
  global: true,
2007
2028
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
2008
- value: ({ stats }) => ({ nominal: 0.25, fair: 0.5, serious: 0.75, critical: 1 })[stats.pressure.state] || 0,
2029
+ value: ({ stats }) => { var _a; return ({ nominal: 0.25, fair: 0.5, serious: 0.75, critical: 1 })[((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) || ""] || 0; },
2009
2030
  },
2010
2031
  {
2011
2032
  id: "turn-usage",
2012
2033
  global: true,
2013
- enabled: ({ stats }) => !!Object.values(stats.candidatePairs).length,
2014
- value: ({ stats }) => Object.values(stats.candidatePairs).some((cp) => cp.usingTurn),
2034
+ enabled: ({ stats }) => !!Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).length,
2035
+ value: ({ stats }) => Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).some((cp) => cp.usingTurn),
2015
2036
  },
2016
2037
  {
2017
2038
  id: "turn-tls-usage",
2018
2039
  global: true,
2019
- enabled: ({ stats }) => !!Object.values(stats.candidatePairs).length,
2020
- value: ({ stats }) => Object.values(stats.candidatePairs).some((cp) => cp.turnProtocol === "tls"),
2040
+ enabled: ({ stats }) => !!Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).length,
2041
+ value: ({ stats }) => Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).some((cp) => cp.turnProtocol === "tls"),
2021
2042
  },
2022
2043
  {
2023
2044
  id: "concealment",
@@ -2052,7 +2073,7 @@ const metrics = [
2052
2073
  {
2053
2074
  id: "qpf",
2054
2075
  enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
2055
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + (ssrc.qpf || 0), 0),
2076
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + (ssrc.qpf || 0), 0),
2056
2077
  },
2057
2078
  ];
2058
2079
  let aggregatedMetrics;
@@ -4904,7 +4925,8 @@ class P2pRtcManager {
4904
4925
  if (!session.publicHostCandidateSeen &&
4905
4926
  !session.relayCandidateSeen &&
4906
4927
  !session.serverReflexiveCandidateSeen) {
4907
- this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED_3SEC);
4928
+ if (pc.iceConnectionState !== "connected" || pc.iceConnectionState !== "completed")
4929
+ this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED_3SEC);
4908
4930
  }
4909
4931
  }, ICE_PUBLIC_IP_GATHERING_TIMEOUT);
4910
4932
  break;
@@ -4974,7 +4996,9 @@ class P2pRtcManager {
4974
4996
  });
4975
4997
  if (!session.publicHostCandidateSeen &&
4976
4998
  !session.relayCandidateSeen &&
4977
- !session.serverReflexiveCandidateSeen) {
4999
+ !session.serverReflexiveCandidateSeen &&
5000
+ pc.iceConnectionState !== "connected" &&
5001
+ pc.iceConnectionState !== "completed") {
4978
5002
  this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED);
4979
5003
  }
4980
5004
  if (session.ipv6HostCandidateSeen) {
@@ -6927,4 +6951,4 @@ var RtcEventNames;
6927
6951
  RtcEventNames["stream_added"] = "stream_added";
6928
6952
  })(RtcEventNames || (RtcEventNames = {}));
6929
6953
 
6930
- export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
6954
+ export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
@@ -472,6 +472,8 @@ const getPeerConnectionIndex = (pc) => { var _a; return (_a = peerConnectionData
472
472
  const setPeerConnectionsForTests = (pcs) => (peerConnections = pcs);
473
473
 
474
474
  const pcDataByPc = new WeakMap();
475
+ let numMissingTrackSsrcLookups = 0;
476
+ let numFailedTrackSsrcLookups = 0;
475
477
  const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConnections().map((pc) => __awaiter(void 0, void 0, void 0, function* () {
476
478
  let pcData = pcDataByPc.get(pc);
477
479
  if (!pcData) {
@@ -519,6 +521,7 @@ const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConne
519
521
  });
520
522
  });
521
523
  missingSsrcs.forEach((ssrc) => {
524
+ numMissingTrackSsrcLookups++;
522
525
  if (!pcData.ssrcToTrackId[ssrc]) {
523
526
  pcData.ssrcToTrackId[ssrc] = "?" + ssrc;
524
527
  }
@@ -526,7 +529,13 @@ const getPeerConnectionsWithStatsReports = () => Promise.all(getCurrentPeerConne
526
529
  }
527
530
  return [pc, report, pcData];
528
531
  }
529
- catch (ex) {
532
+ catch (e) {
533
+ rtcStats.sendEvent("trackSsrcLookupFailed", {
534
+ name: e === null || e === void 0 ? void 0 : e.name,
535
+ cause: e === null || e === void 0 ? void 0 : e.cause,
536
+ message: e === null || e === void 0 ? void 0 : e.message,
537
+ });
538
+ numFailedTrackSsrcLookups++;
530
539
  return [pc, [], pcData];
531
540
  }
532
541
  })));
@@ -683,7 +692,7 @@ function collectStats(state, { logger, interval }, immediate) {
683
692
  });
684
693
  });
685
694
  removeNonUpdatedStats(state.statsByView, state.lastUpdateTime);
686
- Object.entries(defaultViewStats.candidatePairs).forEach(([cpKey, cp]) => {
695
+ Object.entries((defaultViewStats === null || defaultViewStats === void 0 ? void 0 : defaultViewStats.candidatePairs) || {}).forEach(([cpKey, cp]) => {
687
696
  const active = cp.lastRtcStatsTime === state.lastUpdateTime;
688
697
  cp.active = active;
689
698
  if (!active) {
@@ -779,6 +788,8 @@ const getStats = () => {
779
788
  const getNumFailedStatsReports = () => {
780
789
  return STATE.numFailedStatsReports;
781
790
  };
791
+ const getNumMissingTrackSsrcLookups = () => numMissingTrackSsrcLookups;
792
+ const getNumFailedTrackSsrcLookups = () => numFailedTrackSsrcLookups;
782
793
  const getUpdatedStats = () => { var _a; return (_a = STATE.currentMonitor) === null || _a === void 0 ? void 0 : _a.getUpdatedStats(); };
783
794
  const setClientProvider = (provider) => (STATE.getClients = provider);
784
795
  function startStatsMonitor(state, { interval, logger }) {
@@ -1752,7 +1763,7 @@ const badNetworkIssueDetector = {
1752
1763
  id: "bad-network",
1753
1764
  enabled: ({ hasLiveTrack, ssrcs }) => hasLiveTrack && ssrcs.length > 0,
1754
1765
  check: ({ client, clients, kind, ssrcs }) => {
1755
- const hasPositiveBitrate = ssrcs.some((ssrc) => ssrc.bitrate > 0);
1766
+ const hasPositiveBitrate = ssrcs.some((ssrc) => ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0) > 0);
1756
1767
  if (!hasPositiveBitrate && client.isLocalClient && kind === "video") {
1757
1768
  const remoteClients = clients.filter((c) => !c.isLocalClient);
1758
1769
  if (remoteClients.length > 0) {
@@ -1764,10 +1775,10 @@ const badNetworkIssueDetector = {
1764
1775
  return false;
1765
1776
  }
1766
1777
  return (ssrc0.bitrate === 0 ||
1767
- ssrc0.lossRatio > 0.03 ||
1778
+ (ssrc0.lossRatio || 0) > 0.03 ||
1768
1779
  (ssrc0.fractionLost || 0) > 0.03 ||
1769
- (!client.isPresentation && kind === "video" && ssrc0.bitrate < 30000) ||
1770
- (ssrc0.direction === "in" && ssrc0.pliRate > 2));
1780
+ (!client.isPresentation && kind === "video" && !!(ssrc0 === null || ssrc0 === void 0 ? void 0 : ssrc0.bitrate) && ssrc0.bitrate < 30000) ||
1781
+ (ssrc0.direction === "in" && !!ssrc0.pliRate && ssrc0.pliRate > 2));
1771
1782
  },
1772
1783
  };
1773
1784
  const dryTrackIssueDetector = {
@@ -1776,7 +1787,7 @@ const dryTrackIssueDetector = {
1776
1787
  check: ({ client, clients, ssrcs }) => {
1777
1788
  let hasPositiveBitrate = false;
1778
1789
  ssrcs.forEach((ssrc) => {
1779
- hasPositiveBitrate = hasPositiveBitrate || ssrc.bitrate > 0;
1790
+ hasPositiveBitrate = hasPositiveBitrate || ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0) > 0;
1780
1791
  });
1781
1792
  if (!hasPositiveBitrate && client.isLocalClient) {
1782
1793
  const remoteClients = clients.filter((c) => !c.isLocalClient);
@@ -1822,17 +1833,19 @@ const issueDetectors = [
1822
1833
  typeof (stats === null || stats === void 0 ? void 0 : stats.tracks) === "object" &&
1823
1834
  Object.keys(stats.tracks).length > 1);
1824
1835
  },
1825
- check: ({ stats: { tracks } }) => {
1836
+ check: ({ stats }) => {
1837
+ if (!stats)
1838
+ return false;
1826
1839
  const jitter = {
1827
1840
  audio: 0,
1828
1841
  video: 0,
1829
1842
  };
1830
- Object.values(tracks)
1843
+ Object.values(stats.tracks)
1831
1844
  .flatMap((t) => Object.values(t.ssrcs))
1832
1845
  .forEach((ssrc) => {
1833
- if (ssrc.kind === "audio" && ssrc.jitter > jitter.audio)
1846
+ if (ssrc.kind === "audio" && !!ssrc.jitter && ssrc.jitter > jitter.audio)
1834
1847
  jitter.audio = ssrc.jitter;
1835
- if (ssrc.kind === "video" && ssrc.jitter > jitter.video)
1848
+ if (ssrc.kind === "video" && !!ssrc.jitter && ssrc.jitter > jitter.video)
1836
1849
  jitter.video = ssrc.jitter;
1837
1850
  });
1838
1851
  const diff = Math.abs(jitter.audio * 1000 - jitter.video * 1000);
@@ -1858,13 +1871,21 @@ const issueDetectors = [
1858
1871
  },
1859
1872
  {
1860
1873
  id: "quality-limitation-bw",
1861
- enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && stats,
1862
- check: ({ stats }) => !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "bandwidth")),
1874
+ enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && !!stats,
1875
+ check: ({ stats }) => {
1876
+ if (!stats)
1877
+ return false;
1878
+ return !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "bandwidth"));
1879
+ },
1863
1880
  },
1864
1881
  {
1865
1882
  id: "quality-limitation-cpu",
1866
- enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && stats,
1867
- check: ({ stats }) => !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "cpu")),
1883
+ enabled: ({ hasLiveTrack, stats, client, kind }) => hasLiveTrack && client.isLocalClient && kind === "video" && !!stats,
1884
+ check: ({ stats }) => {
1885
+ if (!stats)
1886
+ return false;
1887
+ return !!Object.values(stats.tracks).find((track) => Object.values(track.ssrcs).find((ssrc) => ssrc.qualityLimitationReason === "cpu"));
1888
+ },
1868
1889
  },
1869
1890
  {
1870
1891
  id: "high-plirate",
@@ -1912,13 +1933,13 @@ const issueDetectors = [
1912
1933
  id: "cpu-pressure-serious",
1913
1934
  global: true,
1914
1935
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
1915
- check: ({ stats }) => stats.pressure.state === "serious",
1936
+ check: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) === "serious"; },
1916
1937
  },
1917
1938
  {
1918
1939
  id: "cpu-pressure-critical",
1919
1940
  global: true,
1920
1941
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
1921
- check: ({ stats }) => stats.pressure.state === "critical",
1942
+ check: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) === "critical"; },
1922
1943
  },
1923
1944
  {
1924
1945
  id: "concealed",
@@ -1952,17 +1973,17 @@ const metrics = [
1952
1973
  {
1953
1974
  id: "bitrate",
1954
1975
  enabled: ({ hasLiveTrack, track, ssrc0 }) => hasLiveTrack && !!track && !!ssrc0,
1955
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + ssrc.bitrate, 0),
1976
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + ((ssrc === null || ssrc === void 0 ? void 0 : ssrc.bitrate) || 0), 0),
1956
1977
  },
1957
1978
  {
1958
1979
  id: "pixelrate",
1959
1980
  enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
1960
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + (ssrc.fps || 0) * (ssrc.width || 0) * (ssrc.height || 0), 0),
1981
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + (ssrc.fps || 0) * (ssrc.width || 0) * (ssrc.height || 0), 0),
1961
1982
  },
1962
1983
  {
1963
1984
  id: "height",
1964
- enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
1965
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((max, ssrc) => Math.max(max, ssrc.fps > 0 ? ssrc.height : 0), 0),
1985
+ enabled: ({ hasLiveTrack, track, trackStats, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!trackStats && !!track && !!ssrc0 && !!ssrc0.height,
1986
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((max, ssrc) => Math.max(max, ssrc.fps > 0 ? ssrc.height : 0), 0),
1966
1987
  },
1967
1988
  {
1968
1989
  id: "sourceHeight",
@@ -2005,19 +2026,19 @@ const metrics = [
2005
2026
  id: "cpu-pressure",
2006
2027
  global: true,
2007
2028
  enabled: ({ stats }) => { var _a; return ((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.source) === "cpu"; },
2008
- value: ({ stats }) => ({ nominal: 0.25, fair: 0.5, serious: 0.75, critical: 1 })[stats.pressure.state] || 0,
2029
+ value: ({ stats }) => { var _a; return ({ nominal: 0.25, fair: 0.5, serious: 0.75, critical: 1 })[((_a = stats === null || stats === void 0 ? void 0 : stats.pressure) === null || _a === void 0 ? void 0 : _a.state) || ""] || 0; },
2009
2030
  },
2010
2031
  {
2011
2032
  id: "turn-usage",
2012
2033
  global: true,
2013
- enabled: ({ stats }) => !!Object.values(stats.candidatePairs).length,
2014
- value: ({ stats }) => Object.values(stats.candidatePairs).some((cp) => cp.usingTurn),
2034
+ enabled: ({ stats }) => !!Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).length,
2035
+ value: ({ stats }) => Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).some((cp) => cp.usingTurn),
2015
2036
  },
2016
2037
  {
2017
2038
  id: "turn-tls-usage",
2018
2039
  global: true,
2019
- enabled: ({ stats }) => !!Object.values(stats.candidatePairs).length,
2020
- value: ({ stats }) => Object.values(stats.candidatePairs).some((cp) => cp.turnProtocol === "tls"),
2040
+ enabled: ({ stats }) => !!Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).length,
2041
+ value: ({ stats }) => Object.values((stats === null || stats === void 0 ? void 0 : stats.candidatePairs) || {}).some((cp) => cp.turnProtocol === "tls"),
2021
2042
  },
2022
2043
  {
2023
2044
  id: "concealment",
@@ -2052,7 +2073,7 @@ const metrics = [
2052
2073
  {
2053
2074
  id: "qpf",
2054
2075
  enabled: ({ hasLiveTrack, track, ssrc0, kind }) => hasLiveTrack && kind === "video" && !!track && !!ssrc0 && !!ssrc0.height,
2055
- value: ({ trackStats }) => Object.values(trackStats.ssrcs).reduce((sum, ssrc) => sum + (ssrc.qpf || 0), 0),
2076
+ value: ({ trackStats }) => Object.values((trackStats === null || trackStats === void 0 ? void 0 : trackStats.ssrcs) || {}).reduce((sum, ssrc) => sum + (ssrc.qpf || 0), 0),
2056
2077
  },
2057
2078
  ];
2058
2079
  let aggregatedMetrics;
@@ -4904,7 +4925,8 @@ class P2pRtcManager {
4904
4925
  if (!session.publicHostCandidateSeen &&
4905
4926
  !session.relayCandidateSeen &&
4906
4927
  !session.serverReflexiveCandidateSeen) {
4907
- this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED_3SEC);
4928
+ if (pc.iceConnectionState !== "connected" || pc.iceConnectionState !== "completed")
4929
+ this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED_3SEC);
4908
4930
  }
4909
4931
  }, ICE_PUBLIC_IP_GATHERING_TIMEOUT);
4910
4932
  break;
@@ -4974,7 +4996,9 @@ class P2pRtcManager {
4974
4996
  });
4975
4997
  if (!session.publicHostCandidateSeen &&
4976
4998
  !session.relayCandidateSeen &&
4977
- !session.serverReflexiveCandidateSeen) {
4999
+ !session.serverReflexiveCandidateSeen &&
5000
+ pc.iceConnectionState !== "connected" &&
5001
+ pc.iceConnectionState !== "completed") {
4978
5002
  this._emit(rtcManagerEvents.ICE_NO_PUBLIC_IP_GATHERED);
4979
5003
  }
4980
5004
  if (session.ipv6HostCandidateSeen) {
@@ -6927,5 +6951,5 @@ var RtcEventNames;
6927
6951
  RtcEventNames["stream_added"] = "stream_added";
6928
6952
  })(RtcEventNames || (RtcEventNames = {}));
6929
6953
 
6930
- export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
6954
+ export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
6931
6955
  //# sourceMappingURL=legacy-esm.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@whereby.com/media",
3
3
  "description": "Media library for Whereby",
4
- "version": "1.17.4",
4
+ "version": "1.17.6",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {
@@ -52,7 +52,7 @@
52
52
  "check-ip": "^1.1.1",
53
53
  "events": "^3.3.0",
54
54
  "ip-address": "^9.0.5",
55
- "mediasoup-client": "3.7.12",
55
+ "mediasoup-client": "3.7.18",
56
56
  "rtcstats": "github:whereby/rtcstats#5.4.1",
57
57
  "sdp": "^3.2.0",
58
58
  "sdp-transform": "^2.14.2",
@@ -60,7 +60,7 @@
60
60
  "typescript": "^5.3.3",
61
61
  "uuid": "^9.0.1",
62
62
  "uuid-validate": "^0.0.3",
63
- "webrtc-adapter": "^8.2.3"
63
+ "webrtc-adapter": "^9.0.1"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@babel/core": "^7.23.2",