@stream-io/video-client 1.56.0 → 1.57.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.
package/dist/index.es.js CHANGED
@@ -4927,7 +4927,7 @@ const toIceCandidate = (iceTrickle) => {
4927
4927
  }
4928
4928
  };
4929
4929
 
4930
- const version = "1.56.0";
4930
+ const version = "1.57.0";
4931
4931
  const [major, minor, patch] = version.split('.');
4932
4932
  let sdkInfo = {
4933
4933
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -11197,8 +11197,10 @@ class MediaPlaybackWatchdog {
11197
11197
  tracer;
11198
11198
  controller = new AbortController();
11199
11199
  pendingTimer;
11200
+ settleTimer;
11200
11201
  attempt = 0;
11201
11202
  disposed = false;
11203
+ stopped = false;
11202
11204
  constructor(opts) {
11203
11205
  this.element = opts.element;
11204
11206
  this.kind = opts.kind;
@@ -11219,33 +11221,49 @@ class MediaPlaybackWatchdog {
11219
11221
  return;
11220
11222
  this.disposed = true;
11221
11223
  this.controller.abort();
11224
+ this.clearTimers();
11225
+ };
11226
+ clearTimers = () => {
11222
11227
  if (this.pendingTimer)
11223
11228
  clearTimeout(this.pendingTimer);
11224
11229
  this.pendingTimer = undefined;
11230
+ if (this.settleTimer)
11231
+ clearTimeout(this.settleTimer);
11232
+ this.settleTimer = undefined;
11225
11233
  };
11226
11234
  onPlaying = () => {
11227
- if (this.attempt > 0) {
11228
- this.tracer.trace('mediaPlayback.recover.success', {
11229
- kind: this.kind,
11230
- attempts: this.attempt,
11231
- });
11232
- }
11233
- this.attempt = 0;
11234
11235
  if (this.pendingTimer)
11235
11236
  clearTimeout(this.pendingTimer);
11236
11237
  this.pendingTimer = undefined;
11238
+ if (this.attempt === 0 || this.settleTimer)
11239
+ return;
11240
+ this.settleTimer ??= setTimeout(this.onSettled, 1000);
11241
+ };
11242
+ onSettled = () => {
11243
+ this.settleTimer = undefined;
11244
+ if (this.element.paused)
11245
+ return;
11246
+ this.tracer.trace('mediaPlayback.recover.success', {
11247
+ kind: this.kind,
11248
+ attempts: this.attempt,
11249
+ });
11250
+ this.attempt = 0;
11251
+ this.stopped = false;
11237
11252
  };
11238
11253
  onPauseOrSuspend = (event) => {
11239
- if (this.disposed)
11254
+ if (this.disposed || this.stopped)
11240
11255
  return;
11241
11256
  this.tracer.trace('mediaPlayback.paused', {
11242
11257
  kind: this.kind,
11243
11258
  reason: event.type,
11244
11259
  });
11260
+ if (this.settleTimer)
11261
+ clearTimeout(this.settleTimer);
11262
+ this.settleTimer = undefined;
11245
11263
  this.scheduleRecovery();
11246
11264
  };
11247
11265
  scheduleRecovery = () => {
11248
- if (this.disposed || this.pendingTimer)
11266
+ if (this.disposed || this.stopped || this.pendingTimer)
11249
11267
  return;
11250
11268
  const skipReason = this.computeSkipReason();
11251
11269
  if (skipReason) {
@@ -11255,6 +11273,15 @@ class MediaPlaybackWatchdog {
11255
11273
  });
11256
11274
  return;
11257
11275
  }
11276
+ if (this.attempt >= 10) {
11277
+ this.stopped = true;
11278
+ this.clearTimers();
11279
+ this.tracer.trace('mediaPlayback.recover.giveUp', {
11280
+ kind: this.kind,
11281
+ attempts: this.attempt,
11282
+ });
11283
+ return;
11284
+ }
11258
11285
  const delay = this.attempt === 0 ? 0 : retryInterval(this.attempt);
11259
11286
  this.pendingTimer = setTimeout(this.attemptPlay, delay);
11260
11287
  };
@@ -11290,13 +11317,6 @@ class MediaPlaybackWatchdog {
11290
11317
  if (this.disposed)
11291
11318
  return;
11292
11319
  this.logger.warn(`Failed to recover ${this.kind} playback`, err);
11293
- if (this.attempt >= 10) {
11294
- this.tracer.trace('mediaPlayback.recover.giveUp', {
11295
- kind: this.kind,
11296
- attempts: this.attempt,
11297
- });
11298
- return;
11299
- }
11300
11320
  this.scheduleRecovery();
11301
11321
  }
11302
11322
  };
@@ -18491,11 +18511,11 @@ class StreamClient {
18491
18511
  return await this.wsConnection.connect(this.defaultWSTimeout);
18492
18512
  };
18493
18513
  getSdkVersion = () => this.options.clientAppIdentifier?.sdkVersion ||
18494
- "1.56.0";
18514
+ "1.57.0";
18495
18515
  getUserAgent = () => {
18496
18516
  if (!this.cachedUserAgent) {
18497
18517
  const { clientAppIdentifier = {} } = this.options;
18498
- const { sdkName = 'js', sdkVersion = "1.56.0", ...extras } = clientAppIdentifier;
18518
+ const { sdkName = 'js', sdkVersion = "1.57.0", ...extras } = clientAppIdentifier;
18499
18519
  this.cachedUserAgent = [
18500
18520
  `stream-video-${sdkName}-v${sdkVersion}`,
18501
18521
  ...Object.entries(extras).map(([key, value]) => `${key}=${value}`),