@stream-io/video-react-sdk 0.4.2 → 0.4.4

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
@@ -252,21 +252,26 @@ const useFloatingUIPreset = ({ placement, strategy, }) => {
252
252
  * @param key the key to use for local storage.
253
253
  */
254
254
  const usePersistDevicePreferences = (key) => {
255
- const { useMicrophoneState, useCameraState, useSpeakerState } = useCallStateHooks();
255
+ const { useMicrophoneState, useCameraState, useSpeakerState, useCallSettings, } = useCallStateHooks();
256
256
  const mic = useMicrophoneState();
257
257
  const camera = useCameraState();
258
258
  const speaker = useSpeakerState();
259
+ const settings = useCallSettings();
259
260
  useEffect(() => {
261
+ if (!settings)
262
+ return;
260
263
  try {
264
+ const hasPreferences = !!window.localStorage.getItem(key);
265
+ const { audio, video } = settings;
261
266
  const defaultDevice = 'default';
262
267
  const preferences = {
263
268
  mic: {
264
269
  selectedDeviceId: mic.selectedDevice || defaultDevice,
265
- muted: mic.isMute,
270
+ muted: hasPreferences ? mic.isMute : !audio.mic_default_on,
266
271
  },
267
272
  camera: {
268
273
  selectedDeviceId: camera.selectedDevice || defaultDevice,
269
- muted: camera.isMute,
274
+ muted: hasPreferences ? camera.isMute : !video.camera_default_on,
270
275
  },
271
276
  speaker: {
272
277
  selectedDeviceId: speaker.selectedDevice || defaultDevice,
@@ -284,6 +289,7 @@ const usePersistDevicePreferences = (key) => {
284
289
  key,
285
290
  mic.isMute,
286
291
  mic.selectedDevice,
292
+ settings,
287
293
  speaker.selectedDevice,
288
294
  ]);
289
295
  };
@@ -294,8 +300,10 @@ const usePersistDevicePreferences = (key) => {
294
300
  */
295
301
  const useApplyDevicePreferences = (key) => {
296
302
  const call = useCall();
303
+ const { useCallSettings } = useCallStateHooks();
304
+ const settings = useCallSettings();
297
305
  useEffect(() => {
298
- if (!call)
306
+ if (!call || !settings)
299
307
  return;
300
308
  const apply = async () => {
301
309
  const initMic = async (setting) => {
@@ -319,22 +327,30 @@ const useApplyDevicePreferences = (key) => {
319
327
  const initSpeaker = (setting) => {
320
328
  call.speaker.select(setting.selectedDeviceId);
321
329
  };
330
+ let preferences = null;
322
331
  try {
323
- const preferences = JSON.parse(window.localStorage.getItem(key));
324
- if (preferences) {
325
- await initMic(preferences.mic);
326
- await initCamera(preferences.camera);
327
- initSpeaker(preferences.speaker);
328
- }
332
+ preferences = JSON.parse(window.localStorage.getItem(key));
329
333
  }
330
334
  catch (err) {
331
335
  console.warn('Failed to load device preferences', err);
332
336
  }
337
+ if (preferences) {
338
+ await initMic(preferences.mic);
339
+ await initCamera(preferences.camera);
340
+ initSpeaker(preferences.speaker);
341
+ }
342
+ else {
343
+ const { audio, video } = settings;
344
+ if (audio.mic_default_on)
345
+ await call.microphone.enable();
346
+ if (video.camera_default_on)
347
+ await call.camera.enable();
348
+ }
333
349
  };
334
350
  apply().catch((err) => {
335
351
  console.warn('Failed to apply device preferences', err);
336
352
  });
337
- }, [call, key]);
353
+ }, [call, key, settings]);
338
354
  };
339
355
  /**
340
356
  * This hook will apply and persist the device preferences from local storage.
@@ -816,8 +832,11 @@ const ScreenShareButton = (props) => {
816
832
  const { useHasOngoingScreenShare, useScreenShareState } = useCallStateHooks();
817
833
  const isSomeoneScreenSharing = useHasOngoingScreenShare();
818
834
  const { hasPermission, requestPermission, isAwaitingPermission } = useRequestPermission(OwnCapability.SCREENSHARE);
819
- const { screenShare, isMute: isScreenSharing } = useScreenShareState();
820
- return (jsx(Restricted, { requiredGrants: [OwnCapability.SCREENSHARE], children: jsx(PermissionNotification, { permission: OwnCapability.SCREENSHARE, isAwaitingApproval: isAwaitingPermission, messageApproved: t('You can now share your screen.'), messageAwaitingApproval: t('Awaiting for an approval to share screen.'), messageRevoked: t('You can no longer share your screen.'), children: jsx(CompositeButton, { active: isSomeoneScreenSharing, caption: caption, children: jsx(IconButton, { icon: isScreenSharing ? 'screen-share-on' : 'screen-share-off', title: t('Share screen'), disabled: !isScreenSharing && isSomeoneScreenSharing, onClick: async () => {
835
+ const { screenShare, isMute: amIScreenSharing } = useScreenShareState();
836
+ const disableScreenShareButton = amIScreenSharing
837
+ ? isSomeoneScreenSharing
838
+ : false;
839
+ return (jsx(Restricted, { requiredGrants: [OwnCapability.SCREENSHARE], children: jsx(PermissionNotification, { permission: OwnCapability.SCREENSHARE, isAwaitingApproval: isAwaitingPermission, messageApproved: t('You can now share your screen.'), messageAwaitingApproval: t('Awaiting for an approval to share screen.'), messageRevoked: t('You can no longer share your screen.'), children: jsx(CompositeButton, { active: isSomeoneScreenSharing, caption: caption, children: jsx(IconButton, { icon: isSomeoneScreenSharing ? 'screen-share-on' : 'screen-share-off', title: t('Share screen'), disabled: disableScreenShareButton, onClick: async () => {
821
840
  if (!hasPermission) {
822
841
  await requestPermission();
823
842
  }
@@ -1482,11 +1501,11 @@ const StreamTheme = ({ as: Component = 'div', className, children, ...props }) =
1482
1501
 
1483
1502
  const DefaultDisabledVideoPreview = () => {
1484
1503
  const { t } = useI18n();
1485
- return jsx("div", { children: t('Video is disabled') });
1504
+ return (jsx("div", { className: "str_video__video-preview__disabled-video-preview", children: t('Video is disabled') }));
1486
1505
  };
1487
1506
  const DefaultNoCameraPreview = () => {
1488
1507
  const { t } = useI18n();
1489
- return jsx("div", { children: t('No camera found') });
1508
+ return (jsx("div", { className: "str_video__video-preview__no-camera-preview", children: t('No camera found') }));
1490
1509
  };
1491
1510
  const VideoPreview = ({ className, mirror = true, DisabledVideoPreview = DefaultDisabledVideoPreview, NoCameraPreview = DefaultNoCameraPreview, StartingCameraPreview = LoadingIndicator, }) => {
1492
1511
  const { useCameraState } = useCallStateHooks();
@@ -2097,7 +2116,7 @@ const VerticalScrollButtons = ({ scrollWrapper, }) => {
2097
2116
  };
2098
2117
  const hasScreenShare = (p) => !!p?.publishedTracks.includes(SfuModels.TrackType.SCREEN_SHARE);
2099
2118
 
2100
- const [major, minor, patch] = ("0.4.2" ).split('.');
2119
+ const [major, minor, patch] = ("0.4.4" ).split('.');
2101
2120
  setSdkInfo({
2102
2121
  type: SfuModels.SdkType.REACT,
2103
2122
  major,