@stream-io/video-client 0.3.20 → 0.3.22

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.js CHANGED
@@ -9389,6 +9389,40 @@ class ViewportTracker {
9389
9389
  }
9390
9390
  }
9391
9391
 
9392
+ /**
9393
+ * Checks whether the current browser is Safari.
9394
+ */
9395
+ const isSafari = () => {
9396
+ if (typeof navigator === 'undefined')
9397
+ return false;
9398
+ return /^((?!chrome|android).)*safari/i.test(navigator.userAgent || '');
9399
+ };
9400
+ /**
9401
+ * Checks whether the current browser is Firefox.
9402
+ */
9403
+ const isFirefox = () => {
9404
+ var _a;
9405
+ if (typeof navigator === 'undefined')
9406
+ return false;
9407
+ return (_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Firefox');
9408
+ };
9409
+ /**
9410
+ * Checks whether the current browser is Google Chrome.
9411
+ */
9412
+ const isChrome = () => {
9413
+ var _a;
9414
+ if (typeof navigator === 'undefined')
9415
+ return false;
9416
+ return (_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Chrome');
9417
+ };
9418
+
9419
+ var browsers = /*#__PURE__*/Object.freeze({
9420
+ __proto__: null,
9421
+ isChrome: isChrome,
9422
+ isFirefox: isFirefox,
9423
+ isSafari: isSafari
9424
+ });
9425
+
9392
9426
  const DEFAULT_VIEWPORT_VISIBILITY_STATE = {
9393
9427
  videoTrack: exports.VisibilityState.UNKNOWN,
9394
9428
  screenShareTrack: exports.VisibilityState.UNKNOWN,
@@ -9477,9 +9511,23 @@ class DynascaleManager {
9477
9511
  if (!boundParticipant)
9478
9512
  return;
9479
9513
  const requestTrackWithDimensions = (debounceType, dimension) => {
9514
+ if (dimension && (dimension.width === 0 || dimension.height === 0)) {
9515
+ // ignore 0x0 dimensions. this can happen when the video element
9516
+ // is not visible (e.g., has display: none).
9517
+ // we treat this as "unsubscription" as we don't want to keep
9518
+ // consuming bandwidth for a video that is not visible on the screen.
9519
+ this.logger('debug', `Ignoring 0x0 dimension`, boundParticipant);
9520
+ dimension = undefined;
9521
+ }
9480
9522
  this.call.updateSubscriptionsPartial(trackType, { [sessionId]: { dimension } }, debounceType);
9481
9523
  };
9482
9524
  const participant$ = this.call.state.participants$.pipe(rxjs.map((participants) => participants.find((participant) => participant.sessionId === sessionId)), rxjs.takeWhile((participant) => !!participant), rxjs.distinctUntilChanged(), rxjs.shareReplay(1));
9525
+ /**
9526
+ * Since the video elements are now being removed from the DOM (React SDK) upon
9527
+ * visibility change, this subscription is not in use an stays here only for the
9528
+ * plain JS integrations where integrators might choose not to remove the video
9529
+ * elements from the DOM.
9530
+ */
9483
9531
  // keep copy for resize observer handler
9484
9532
  let viewportVisibilityState;
9485
9533
  const viewportVisibilityStateSubscription = boundParticipant.isLocalParticipant
@@ -9524,6 +9572,8 @@ class DynascaleManager {
9524
9572
  lastDimensions = currentDimensions;
9525
9573
  });
9526
9574
  resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(videoElement);
9575
+ // element renders and gets bound - track subscription gets
9576
+ // triggered first other ones get skipped on initial subscriptions
9527
9577
  const publishedTracksSubscription = boundParticipant.isLocalParticipant
9528
9578
  ? null
9529
9579
  : participant$
@@ -9533,39 +9583,43 @@ class DynascaleManager {
9533
9583
  .subscribe((isPublishing) => {
9534
9584
  if (isPublishing) {
9535
9585
  // the participant just started to publish a track
9536
- requestTrackWithDimensions(exports.DebounceType.IMMEDIATE, {
9586
+ requestTrackWithDimensions(exports.DebounceType.FAST, {
9537
9587
  width: videoElement.clientWidth,
9538
9588
  height: videoElement.clientHeight,
9539
9589
  });
9540
9590
  }
9541
9591
  else {
9542
9592
  // the participant just stopped publishing a track
9543
- requestTrackWithDimensions(exports.DebounceType.IMMEDIATE, undefined);
9593
+ requestTrackWithDimensions(exports.DebounceType.FAST, undefined);
9544
9594
  }
9545
9595
  });
9596
+ videoElement.autoplay = true;
9597
+ videoElement.playsInline = true;
9598
+ // explicitly marking the element as muted will allow autoplay to work
9599
+ // without prior user interaction:
9600
+ // https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide
9601
+ videoElement.muted = true;
9546
9602
  const streamSubscription = participant$
9547
9603
  .pipe(rxjs.distinctUntilKeyChanged(trackType === 'videoTrack' ? 'videoStream' : 'screenShareStream'))
9548
9604
  .subscribe((p) => {
9549
9605
  const source = trackType === 'videoTrack' ? p.videoStream : p.screenShareStream;
9550
9606
  if (videoElement.srcObject === source)
9551
9607
  return;
9552
- setTimeout(() => {
9553
- videoElement.srcObject = source !== null && source !== void 0 ? source : null;
9554
- if (videoElement.srcObject) {
9608
+ videoElement.srcObject = source !== null && source !== void 0 ? source : null;
9609
+ if (isSafari() || isFirefox()) {
9610
+ setTimeout(() => {
9611
+ videoElement.srcObject = source !== null && source !== void 0 ? source : null;
9555
9612
  videoElement.play().catch((e) => {
9556
9613
  this.logger('warn', `Failed to play stream`, e);
9557
9614
  });
9558
- }
9559
- }, 0);
9615
+ // we add extra delay until we attempt to force-play
9616
+ // the participant's media stream in Firefox and Safari,
9617
+ // as they seem to have some timing issues
9618
+ }, 25);
9619
+ }
9560
9620
  });
9561
- videoElement.playsInline = true;
9562
- videoElement.autoplay = true;
9563
- // explicitly marking the element as muted will allow autoplay to work
9564
- // without prior user interaction:
9565
- // https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide
9566
- videoElement.muted = true;
9567
9621
  return () => {
9568
- requestTrackWithDimensions(exports.DebounceType.IMMEDIATE, undefined);
9622
+ requestTrackWithDimensions(exports.DebounceType.FAST, undefined);
9569
9623
  viewportVisibilityStateSubscription === null || viewportVisibilityStateSubscription === void 0 ? void 0 : viewportVisibilityStateSubscription.unsubscribe();
9570
9624
  publishedTracksSubscription === null || publishedTracksSubscription === void 0 ? void 0 : publishedTracksSubscription.unsubscribe();
9571
9625
  streamSubscription.unsubscribe();
@@ -13132,7 +13186,7 @@ class WSConnectionFallback {
13132
13186
  }
13133
13187
  }
13134
13188
 
13135
- const version = '0.3.20';
13189
+ const version = '0.3.22';
13136
13190
 
13137
13191
  const logger = getLogger(['location']);
13138
13192
  const HINT_URL = `https://hint.stream-io-video.com/`;
@@ -14112,40 +14166,6 @@ class StreamVideoServerClient extends StreamVideoClient {
14112
14166
  }
14113
14167
  }
14114
14168
 
14115
- /**
14116
- * Checks whether the current browser is Safari.
14117
- */
14118
- const isSafari = () => {
14119
- if (typeof navigator === 'undefined')
14120
- return false;
14121
- return /^((?!chrome|android).)*safari/i.test(navigator.userAgent || '');
14122
- };
14123
- /**
14124
- * Checks whether the current browser is Firefox.
14125
- */
14126
- const isFirefox = () => {
14127
- var _a;
14128
- if (typeof navigator === 'undefined')
14129
- return false;
14130
- return (_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Firefox');
14131
- };
14132
- /**
14133
- * Checks whether the current browser is Google Chrome.
14134
- */
14135
- const isChrome = () => {
14136
- var _a;
14137
- if (typeof navigator === 'undefined')
14138
- return false;
14139
- return (_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Chrome');
14140
- };
14141
-
14142
- var browsers = /*#__PURE__*/Object.freeze({
14143
- __proto__: null,
14144
- isChrome: isChrome,
14145
- isFirefox: isFirefox,
14146
- isSafari: isSafari
14147
- });
14148
-
14149
14169
  Object.defineProperty(exports, 'AxiosError', {
14150
14170
  enumerable: true,
14151
14171
  get: function () { return axios.AxiosError; }