@stream-io/video-client 0.3.36 → 0.4.1

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
@@ -5739,9 +5739,6 @@ var DebounceType;
5739
5739
  DebounceType[DebounceType["MEDIUM"] = 600] = "MEDIUM";
5740
5740
  DebounceType[DebounceType["SLOW"] = 1200] = "SLOW";
5741
5741
  })(DebounceType || (DebounceType = {}));
5742
- const isStreamVideoLocalParticipant = (p) => {
5743
- return !!p.isLocalParticipant;
5744
- };
5745
5742
 
5746
5743
  /**
5747
5744
  * @generated from protobuf service stream.video.sfu.signal.SignalServer
@@ -6225,21 +6222,6 @@ const trackTypeToParticipantStreamKey = (trackType) => {
6225
6222
  throw new Error(`Unknown track type: ${exhaustiveTrackTypeCheck}`);
6226
6223
  }
6227
6224
  };
6228
- const trackTypeToDeviceIdKey = (trackType) => {
6229
- switch (trackType) {
6230
- case TrackType.AUDIO:
6231
- return 'audioDeviceId';
6232
- case TrackType.VIDEO:
6233
- return 'videoDeviceId';
6234
- case TrackType.SCREEN_SHARE:
6235
- case TrackType.SCREEN_SHARE_AUDIO:
6236
- case TrackType.UNSPECIFIED:
6237
- return undefined;
6238
- default:
6239
- const exhaustiveTrackTypeCheck = trackType;
6240
- throw new Error(`Unknown track type: ${exhaustiveTrackTypeCheck}`);
6241
- }
6242
- };
6243
6225
  const muteTypeToTrackType = (muteType) => {
6244
6226
  switch (muteType) {
6245
6227
  case 'audio':
@@ -6631,14 +6613,11 @@ class Publisher {
6631
6613
  }));
6632
6614
  }
6633
6615
  else {
6634
- const deviceId = track.getSettings().deviceId;
6635
- const audioOrVideoDeviceKey = trackTypeToDeviceIdKey(trackType);
6636
6616
  this.state.updateParticipant(this.sfuClient.sessionId, (p) => {
6637
6617
  return {
6638
6618
  publishedTracks: p.publishedTracks.includes(trackType)
6639
6619
  ? p.publishedTracks
6640
6620
  : [...p.publishedTracks, trackType],
6641
- ...(audioOrVideoDeviceKey && { [audioOrVideoDeviceKey]: deviceId }),
6642
6621
  [audioOrVideoOrScreenShareStream]: mediaStream,
6643
6622
  };
6644
6623
  });
@@ -8480,7 +8459,7 @@ class CallState {
8480
8459
  // maintain stable-sort by mutating the participants stored
8481
8460
  // in the original subject
8482
8461
  map$1((ps) => ps.sort(this.sortParticipantsBy)), shareReplay({ bufferSize: 1, refCount: true }));
8483
- this.localParticipant$ = this.participants$.pipe(map$1((participants) => participants.find(isStreamVideoLocalParticipant)), shareReplay({ bufferSize: 1, refCount: true }));
8462
+ this.localParticipant$ = this.participants$.pipe(map$1((participants) => participants.find((p) => p.isLocalParticipant)), shareReplay({ bufferSize: 1, refCount: true }));
8484
8463
  this.remoteParticipants$ = this.participants$.pipe(map$1((participants) => participants.filter((p) => !p.isLocalParticipant)), shareReplay({ bufferSize: 1, refCount: true }));
8485
8464
  this.pinnedParticipants$ = this.participants$.pipe(map$1((participants) => participants.filter((p) => !!p.pin)), shareReplay({ bufferSize: 1, refCount: true }));
8486
8465
  this.dominantSpeaker$ = this.participants$.pipe(map$1((participants) => participants.find((p) => p.isDominantSpeaker)), shareReplay({ bufferSize: 1, refCount: true }));
@@ -9215,14 +9194,7 @@ const reconcileParticipantLocalState = (target, source) => {
9215
9194
  if (!source)
9216
9195
  return target;
9217
9196
  // copy everything from source to target
9218
- Object.assign(target, source);
9219
- if (isStreamVideoLocalParticipant(source) &&
9220
- isStreamVideoLocalParticipant(target)) {
9221
- target.audioDeviceId = source.audioDeviceId;
9222
- target.videoDeviceId = source.videoDeviceId;
9223
- target.audioOutputDeviceId = source.audioOutputDeviceId;
9224
- }
9225
- return target;
9197
+ return Object.assign(target, source);
9226
9198
  };
9227
9199
 
9228
9200
  /**
@@ -9825,24 +9797,20 @@ class DynascaleManager {
9825
9797
  }
9826
9798
  });
9827
9799
  });
9828
- const sinkIdSubscription = combineLatest([
9829
- this.call.state.localParticipant$,
9830
- this.call.speaker.state.selectedDevice$,
9831
- ]).subscribe(([p, selectedDevice]) => {
9832
- const deviceId = getSdkInfo()?.type === SdkType.REACT
9833
- ? p?.audioOutputDeviceId
9834
- : selectedDevice;
9835
- if ('setSinkId' in audioElement && typeof deviceId === 'string') {
9836
- // @ts-expect-error setSinkId is not yet in the lib
9837
- audioElement.setSinkId(deviceId);
9838
- }
9839
- });
9800
+ const sinkIdSubscription = !('setSinkId' in audioElement)
9801
+ ? null
9802
+ : this.call.speaker.state.selectedDevice$.subscribe((deviceId) => {
9803
+ if (deviceId) {
9804
+ // @ts-expect-error setSinkId is not yet in the lib
9805
+ audioElement.setSinkId(deviceId);
9806
+ }
9807
+ });
9840
9808
  const volumeSubscription = this.call.speaker.state.volume$.subscribe((volume) => {
9841
9809
  audioElement.volume = volume;
9842
9810
  });
9843
9811
  audioElement.autoplay = true;
9844
9812
  return () => {
9845
- sinkIdSubscription.unsubscribe();
9813
+ sinkIdSubscription?.unsubscribe();
9846
9814
  volumeSubscription.unsubscribe();
9847
9815
  updateMediaStreamSubscription.unsubscribe();
9848
9816
  };
@@ -9891,11 +9859,12 @@ class PermissionsContext {
9891
9859
  * within the call.
9892
9860
  *
9893
9861
  * @param permission the permission to check for.
9862
+ * @param settings the call settings to check against (optional).
9894
9863
  */
9895
- this.canRequest = (permission) => {
9896
- if (!this.settings)
9864
+ this.canRequest = (permission, settings = this.settings) => {
9865
+ if (!settings)
9897
9866
  return false;
9898
- const { audio, video, screensharing } = this.settings;
9867
+ const { audio, video, screensharing } = settings;
9899
9868
  switch (permission) {
9900
9869
  case OwnCapability.SEND_AUDIO:
9901
9870
  return audio.access_request_enabled;
@@ -10303,6 +10272,7 @@ class InputMediaDeviceManager {
10303
10272
  try {
10304
10273
  await this.enablePromise;
10305
10274
  this.state.setStatus('enabled');
10275
+ this.enablePromise = undefined;
10306
10276
  }
10307
10277
  catch (error) {
10308
10278
  this.enablePromise = undefined;
@@ -11148,6 +11118,7 @@ class Call {
11148
11118
  this.watching = true;
11149
11119
  this.clientStore.registerCall(this);
11150
11120
  }
11121
+ this.applyDeviceConfig();
11151
11122
  return response;
11152
11123
  };
11153
11124
  /**
@@ -11167,6 +11138,7 @@ class Call {
11167
11138
  this.watching = true;
11168
11139
  this.clientStore.registerCall(this);
11169
11140
  }
11141
+ this.applyDeviceConfig();
11170
11142
  return response;
11171
11143
  };
11172
11144
  /**
@@ -11498,15 +11470,12 @@ class Call {
11498
11470
  this.state.setServerSidePins(pins);
11499
11471
  this.reconnectAttempts = 0; // reset the reconnect attempts counter
11500
11472
  this.state.setCallingState(CallingState.JOINED);
11501
- // React uses a different device management for now
11502
- if (getSdkInfo()?.type !== SdkType.REACT) {
11503
- try {
11504
- await this.initCamera();
11505
- await this.initMic();
11506
- }
11507
- catch (error) {
11508
- this.logger('warn', 'Camera and/or mic init failed during join call');
11509
- }
11473
+ try {
11474
+ await this.initCamera({ setStatus: true });
11475
+ await this.initMic({ setStatus: true });
11476
+ }
11477
+ catch (error) {
11478
+ this.logger('warn', 'Camera and/or mic init failed during join call');
11510
11479
  }
11511
11480
  // 3. once we have the "joinResponse", and possibly reconciled the local state
11512
11481
  // we schedule a fast subscription update for all remote participants
@@ -11733,56 +11702,6 @@ class Call {
11733
11702
  this.stopReportingStatsFor = (sessionId) => {
11734
11703
  return this.statsReporter?.stopReportingStatsFor(sessionId);
11735
11704
  };
11736
- /**
11737
- * Sets the used audio output device (`audioOutputDeviceId` of the [`localParticipant$`](./StreamVideoClient.md/#readonlystatestore).
11738
- *
11739
- * This method only stores the selection, if you're using custom UI components, you'll have to implement the audio switching, for more information see: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/sinkId.
11740
- *
11741
- *
11742
- * @param deviceId the selected device, `undefined` means the user wants to use the system's default audio output
11743
- *
11744
- * @deprecated use `call.speaker` instead
11745
- */
11746
- this.setAudioOutputDevice = (deviceId) => {
11747
- if (!this.sfuClient)
11748
- return;
11749
- this.state.updateParticipant(this.sfuClient.sessionId, {
11750
- audioOutputDeviceId: deviceId,
11751
- });
11752
- };
11753
- /**
11754
- * Sets the `audioDeviceId` property of the [`localParticipant$`](./StreamVideoClient.md/#readonlystatestore)).
11755
- *
11756
- * This method only stores the selection, if you want to start publishing a media stream call the [`publishAudioStream` method](#publishaudiostream) that will set `audioDeviceId` as well.
11757
- *
11758
- *
11759
- * @param deviceId the selected device, pass `undefined` to clear the device selection
11760
- *
11761
- * @deprecated use call.microphone.select
11762
- */
11763
- this.setAudioDevice = (deviceId) => {
11764
- if (!this.sfuClient)
11765
- return;
11766
- this.state.updateParticipant(this.sfuClient.sessionId, {
11767
- audioDeviceId: deviceId,
11768
- });
11769
- };
11770
- /**
11771
- * Sets the `videoDeviceId` property of the [`localParticipant$`](./StreamVideoClient.md/#readonlystatestore).
11772
- *
11773
- * This method only stores the selection, if you want to start publishing a media stream call the [`publishVideoStream` method](#publishvideostream) that will set `videoDeviceId` as well.
11774
- *
11775
- * @param deviceId the selected device, pass `undefined` to clear the device selection
11776
- *
11777
- * @deprecated use call.camera.select
11778
- */
11779
- this.setVideoDevice = (deviceId) => {
11780
- if (!this.sfuClient)
11781
- return;
11782
- this.state.updateParticipant(this.sfuClient.sessionId, {
11783
- videoDeviceId: deviceId,
11784
- });
11785
- };
11786
11705
  /**
11787
11706
  * Resets the last sent reaction for the user holding the given `sessionId`. This is a local action, it won't reset the reaction on the backend.
11788
11707
  *
@@ -12129,6 +12048,10 @@ class Call {
12129
12048
  this.sendCustomEvent = async (payload) => {
12130
12049
  return this.streamClient.post(`${this.streamClientBasePath}/event`, { custom: payload });
12131
12050
  };
12051
+ this.applyDeviceConfig = () => {
12052
+ this.initCamera({ setStatus: false });
12053
+ this.initMic({ setStatus: false });
12054
+ };
12132
12055
  /**
12133
12056
  * Will begin tracking the given element for visibility changes within the
12134
12057
  * configured viewport element (`call.setViewport`).
@@ -12374,7 +12297,7 @@ class Call {
12374
12297
  get isCreatedByMe() {
12375
12298
  return this.state.createdBy?.id === this.currentUserId;
12376
12299
  }
12377
- async initCamera() {
12300
+ async initCamera(options) {
12378
12301
  // Wait for any in progress camera operation
12379
12302
  if (this.camera.enablePromise) {
12380
12303
  await this.camera.enablePromise;
@@ -12400,19 +12323,21 @@ class Call {
12400
12323
  if (targetResolution) {
12401
12324
  await this.camera.selectTargetResolution(targetResolution);
12402
12325
  }
12403
- // Publish already that was set before we joined
12404
- if (this.camera.state.status === 'enabled' &&
12405
- this.camera.state.mediaStream &&
12406
- !this.publisher?.isPublishing(TrackType.VIDEO)) {
12407
- await this.publishVideoStream(this.camera.state.mediaStream);
12408
- }
12409
- // Start camera if backend config speicifies, and there is no local setting
12410
- if (this.camera.state.status === undefined &&
12411
- this.state.settings?.video.camera_default_on) {
12412
- await this.camera.enable();
12326
+ if (options.setStatus) {
12327
+ // Publish already that was set before we joined
12328
+ if (this.camera.state.status === 'enabled' &&
12329
+ this.camera.state.mediaStream &&
12330
+ !this.publisher?.isPublishing(TrackType.VIDEO)) {
12331
+ await this.publishVideoStream(this.camera.state.mediaStream);
12332
+ }
12333
+ // Start camera if backend config speicifies, and there is no local setting
12334
+ if (this.camera.state.status === undefined &&
12335
+ this.state.settings?.video.camera_default_on) {
12336
+ await this.camera.enable();
12337
+ }
12413
12338
  }
12414
12339
  }
12415
- async initMic() {
12340
+ async initMic(options) {
12416
12341
  // Wait for any in progress mic operation
12417
12342
  if (this.microphone.enablePromise) {
12418
12343
  await this.microphone.enablePromise;
@@ -12424,16 +12349,18 @@ class Call {
12424
12349
  !this.permissionsContext.hasPermission('send-audio')) {
12425
12350
  return;
12426
12351
  }
12427
- // Publish media stream that was set before we joined
12428
- if (this.microphone.state.status === 'enabled' &&
12429
- this.microphone.state.mediaStream &&
12430
- !this.publisher?.isPublishing(TrackType.AUDIO)) {
12431
- await this.publishAudioStream(this.microphone.state.mediaStream);
12432
- }
12433
- // Start mic if backend config specifies, and there is no local setting
12434
- if (this.microphone.state.status === undefined &&
12435
- this.state.settings?.audio.mic_default_on) {
12436
- await this.microphone.enable();
12352
+ if (options.setStatus) {
12353
+ // Publish media stream that was set before we joined
12354
+ if (this.microphone.state.status === 'enabled' &&
12355
+ this.microphone.state.mediaStream &&
12356
+ !this.publisher?.isPublishing(TrackType.AUDIO)) {
12357
+ await this.publishAudioStream(this.microphone.state.mediaStream);
12358
+ }
12359
+ // Start mic if backend config specifies, and there is no local setting
12360
+ if (this.microphone.state.status === undefined &&
12361
+ this.state.settings?.audio.mic_default_on) {
12362
+ await this.microphone.enable();
12363
+ }
12437
12364
  }
12438
12365
  }
12439
12366
  }
@@ -14019,7 +13946,7 @@ class StreamClient {
14019
13946
  });
14020
13947
  };
14021
13948
  this.getUserAgent = () => {
14022
- const version = "0.3.36" ;
13949
+ const version = "0.4.1" ;
14023
13950
  return (this.userAgent ||
14024
13951
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
14025
13952
  };
@@ -14267,6 +14194,7 @@ class StreamVideoClient {
14267
14194
  clientStore: this.writeableStateStore,
14268
14195
  });
14269
14196
  call.state.updateFromCallResponse(c.call);
14197
+ call.applyDeviceConfig();
14270
14198
  if (data.watch) {
14271
14199
  this.writeableStateStore.registerCall(call);
14272
14200
  }
@@ -14553,5 +14481,5 @@ class StreamVideoServerClient extends StreamVideoClient {
14553
14481
  }
14554
14482
  }
14555
14483
 
14556
- export { AudioSettingsDefaultDeviceEnum, AudioSettingsRequestDefaultDeviceEnum, browsers as Browsers, Call, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, CreateDeviceRequestPushProviderEnum, DebounceType, DynascaleManager, ErrorFromResponse, InputMediaDeviceManager, InputMediaDeviceManagerState, LayoutSettingsNameEnum, LayoutSettingsRequestNameEnum, MicrophoneManager, MicrophoneManagerState, OwnCapability, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, 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, paginatedLayoutSortPreset, pinned, publishingAudio, publishingVideo, reactionType, role, screenSharing, setDeviceInfo, setLogLevel, setLogger, setOSInfo, setSdkInfo, speakerLayoutSortPreset, speaking, watchForAddedDefaultAudioDevice, watchForAddedDefaultAudioOutputDevice, watchForAddedDefaultVideoDevice, watchForDisconnectedAudioDevice, watchForDisconnectedAudioOutputDevice, watchForDisconnectedVideoDevice };
14484
+ export { AudioSettingsDefaultDeviceEnum, AudioSettingsRequestDefaultDeviceEnum, browsers as Browsers, Call, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, CreateDeviceRequestPushProviderEnum, DebounceType, DynascaleManager, ErrorFromResponse, InputMediaDeviceManager, InputMediaDeviceManagerState, LayoutSettingsNameEnum, LayoutSettingsRequestNameEnum, MicrophoneManager, MicrophoneManagerState, OwnCapability, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, 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, livestreamOrAudioRoomSortPreset, logLevels, logToConsole, name, noopComparator, paginatedLayoutSortPreset, pinned, publishingAudio, publishingVideo, reactionType, role, screenSharing, setDeviceInfo, setLogLevel, setLogger, setOSInfo, setSdkInfo, speakerLayoutSortPreset, speaking, watchForAddedDefaultAudioDevice, watchForAddedDefaultAudioOutputDevice, watchForAddedDefaultVideoDevice, watchForDisconnectedAudioDevice, watchForDisconnectedAudioOutputDevice, watchForDisconnectedVideoDevice };
14557
14485
  //# sourceMappingURL=index.es.js.map