@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.es.js CHANGED
@@ -9369,6 +9369,40 @@ class ViewportTracker {
9369
9369
  }
9370
9370
  }
9371
9371
 
9372
+ /**
9373
+ * Checks whether the current browser is Safari.
9374
+ */
9375
+ const isSafari = () => {
9376
+ if (typeof navigator === 'undefined')
9377
+ return false;
9378
+ return /^((?!chrome|android).)*safari/i.test(navigator.userAgent || '');
9379
+ };
9380
+ /**
9381
+ * Checks whether the current browser is Firefox.
9382
+ */
9383
+ const isFirefox = () => {
9384
+ var _a;
9385
+ if (typeof navigator === 'undefined')
9386
+ return false;
9387
+ return (_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Firefox');
9388
+ };
9389
+ /**
9390
+ * Checks whether the current browser is Google Chrome.
9391
+ */
9392
+ const isChrome = () => {
9393
+ var _a;
9394
+ if (typeof navigator === 'undefined')
9395
+ return false;
9396
+ return (_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Chrome');
9397
+ };
9398
+
9399
+ var browsers = /*#__PURE__*/Object.freeze({
9400
+ __proto__: null,
9401
+ isChrome: isChrome,
9402
+ isFirefox: isFirefox,
9403
+ isSafari: isSafari
9404
+ });
9405
+
9372
9406
  const DEFAULT_VIEWPORT_VISIBILITY_STATE = {
9373
9407
  videoTrack: VisibilityState.UNKNOWN,
9374
9408
  screenShareTrack: VisibilityState.UNKNOWN,
@@ -9457,9 +9491,23 @@ class DynascaleManager {
9457
9491
  if (!boundParticipant)
9458
9492
  return;
9459
9493
  const requestTrackWithDimensions = (debounceType, dimension) => {
9494
+ if (dimension && (dimension.width === 0 || dimension.height === 0)) {
9495
+ // ignore 0x0 dimensions. this can happen when the video element
9496
+ // is not visible (e.g., has display: none).
9497
+ // we treat this as "unsubscription" as we don't want to keep
9498
+ // consuming bandwidth for a video that is not visible on the screen.
9499
+ this.logger('debug', `Ignoring 0x0 dimension`, boundParticipant);
9500
+ dimension = undefined;
9501
+ }
9460
9502
  this.call.updateSubscriptionsPartial(trackType, { [sessionId]: { dimension } }, debounceType);
9461
9503
  };
9462
9504
  const participant$ = this.call.state.participants$.pipe(map$2((participants) => participants.find((participant) => participant.sessionId === sessionId)), takeWhile((participant) => !!participant), distinctUntilChanged$1(), shareReplay(1));
9505
+ /**
9506
+ * Since the video elements are now being removed from the DOM (React SDK) upon
9507
+ * visibility change, this subscription is not in use an stays here only for the
9508
+ * plain JS integrations where integrators might choose not to remove the video
9509
+ * elements from the DOM.
9510
+ */
9463
9511
  // keep copy for resize observer handler
9464
9512
  let viewportVisibilityState;
9465
9513
  const viewportVisibilityStateSubscription = boundParticipant.isLocalParticipant
@@ -9504,6 +9552,8 @@ class DynascaleManager {
9504
9552
  lastDimensions = currentDimensions;
9505
9553
  });
9506
9554
  resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(videoElement);
9555
+ // element renders and gets bound - track subscription gets
9556
+ // triggered first other ones get skipped on initial subscriptions
9507
9557
  const publishedTracksSubscription = boundParticipant.isLocalParticipant
9508
9558
  ? null
9509
9559
  : participant$
@@ -9513,39 +9563,43 @@ class DynascaleManager {
9513
9563
  .subscribe((isPublishing) => {
9514
9564
  if (isPublishing) {
9515
9565
  // the participant just started to publish a track
9516
- requestTrackWithDimensions(DebounceType.IMMEDIATE, {
9566
+ requestTrackWithDimensions(DebounceType.FAST, {
9517
9567
  width: videoElement.clientWidth,
9518
9568
  height: videoElement.clientHeight,
9519
9569
  });
9520
9570
  }
9521
9571
  else {
9522
9572
  // the participant just stopped publishing a track
9523
- requestTrackWithDimensions(DebounceType.IMMEDIATE, undefined);
9573
+ requestTrackWithDimensions(DebounceType.FAST, undefined);
9524
9574
  }
9525
9575
  });
9576
+ videoElement.autoplay = true;
9577
+ videoElement.playsInline = true;
9578
+ // explicitly marking the element as muted will allow autoplay to work
9579
+ // without prior user interaction:
9580
+ // https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide
9581
+ videoElement.muted = true;
9526
9582
  const streamSubscription = participant$
9527
9583
  .pipe(distinctUntilKeyChanged(trackType === 'videoTrack' ? 'videoStream' : 'screenShareStream'))
9528
9584
  .subscribe((p) => {
9529
9585
  const source = trackType === 'videoTrack' ? p.videoStream : p.screenShareStream;
9530
9586
  if (videoElement.srcObject === source)
9531
9587
  return;
9532
- setTimeout(() => {
9533
- videoElement.srcObject = source !== null && source !== void 0 ? source : null;
9534
- if (videoElement.srcObject) {
9588
+ videoElement.srcObject = source !== null && source !== void 0 ? source : null;
9589
+ if (isSafari() || isFirefox()) {
9590
+ setTimeout(() => {
9591
+ videoElement.srcObject = source !== null && source !== void 0 ? source : null;
9535
9592
  videoElement.play().catch((e) => {
9536
9593
  this.logger('warn', `Failed to play stream`, e);
9537
9594
  });
9538
- }
9539
- }, 0);
9595
+ // we add extra delay until we attempt to force-play
9596
+ // the participant's media stream in Firefox and Safari,
9597
+ // as they seem to have some timing issues
9598
+ }, 25);
9599
+ }
9540
9600
  });
9541
- videoElement.playsInline = true;
9542
- videoElement.autoplay = true;
9543
- // explicitly marking the element as muted will allow autoplay to work
9544
- // without prior user interaction:
9545
- // https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide
9546
- videoElement.muted = true;
9547
9601
  return () => {
9548
- requestTrackWithDimensions(DebounceType.IMMEDIATE, undefined);
9602
+ requestTrackWithDimensions(DebounceType.FAST, undefined);
9549
9603
  viewportVisibilityStateSubscription === null || viewportVisibilityStateSubscription === void 0 ? void 0 : viewportVisibilityStateSubscription.unsubscribe();
9550
9604
  publishedTracksSubscription === null || publishedTracksSubscription === void 0 ? void 0 : publishedTracksSubscription.unsubscribe();
9551
9605
  streamSubscription.unsubscribe();
@@ -13112,7 +13166,7 @@ class WSConnectionFallback {
13112
13166
  }
13113
13167
  }
13114
13168
 
13115
- const version = '0.3.20';
13169
+ const version = '0.3.22';
13116
13170
 
13117
13171
  const logger = getLogger(['location']);
13118
13172
  const HINT_URL = `https://hint.stream-io-video.com/`;
@@ -14092,39 +14146,5 @@ class StreamVideoServerClient extends StreamVideoClient {
14092
14146
  }
14093
14147
  }
14094
14148
 
14095
- /**
14096
- * Checks whether the current browser is Safari.
14097
- */
14098
- const isSafari = () => {
14099
- if (typeof navigator === 'undefined')
14100
- return false;
14101
- return /^((?!chrome|android).)*safari/i.test(navigator.userAgent || '');
14102
- };
14103
- /**
14104
- * Checks whether the current browser is Firefox.
14105
- */
14106
- const isFirefox = () => {
14107
- var _a;
14108
- if (typeof navigator === 'undefined')
14109
- return false;
14110
- return (_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Firefox');
14111
- };
14112
- /**
14113
- * Checks whether the current browser is Google Chrome.
14114
- */
14115
- const isChrome = () => {
14116
- var _a;
14117
- if (typeof navigator === 'undefined')
14118
- return false;
14119
- return (_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Chrome');
14120
- };
14121
-
14122
- var browsers = /*#__PURE__*/Object.freeze({
14123
- __proto__: null,
14124
- isChrome: isChrome,
14125
- isFirefox: isFirefox,
14126
- isSafari: isSafari
14127
- });
14128
-
14129
14149
  export { AudioSettingsDefaultDeviceEnum, AudioSettingsRequestDefaultDeviceEnum, browsers as Browsers, Call, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, CreateDeviceRequestPushProviderEnum, DebounceType, DynascaleManager, ErrorFromResponse, InputMediaDeviceManager, InputMediaDeviceManagerState, MicrophoneManager, MicrophoneManagerState, OwnCapability, RecordSettingsModeEnum, RecordSettingsQualityEnum, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, rxUtils as RxUtils, events as SfuEvents, models as SfuModels, SpeakerManager, SpeakerState, StreamSfuClient, StreamVideoClient, StreamVideoReadOnlyStateStore, StreamVideoServerClient, StreamVideoWriteableStateStore, TranscriptionSettingsModeEnum, TranscriptionSettingsRequestModeEnum, VideoSettingsCameraFacingEnum, VideoSettingsRequestCameraFacingEnum, ViewportTracker, VisibilityState, checkIfAudioOutputChangeSupported, combineComparators, conditional, createSoundDetector, defaultSortPreset, descending, disposeOfMediaStream, dominantSpeaker, getAudioDevices, getAudioOutputDevices, getAudioStream, getClientDetails, getDeviceInfo, getLogger, getOSInfo, getScreenShareStream, getSdkInfo, getVideoDevices, getVideoStream, isStreamVideoLocalParticipant, livestreamOrAudioRoomSortPreset, logLevels, logToConsole, name, noopComparator, pinned, publishingAudio, publishingVideo, reactionType, role, screenSharing, setDeviceInfo, setLogLevel, setLogger, setOSInfo, setSdkInfo, speakerLayoutSortPreset, speaking, watchForAddedDefaultAudioDevice, watchForAddedDefaultAudioOutputDevice, watchForAddedDefaultVideoDevice, watchForDisconnectedAudioDevice, watchForDisconnectedAudioOutputDevice, watchForDisconnectedVideoDevice };
14130
14150
  //# sourceMappingURL=index.es.js.map