@stream-io/video-client 1.51.0 → 1.52.0

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/index.browser.es.js +311 -14
  3. package/dist/index.browser.es.js.map +1 -1
  4. package/dist/index.cjs.js +311 -13
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.es.js +311 -14
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/src/gen/video/sfu/event/events.d.ts +4 -0
  9. package/dist/src/gen/video/sfu/models/models.d.ts +204 -2
  10. package/dist/src/gen/video/sfu/signal_rpc/signal.client.d.ts +9 -1
  11. package/dist/src/gen/video/sfu/signal_rpc/signal.d.ts +67 -1
  12. package/dist/src/helpers/participantUtils.d.ts +10 -0
  13. package/dist/src/rtc/BasePeerConnection.d.ts +1 -1
  14. package/dist/src/rtc/types.d.ts +1 -0
  15. package/dist/src/stats/rtc/StatsTracer.d.ts +2 -1
  16. package/dist/src/stats/utils.d.ts +1 -0
  17. package/package.json +14 -14
  18. package/src/Call.ts +5 -1
  19. package/src/devices/__tests__/CameraManager.test.ts +3 -1
  20. package/src/devices/__tests__/DeviceManager.test.ts +3 -1
  21. package/src/devices/__tests__/MicrophoneManager.test.ts +3 -1
  22. package/src/devices/__tests__/MicrophoneManagerRN.test.ts +3 -1
  23. package/src/devices/__tests__/ScreenShareManager.test.ts +3 -1
  24. package/src/devices/__tests__/web-audio.mocks.ts +3 -1
  25. package/src/gen/video/sfu/event/events.ts +10 -0
  26. package/src/gen/video/sfu/models/models.ts +338 -0
  27. package/src/gen/video/sfu/signal_rpc/signal.client.ts +28 -2
  28. package/src/gen/video/sfu/signal_rpc/signal.ts +121 -15
  29. package/src/helpers/__tests__/DynascaleManager.test.ts +8 -7
  30. package/src/helpers/__tests__/browsers.test.ts +4 -4
  31. package/src/helpers/__tests__/participantUtils.test.ts +47 -0
  32. package/src/helpers/client-details.ts +4 -1
  33. package/src/helpers/participantUtils.ts +15 -0
  34. package/src/rtc/BasePeerConnection.ts +7 -1
  35. package/src/rtc/Subscriber.ts +1 -0
  36. package/src/rtc/__tests__/Subscriber.test.ts +5 -1
  37. package/src/rtc/__tests__/mocks/webrtc.mocks.ts +16 -15
  38. package/src/rtc/types.ts +1 -0
  39. package/src/stats/rtc/StatsTracer.ts +25 -4
  40. package/src/stats/rtc/__tests__/StatsTracer.test.ts +155 -0
package/dist/index.es.js CHANGED
@@ -1187,6 +1187,14 @@ var SdkType;
1187
1187
  * @generated from protobuf enum value: SDK_TYPE_PLAIN_JAVASCRIPT = 9;
1188
1188
  */
1189
1189
  SdkType[SdkType["PLAIN_JAVASCRIPT"] = 9] = "PLAIN_JAVASCRIPT";
1190
+ /**
1191
+ * @generated from protobuf enum value: SDK_TYPE_PYTHON = 10;
1192
+ */
1193
+ SdkType[SdkType["PYTHON"] = 10] = "PYTHON";
1194
+ /**
1195
+ * @generated from protobuf enum value: SDK_TYPE_VISION_AGENTS = 11;
1196
+ */
1197
+ SdkType[SdkType["VISION_AGENTS"] = 11] = "VISION_AGENTS";
1190
1198
  })(SdkType || (SdkType = {}));
1191
1199
  /**
1192
1200
  * @generated from protobuf enum stream.video.sfu.models.TrackUnpublishReason
@@ -1398,6 +1406,12 @@ var ClientCapability;
1398
1406
  * @generated from protobuf enum value: CLIENT_CAPABILITY_SUBSCRIBER_VIDEO_PAUSE = 1;
1399
1407
  */
1400
1408
  ClientCapability[ClientCapability["SUBSCRIBER_VIDEO_PAUSE"] = 1] = "SUBSCRIBER_VIDEO_PAUSE";
1409
+ /**
1410
+ * Instructs SFU that stats will be sent to the coordinator
1411
+ *
1412
+ * @generated from protobuf enum value: CLIENT_CAPABILITY_COORDINATOR_STATS = 2;
1413
+ */
1414
+ ClientCapability[ClientCapability["COORDINATOR_STATS"] = 2] = "COORDINATOR_STATS";
1401
1415
  })(ClientCapability || (ClientCapability = {}));
1402
1416
  /**
1403
1417
  * DegradationPreference represents the RTCDegradationPreference from WebRTC.
@@ -1863,6 +1877,12 @@ class ClientDetails$Type extends MessageType {
1863
1877
  { no: 2, name: 'os', kind: 'message', T: () => OS },
1864
1878
  { no: 3, name: 'browser', kind: 'message', T: () => Browser },
1865
1879
  { no: 4, name: 'device', kind: 'message', T: () => Device },
1880
+ {
1881
+ no: 5,
1882
+ name: 'webrtc_version',
1883
+ kind: 'scalar',
1884
+ T: 9 /*ScalarType.STRING*/,
1885
+ },
1866
1886
  ]);
1867
1887
  }
1868
1888
  }
@@ -2135,6 +2155,171 @@ class PerformanceStats$Type extends MessageType {
2135
2155
  * @generated MessageType for protobuf message stream.video.sfu.models.PerformanceStats
2136
2156
  */
2137
2157
  const PerformanceStats = new PerformanceStats$Type();
2158
+ // @generated message type with reflection information, may provide speed optimized methods
2159
+ class RtpBase$Type extends MessageType {
2160
+ constructor() {
2161
+ super('stream.video.sfu.models.RtpBase', [
2162
+ { no: 1, name: 'ssrc', kind: 'scalar', T: 13 /*ScalarType.UINT32*/ },
2163
+ { no: 2, name: 'kind', kind: 'scalar', T: 9 /*ScalarType.STRING*/ },
2164
+ {
2165
+ no: 3,
2166
+ name: 'timestamp_ms',
2167
+ kind: 'scalar',
2168
+ T: 1 /*ScalarType.DOUBLE*/,
2169
+ },
2170
+ ]);
2171
+ }
2172
+ }
2173
+ /**
2174
+ * @generated MessageType for protobuf message stream.video.sfu.models.RtpBase
2175
+ */
2176
+ const RtpBase = new RtpBase$Type();
2177
+ // @generated message type with reflection information, may provide speed optimized methods
2178
+ class InboundRtp$Type extends MessageType {
2179
+ constructor() {
2180
+ super('stream.video.sfu.models.InboundRtp', [
2181
+ { no: 1, name: 'base', kind: 'message', T: () => RtpBase },
2182
+ {
2183
+ no: 2,
2184
+ name: 'jitter_seconds',
2185
+ kind: 'scalar',
2186
+ T: 1 /*ScalarType.DOUBLE*/,
2187
+ },
2188
+ {
2189
+ no: 3,
2190
+ name: 'packets_received',
2191
+ kind: 'scalar',
2192
+ T: 4 /*ScalarType.UINT64*/,
2193
+ },
2194
+ {
2195
+ no: 4,
2196
+ name: 'packets_lost',
2197
+ kind: 'scalar',
2198
+ T: 4 /*ScalarType.UINT64*/,
2199
+ },
2200
+ {
2201
+ no: 5,
2202
+ name: 'packet_loss_percent',
2203
+ kind: 'scalar',
2204
+ T: 1 /*ScalarType.DOUBLE*/,
2205
+ },
2206
+ {
2207
+ no: 10,
2208
+ name: 'concealment_events',
2209
+ kind: 'scalar',
2210
+ T: 13 /*ScalarType.UINT32*/,
2211
+ },
2212
+ {
2213
+ no: 11,
2214
+ name: 'concealment_percent',
2215
+ kind: 'scalar',
2216
+ T: 1 /*ScalarType.DOUBLE*/,
2217
+ },
2218
+ { no: 20, name: 'fps', kind: 'scalar', T: 1 /*ScalarType.DOUBLE*/ },
2219
+ {
2220
+ no: 21,
2221
+ name: 'freeze_duration_seconds',
2222
+ kind: 'scalar',
2223
+ T: 1 /*ScalarType.DOUBLE*/,
2224
+ },
2225
+ {
2226
+ no: 22,
2227
+ name: 'avg_decode_time_seconds',
2228
+ kind: 'scalar',
2229
+ T: 1 /*ScalarType.DOUBLE*/,
2230
+ },
2231
+ {
2232
+ no: 23,
2233
+ name: 'min_dimension_px',
2234
+ kind: 'scalar',
2235
+ T: 13 /*ScalarType.UINT32*/,
2236
+ },
2237
+ ]);
2238
+ }
2239
+ }
2240
+ /**
2241
+ * @generated MessageType for protobuf message stream.video.sfu.models.InboundRtp
2242
+ */
2243
+ const InboundRtp = new InboundRtp$Type();
2244
+ // @generated message type with reflection information, may provide speed optimized methods
2245
+ class OutboundRtp$Type extends MessageType {
2246
+ constructor() {
2247
+ super('stream.video.sfu.models.OutboundRtp', [
2248
+ { no: 1, name: 'base', kind: 'message', T: () => RtpBase },
2249
+ { no: 10, name: 'fps', kind: 'scalar', T: 1 /*ScalarType.DOUBLE*/ },
2250
+ {
2251
+ no: 11,
2252
+ name: 'avg_encode_time_seconds',
2253
+ kind: 'scalar',
2254
+ T: 1 /*ScalarType.DOUBLE*/,
2255
+ },
2256
+ {
2257
+ no: 12,
2258
+ name: 'bitrate_bps',
2259
+ kind: 'scalar',
2260
+ T: 1 /*ScalarType.DOUBLE*/,
2261
+ },
2262
+ {
2263
+ no: 13,
2264
+ name: 'min_dimension_px',
2265
+ kind: 'scalar',
2266
+ T: 13 /*ScalarType.UINT32*/,
2267
+ },
2268
+ ]);
2269
+ }
2270
+ }
2271
+ /**
2272
+ * @generated MessageType for protobuf message stream.video.sfu.models.OutboundRtp
2273
+ */
2274
+ const OutboundRtp = new OutboundRtp$Type();
2275
+ // @generated message type with reflection information, may provide speed optimized methods
2276
+ class RemoteInboundRtp$Type extends MessageType {
2277
+ constructor() {
2278
+ super('stream.video.sfu.models.RemoteInboundRtp', [
2279
+ { no: 1, name: 'base', kind: 'message', T: () => RtpBase },
2280
+ {
2281
+ no: 2,
2282
+ name: 'jitter_seconds',
2283
+ kind: 'scalar',
2284
+ T: 1 /*ScalarType.DOUBLE*/,
2285
+ },
2286
+ {
2287
+ no: 3,
2288
+ name: 'round_trip_time_s',
2289
+ kind: 'scalar',
2290
+ T: 1 /*ScalarType.DOUBLE*/,
2291
+ },
2292
+ ]);
2293
+ }
2294
+ }
2295
+ /**
2296
+ * @generated MessageType for protobuf message stream.video.sfu.models.RemoteInboundRtp
2297
+ */
2298
+ const RemoteInboundRtp = new RemoteInboundRtp$Type();
2299
+ // @generated message type with reflection information, may provide speed optimized methods
2300
+ class RemoteOutboundRtp$Type extends MessageType {
2301
+ constructor() {
2302
+ super('stream.video.sfu.models.RemoteOutboundRtp', [
2303
+ { no: 1, name: 'base', kind: 'message', T: () => RtpBase },
2304
+ {
2305
+ no: 2,
2306
+ name: 'jitter_seconds',
2307
+ kind: 'scalar',
2308
+ T: 1 /*ScalarType.DOUBLE*/,
2309
+ },
2310
+ {
2311
+ no: 3,
2312
+ name: 'round_trip_time_s',
2313
+ kind: 'scalar',
2314
+ T: 1 /*ScalarType.DOUBLE*/,
2315
+ },
2316
+ ]);
2317
+ }
2318
+ }
2319
+ /**
2320
+ * @generated MessageType for protobuf message stream.video.sfu.models.RemoteOutboundRtp
2321
+ */
2322
+ const RemoteOutboundRtp = new RemoteOutboundRtp$Type();
2138
2323
 
2139
2324
  var models = /*#__PURE__*/Object.freeze({
2140
2325
  __proto__: null,
@@ -2159,8 +2344,10 @@ var models = /*#__PURE__*/Object.freeze({
2159
2344
  get ErrorCode () { return ErrorCode; },
2160
2345
  get GoAwayReason () { return GoAwayReason; },
2161
2346
  ICETrickle: ICETrickle$1,
2347
+ InboundRtp: InboundRtp,
2162
2348
  InputDevices: InputDevices,
2163
2349
  OS: OS,
2350
+ OutboundRtp: OutboundRtp,
2164
2351
  Participant: Participant,
2165
2352
  ParticipantCount: ParticipantCount,
2166
2353
  get ParticipantSource () { return ParticipantSource; },
@@ -2169,6 +2356,9 @@ var models = /*#__PURE__*/Object.freeze({
2169
2356
  Pin: Pin,
2170
2357
  PublishOption: PublishOption,
2171
2358
  RTMPIngress: RTMPIngress,
2359
+ RemoteInboundRtp: RemoteInboundRtp,
2360
+ RemoteOutboundRtp: RemoteOutboundRtp,
2361
+ RtpBase: RtpBase,
2172
2362
  Sdk: Sdk,
2173
2363
  get SdkType () { return SdkType; },
2174
2364
  StreamQuality: StreamQuality,
@@ -2286,6 +2476,62 @@ class Telemetry$Type extends MessageType {
2286
2476
  */
2287
2477
  const Telemetry = new Telemetry$Type();
2288
2478
  // @generated message type with reflection information, may provide speed optimized methods
2479
+ class SendMetricsRequest$Type extends MessageType {
2480
+ constructor() {
2481
+ super('stream.video.sfu.signal.SendMetricsRequest', [
2482
+ { no: 1, name: 'session_id', kind: 'scalar', T: 9 /*ScalarType.STRING*/ },
2483
+ {
2484
+ no: 2,
2485
+ name: 'unified_session_id',
2486
+ kind: 'scalar',
2487
+ T: 9 /*ScalarType.STRING*/,
2488
+ },
2489
+ {
2490
+ no: 3,
2491
+ name: 'inbounds',
2492
+ kind: 'message',
2493
+ repeat: 2 /*RepeatType.UNPACKED*/,
2494
+ T: () => InboundRtp,
2495
+ },
2496
+ {
2497
+ no: 4,
2498
+ name: 'outbounds',
2499
+ kind: 'message',
2500
+ repeat: 2 /*RepeatType.UNPACKED*/,
2501
+ T: () => OutboundRtp,
2502
+ },
2503
+ {
2504
+ no: 5,
2505
+ name: 'remote_inbounds',
2506
+ kind: 'message',
2507
+ repeat: 2 /*RepeatType.UNPACKED*/,
2508
+ T: () => RemoteInboundRtp,
2509
+ },
2510
+ {
2511
+ no: 6,
2512
+ name: 'remote_outbounds',
2513
+ kind: 'message',
2514
+ repeat: 2 /*RepeatType.UNPACKED*/,
2515
+ T: () => RemoteOutboundRtp,
2516
+ },
2517
+ ]);
2518
+ }
2519
+ }
2520
+ /**
2521
+ * @generated MessageType for protobuf message stream.video.sfu.signal.SendMetricsRequest
2522
+ */
2523
+ const SendMetricsRequest = new SendMetricsRequest$Type();
2524
+ // @generated message type with reflection information, may provide speed optimized methods
2525
+ class SendMetricsResponse$Type extends MessageType {
2526
+ constructor() {
2527
+ super('stream.video.sfu.signal.SendMetricsResponse', []);
2528
+ }
2529
+ }
2530
+ /**
2531
+ * @generated MessageType for protobuf message stream.video.sfu.signal.SendMetricsResponse
2532
+ */
2533
+ const SendMetricsResponse = new SendMetricsResponse$Type();
2534
+ // @generated message type with reflection information, may provide speed optimized methods
2289
2535
  class SendStatsRequest$Type extends MessageType {
2290
2536
  constructor() {
2291
2537
  super('stream.video.sfu.signal.SendStatsRequest', [
@@ -2559,6 +2805,12 @@ class SendAnswerRequest$Type extends MessageType {
2559
2805
  },
2560
2806
  { no: 2, name: 'sdp', kind: 'scalar', T: 9 /*ScalarType.STRING*/ },
2561
2807
  { no: 3, name: 'session_id', kind: 'scalar', T: 9 /*ScalarType.STRING*/ },
2808
+ {
2809
+ no: 4,
2810
+ name: 'negotiation_id',
2811
+ kind: 'scalar',
2812
+ T: 13 /*ScalarType.UINT32*/,
2813
+ },
2562
2814
  ]);
2563
2815
  }
2564
2816
  }
@@ -2666,6 +2918,12 @@ const SignalServer = new ServiceType('stream.video.sfu.signal.SignalServer', [
2666
2918
  I: SendStatsRequest,
2667
2919
  O: SendStatsResponse,
2668
2920
  },
2921
+ {
2922
+ name: 'SendMetrics',
2923
+ options: {},
2924
+ I: SendMetricsRequest,
2925
+ O: SendMetricsResponse,
2926
+ },
2669
2927
  {
2670
2928
  name: 'StartNoiseCancellation',
2671
2929
  options: {},
@@ -3346,6 +3604,12 @@ class SubscriberOffer$Type extends MessageType {
3346
3604
  super('stream.video.sfu.event.SubscriberOffer', [
3347
3605
  { no: 1, name: 'ice_restart', kind: 'scalar', T: 8 /*ScalarType.BOOL*/ },
3348
3606
  { no: 2, name: 'sdp', kind: 'scalar', T: 9 /*ScalarType.STRING*/ },
3607
+ {
3608
+ no: 3,
3609
+ name: 'negotiation_id',
3610
+ kind: 'scalar',
3611
+ T: 13 /*ScalarType.UINT32*/,
3612
+ },
3349
3613
  ]);
3350
3614
  }
3351
3615
  }
@@ -3804,18 +4068,25 @@ class SignalServerClient {
3804
4068
  const method = this.methods[6], opt = this._transport.mergeOptions(options);
3805
4069
  return stackIntercept('unary', this._transport, method, opt, input);
3806
4070
  }
4071
+ /**
4072
+ * @generated from protobuf rpc: SendMetrics(stream.video.sfu.signal.SendMetricsRequest) returns (stream.video.sfu.signal.SendMetricsResponse);
4073
+ */
4074
+ sendMetrics(input, options) {
4075
+ const method = this.methods[7], opt = this._transport.mergeOptions(options);
4076
+ return stackIntercept('unary', this._transport, method, opt, input);
4077
+ }
3807
4078
  /**
3808
4079
  * @generated from protobuf rpc: StartNoiseCancellation(stream.video.sfu.signal.StartNoiseCancellationRequest) returns (stream.video.sfu.signal.StartNoiseCancellationResponse);
3809
4080
  */
3810
4081
  startNoiseCancellation(input, options) {
3811
- const method = this.methods[7], opt = this._transport.mergeOptions(options);
4082
+ const method = this.methods[8], opt = this._transport.mergeOptions(options);
3812
4083
  return stackIntercept('unary', this._transport, method, opt, input);
3813
4084
  }
3814
4085
  /**
3815
4086
  * @generated from protobuf rpc: StopNoiseCancellation(stream.video.sfu.signal.StopNoiseCancellationRequest) returns (stream.video.sfu.signal.StopNoiseCancellationResponse);
3816
4087
  */
3817
4088
  stopNoiseCancellation(input, options) {
3818
- const method = this.methods[8], opt = this._transport.mergeOptions(options);
4089
+ const method = this.methods[9], opt = this._transport.mergeOptions(options);
3819
4090
  return stackIntercept('unary', this._transport, method, opt, input);
3820
4091
  }
3821
4092
  }
@@ -4995,6 +5266,16 @@ const hasScreenShareAudio = (p) => p.publishedTracks.includes(TrackType.SCREEN_S
4995
5266
  * @param p the participant.
4996
5267
  */
4997
5268
  const isPinned = (p) => !!p.pin && (p.pin.isLocalPin || p.pin.pinnedAt > 0);
5269
+ /**
5270
+ * Check if a participant has a track that is currently interrupted: the
5271
+ * participant intends to publish it (it is in `publishedTracks`) but no
5272
+ * media is flowing right now (it is in `interruptedTracks`).
5273
+ *
5274
+ * @param p the participant to check.
5275
+ * @param trackType the track type to check.
5276
+ */
5277
+ const hasInterruptedTrack = (p, trackType) => !!p.interruptedTracks?.includes(trackType) &&
5278
+ p.publishedTracks.includes(trackType);
4998
5279
  /**
4999
5280
  * Check if a participant has a paused track of the specified type.
5000
5281
  *
@@ -6360,7 +6641,7 @@ const getSdkVersion = (sdk) => {
6360
6641
  return sdk ? `${sdk.major}.${sdk.minor}.${sdk.patch}` : '0.0.0-development';
6361
6642
  };
6362
6643
 
6363
- const version = "1.51.0";
6644
+ const version = "1.52.0";
6364
6645
  const [major, minor, patch] = version.split('.');
6365
6646
  let sdkInfo = {
6366
6647
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -6458,6 +6739,7 @@ const getClientDetails = async () => {
6458
6739
  sdk: sdkInfo,
6459
6740
  os: osInfo,
6460
6741
  device: deviceInfo,
6742
+ webrtcVersion: webRtcInfo?.version || '',
6461
6743
  };
6462
6744
  }
6463
6745
  // @ts-expect-error - userAgentData is not yet in the TS types
@@ -6485,11 +6767,12 @@ const getClientDetails = async () => {
6485
6767
  // Eliminates the generic "Chromium" name and "Not)A_Brand" name from the list.
6486
6768
  // https://wicg.github.io/ua-client-hints/#create-arbitrary-brands-section
6487
6769
  const uaBrowser = userAgentData?.fullVersionList?.find((v) => !v.brand.includes('Chromium') && !v.brand.match(/[()\-./:;=?_]/g));
6770
+ const browserVersion = uaBrowser?.version || browser.version || '';
6488
6771
  return {
6489
6772
  sdk: sdkInfo,
6490
6773
  browser: {
6491
6774
  name: uaBrowser?.brand || browser.name || navigator.userAgent,
6492
- version: uaBrowser?.version || browser.version || '',
6775
+ version: browserVersion,
6493
6776
  },
6494
6777
  os: {
6495
6778
  name: userAgentData?.platform || os.name || '',
@@ -6502,6 +6785,7 @@ const getClientDetails = async () => {
6502
6785
  .join(' '),
6503
6786
  version: '',
6504
6787
  },
6788
+ webrtcVersion: browserVersion,
6505
6789
  };
6506
6790
  };
6507
6791
 
@@ -7165,7 +7449,7 @@ class StatsTracer {
7165
7449
  /**
7166
7450
  * Creates a new StatsTracer instance.
7167
7451
  */
7168
- constructor(pc, peerType, trackIdToTrackType) {
7452
+ constructor(pc, peerType, trackIdToTrackType, statsTimestampDriftThresholdMs = 0) {
7169
7453
  this.previousStats = {};
7170
7454
  this.frameTimeHistory = [];
7171
7455
  this.fpsHistory = [];
@@ -7179,7 +7463,7 @@ class StatsTracer {
7179
7463
  */
7180
7464
  this.get = async () => {
7181
7465
  const stats = await this.pc.getStats();
7182
- const currentStats = toObject(stats);
7466
+ const currentStats = toObjectWithCorrectedTimestamp(stats, Date.now(), this.driftThresholdMs);
7183
7467
  const performanceStats = this.withOverrides(this.peerType === PeerType.SUBSCRIBER
7184
7468
  ? this.getDecodeStats(currentStats)
7185
7469
  : this.getEncodeStats(currentStats));
@@ -7298,17 +7582,28 @@ class StatsTracer {
7298
7582
  this.pc = pc;
7299
7583
  this.peerType = peerType;
7300
7584
  this.trackIdToTrackType = trackIdToTrackType;
7585
+ this.driftThresholdMs = statsTimestampDriftThresholdMs;
7301
7586
  }
7302
7587
  }
7303
7588
  /**
7304
- * Convert the stat report to an object.
7589
+ * Convert the stat report to an object, correcting clock drift along the way.
7590
+ * Entries whose `timestamp` differs from `wallNow` by more than `thresholdMs`
7591
+ * are replaced with a clone whose `timestamp` is set to `wallNow`. The platform
7592
+ * clock backing `DOMHighResTimeStamp` can desynchronise from `Date.now()` after
7593
+ * system sleep or clock-jump events (notably on Electron/Chromium), which
7594
+ * corrupts the delta-compressed stats payload. A non-positive `thresholdMs`
7595
+ * disables correction.
7305
7596
  *
7306
7597
  * @param report the stat report to convert.
7598
+ * @param wallNow current wall-clock time used as the drift reference.
7599
+ * @param thresholdMs maximum tolerated drift in milliseconds.
7307
7600
  */
7308
- const toObject = (report) => {
7601
+ const toObjectWithCorrectedTimestamp = (report, wallNow, thresholdMs) => {
7309
7602
  const obj = {};
7603
+ const correct = thresholdMs > 0;
7310
7604
  report.forEach((v, k) => {
7311
- obj[k] = v;
7605
+ const drift = Math.abs(v.timestamp - wallNow);
7606
+ obj[k] = correct && drift > thresholdMs ? { ...v, timestamp: wallNow } : v;
7312
7607
  });
7313
7608
  return obj;
7314
7609
  };
@@ -7440,7 +7735,7 @@ class BasePeerConnection {
7440
7735
  /**
7441
7736
  * Constructs a new `BasePeerConnection` instance.
7442
7737
  */
7443
- constructor(peerType, { sfuClient, connectionConfig, state, dispatcher, onReconnectionNeeded, onIceConnected, tag, enableTracing, clientPublishOptions, iceRestartDelay = 2500, }) {
7738
+ constructor(peerType, { sfuClient, connectionConfig, state, dispatcher, onReconnectionNeeded, onIceConnected, tag, enableTracing, clientPublishOptions, iceRestartDelay = 2500, statsTimestampDriftThresholdMs = 0, }) {
7444
7739
  this.iceHasEverConnected = false;
7445
7740
  this.isIceRestarting = false;
7446
7741
  this.isDisposed = false;
@@ -7734,7 +8029,7 @@ class BasePeerConnection {
7734
8029
  this.onIceConnected = onIceConnected;
7735
8030
  this.logger = videoLoggerSystem.getLogger(peerType === PeerType.SUBSCRIBER ? 'Subscriber' : 'Publisher', { tags: [tag] });
7736
8031
  this.pc = this.createPeerConnection(connectionConfig);
7737
- this.stats = new StatsTracer(this.pc, peerType, this.trackIdToTrackType);
8032
+ this.stats = new StatsTracer(this.pc, peerType, this.trackIdToTrackType, statsTimestampDriftThresholdMs);
7738
8033
  if (enableTracing) {
7739
8034
  this.tracer = new Tracer(`${tag}-${peerType === PeerType.SUBSCRIBER ? 'sub' : 'pub'}`);
7740
8035
  this.tracer.trace('create', {
@@ -8820,6 +9115,7 @@ class Subscriber extends BasePeerConnection {
8820
9115
  await this.sfuClient.sendAnswer({
8821
9116
  peerType: PeerType.SUBSCRIBER,
8822
9117
  sdp: answer.sdp || '',
9118
+ negotiationId: subscriberOffer.negotiationId,
8823
9119
  });
8824
9120
  this.isIceRestarting = false;
8825
9121
  };
@@ -14365,7 +14661,7 @@ class Call {
14365
14661
  */
14366
14662
  this.initPublisherAndSubscriber = async (opts) => {
14367
14663
  const { sfuClient, connectionConfig, clientDetails, statsOptions, publishOptions, closePreviousInstances, unifiedSessionId, } = opts;
14368
- const { enable_rtc_stats: enableTracing } = statsOptions;
14664
+ const { enable_rtc_stats: enableTracing, reporting_interval_ms: reportingIntervalMs, } = statsOptions;
14369
14665
  if (closePreviousInstances && this.subscriber) {
14370
14666
  await this.subscriber.dispose();
14371
14667
  }
@@ -14376,6 +14672,7 @@ class Call {
14376
14672
  connectionConfig,
14377
14673
  tag: sfuClient.tag,
14378
14674
  enableTracing,
14675
+ statsTimestampDriftThresholdMs: reportingIntervalMs / 2,
14379
14676
  clientPublishOptions: this.clientPublishOptions,
14380
14677
  onReconnectionNeeded: (kind, reason, peerType) => {
14381
14678
  this.reconnect(kind, reason).catch((err) => {
@@ -17017,7 +17314,7 @@ class StreamClient {
17017
17314
  this.getUserAgent = () => {
17018
17315
  if (!this.cachedUserAgent) {
17019
17316
  const { clientAppIdentifier = {} } = this.options;
17020
- const { sdkName = 'js', sdkVersion = "1.51.0", ...extras } = clientAppIdentifier;
17317
+ const { sdkName = 'js', sdkVersion = "1.52.0", ...extras } = clientAppIdentifier;
17021
17318
  this.cachedUserAgent = [
17022
17319
  `stream-video-${sdkName}-v${sdkVersion}`,
17023
17320
  ...Object.entries(extras).map(([key, value]) => `${key}=${value}`),
@@ -17653,5 +17950,5 @@ const humanize = (n) => {
17653
17950
  return String(n);
17654
17951
  };
17655
17952
 
17656
- export { AudioSettingsRequestDefaultDeviceEnum, AudioSettingsResponseDefaultDeviceEnum, browsers as Browsers, Call, CallRecordingFailedEventRecordingTypeEnum, CallRecordingReadyEventRecordingTypeEnum, CallRecordingStartedEventRecordingTypeEnum, CallRecordingStoppedEventRecordingTypeEnum, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, CreateDeviceRequestPushProviderEnum, DebounceType, DeviceManager, DeviceManagerState, DynascaleManager, ErrorFromResponse, FrameRecordingSettingsRequestModeEnum, FrameRecordingSettingsRequestQualityEnum, FrameRecordingSettingsResponseModeEnum, IndividualRecordingSettingsRequestModeEnum, IndividualRecordingSettingsResponseModeEnum, IngressAudioEncodingOptionsRequestChannelsEnum, IngressSourceRequestFpsEnum, IngressVideoLayerRequestCodecEnum, LayoutSettingsRequestNameEnum, MicrophoneManager, MicrophoneManagerState, NoiseCancellationSettingsModeEnum, OwnCapability, RTMPBroadcastRequestQualityEnum, RTMPSettingsRequestQualityEnum, RawRecordingSettingsRequestModeEnum, RawRecordingSettingsResponseModeEnum, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, events as SfuEvents, SfuJoinError, models as SfuModels, SpeakerManager, SpeakerState, StartClosedCaptionsRequestLanguageEnum, StartTranscriptionRequestLanguageEnum, StreamSfuClient, StreamVideoClient, StreamVideoReadOnlyStateStore, StreamVideoWriteableStateStore, TranscriptionSettingsRequestClosedCaptionModeEnum, TranscriptionSettingsRequestLanguageEnum, TranscriptionSettingsRequestModeEnum, TranscriptionSettingsResponseClosedCaptionModeEnum, TranscriptionSettingsResponseLanguageEnum, TranscriptionSettingsResponseModeEnum, VideoSettingsRequestCameraFacingEnum, VideoSettingsResponseCameraFacingEnum, ViewportTracker, VisibilityState, checkIfAudioOutputChangeSupported, combineComparators, conditional, createSoundDetector, defaultSortPreset, descending, deviceIds$, disposeOfMediaStream, dominantSpeaker, getAudioBrowserPermission, getAudioDevices, getAudioOutputDevices, getAudioStream, getClientDetails, getDeviceState, getScreenShareStream, getSdkInfo, getVideoBrowserPermission, getVideoDevices, getVideoStream, getWebRTCInfo, hasAudio$1 as hasAudio, hasPausedTrack, hasScreenShare, hasScreenShareAudio, hasVideo, humanize, isPinned, livestreamOrAudioRoomSortPreset, logToConsole, name, noopComparator, paginatedLayoutSortPreset, pinned, publishingAudio, publishingVideo, reactionType, resolveDeviceId, role, screenSharing, setDeviceInfo, setOSInfo, setPowerState, setSdkInfo, setThermalState, setWebRTCInfo, speakerLayoutSortPreset, speaking, videoLoggerSystem, withParticipantSource };
17953
+ export { AudioSettingsRequestDefaultDeviceEnum, AudioSettingsResponseDefaultDeviceEnum, browsers as Browsers, Call, CallRecordingFailedEventRecordingTypeEnum, CallRecordingReadyEventRecordingTypeEnum, CallRecordingStartedEventRecordingTypeEnum, CallRecordingStoppedEventRecordingTypeEnum, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, CreateDeviceRequestPushProviderEnum, DebounceType, DeviceManager, DeviceManagerState, DynascaleManager, ErrorFromResponse, FrameRecordingSettingsRequestModeEnum, FrameRecordingSettingsRequestQualityEnum, FrameRecordingSettingsResponseModeEnum, IndividualRecordingSettingsRequestModeEnum, IndividualRecordingSettingsResponseModeEnum, IngressAudioEncodingOptionsRequestChannelsEnum, IngressSourceRequestFpsEnum, IngressVideoLayerRequestCodecEnum, LayoutSettingsRequestNameEnum, MicrophoneManager, MicrophoneManagerState, NoiseCancellationSettingsModeEnum, OwnCapability, RTMPBroadcastRequestQualityEnum, RTMPSettingsRequestQualityEnum, RawRecordingSettingsRequestModeEnum, RawRecordingSettingsResponseModeEnum, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, events as SfuEvents, SfuJoinError, models as SfuModels, SpeakerManager, SpeakerState, StartClosedCaptionsRequestLanguageEnum, StartTranscriptionRequestLanguageEnum, StreamSfuClient, StreamVideoClient, StreamVideoReadOnlyStateStore, StreamVideoWriteableStateStore, TranscriptionSettingsRequestClosedCaptionModeEnum, TranscriptionSettingsRequestLanguageEnum, TranscriptionSettingsRequestModeEnum, TranscriptionSettingsResponseClosedCaptionModeEnum, TranscriptionSettingsResponseLanguageEnum, TranscriptionSettingsResponseModeEnum, VideoSettingsRequestCameraFacingEnum, VideoSettingsResponseCameraFacingEnum, ViewportTracker, VisibilityState, checkIfAudioOutputChangeSupported, combineComparators, conditional, createSoundDetector, defaultSortPreset, descending, deviceIds$, disposeOfMediaStream, dominantSpeaker, getAudioBrowserPermission, getAudioDevices, getAudioOutputDevices, getAudioStream, getClientDetails, getDeviceState, getScreenShareStream, getSdkInfo, getVideoBrowserPermission, getVideoDevices, getVideoStream, getWebRTCInfo, hasAudio$1 as hasAudio, hasInterruptedTrack, hasPausedTrack, hasScreenShare, hasScreenShareAudio, hasVideo, humanize, isPinned, livestreamOrAudioRoomSortPreset, logToConsole, name, noopComparator, paginatedLayoutSortPreset, pinned, publishingAudio, publishingVideo, reactionType, resolveDeviceId, role, screenSharing, setDeviceInfo, setOSInfo, setPowerState, setSdkInfo, setThermalState, setWebRTCInfo, speakerLayoutSortPreset, speaking, videoLoggerSystem, withParticipantSource };
17657
17954
  //# sourceMappingURL=index.es.js.map