@stream-io/video-react-sdk 1.7.24 → 1.7.26

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.
@@ -1,8 +1,9 @@
1
- export type DeviceSelectorAudioInputProps = {
1
+ import { PropsWithErrorHandler } from '../../utilities/callControlHandler';
2
+ export type DeviceSelectorAudioInputProps = PropsWithErrorHandler<{
2
3
  title?: string;
3
4
  visualType?: 'list' | 'dropdown';
4
- };
5
- export declare const DeviceSelectorAudioInput: ({ title, visualType, }: DeviceSelectorAudioInputProps) => import("react/jsx-runtime").JSX.Element;
5
+ }>;
6
+ export declare const DeviceSelectorAudioInput: (props: DeviceSelectorAudioInputProps) => import("react/jsx-runtime").JSX.Element;
6
7
  export type DeviceSelectorAudioOutputProps = {
7
8
  title?: string;
8
9
  visualType?: 'list' | 'dropdown';
@@ -1,5 +1,6 @@
1
- export type DeviceSelectorVideoProps = {
1
+ import { PropsWithErrorHandler } from '../../utilities/callControlHandler';
2
+ export type DeviceSelectorVideoProps = PropsWithErrorHandler<{
2
3
  title?: string;
3
4
  visualType?: 'list' | 'dropdown';
4
- };
5
- export declare const DeviceSelectorVideo: ({ title, visualType, }: DeviceSelectorVideoProps) => import("react/jsx-runtime").JSX.Element;
5
+ }>;
6
+ export declare const DeviceSelectorVideo: (props: DeviceSelectorVideoProps) => import("react/jsx-runtime").JSX.Element;
@@ -13,4 +13,4 @@ export type PropsWithErrorHandler<T = unknown> = T & {
13
13
  * @param props component props, including the onError callback
14
14
  * @param handler event handler to wrap
15
15
  */
16
- export declare const createCallControlHandler: (props: PropsWithErrorHandler, handler: () => Promise<void>) => (() => Promise<void>);
16
+ export declare const createCallControlHandler: <P extends unknown[]>(props: PropsWithErrorHandler, handler: (...args: P) => Promise<void>) => (() => Promise<void>);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-io/video-react-sdk",
3
- "version": "1.7.24",
3
+ "version": "1.7.26",
4
4
  "packageManager": "yarn@3.2.4",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.es.js",
@@ -32,9 +32,9 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "@floating-ui/react": "^0.26.24",
35
- "@stream-io/video-client": "1.11.8",
35
+ "@stream-io/video-client": "1.11.10",
36
36
  "@stream-io/video-filters-web": "0.1.6",
37
- "@stream-io/video-react-bindings": "1.2.2",
37
+ "@stream-io/video-react-bindings": "1.2.4",
38
38
  "chart.js": "^4.4.4",
39
39
  "clsx": "^2.0.0",
40
40
  "react-chartjs-2": "^5.2.0"
@@ -1,28 +1,35 @@
1
1
  import { useCallStateHooks } from '@stream-io/video-react-bindings';
2
2
  import { DeviceSelector } from './DeviceSelector';
3
+ import {
4
+ createCallControlHandler,
5
+ PropsWithErrorHandler,
6
+ } from '../../utilities/callControlHandler';
3
7
 
4
- export type DeviceSelectorAudioInputProps = {
8
+ export type DeviceSelectorAudioInputProps = PropsWithErrorHandler<{
5
9
  title?: string;
6
10
  visualType?: 'list' | 'dropdown';
7
- };
11
+ }>;
8
12
 
9
- export const DeviceSelectorAudioInput = ({
10
- title,
11
- visualType,
12
- }: DeviceSelectorAudioInputProps) => {
13
+ export const DeviceSelectorAudioInput = (
14
+ props: DeviceSelectorAudioInputProps,
15
+ ) => {
13
16
  const { useMicrophoneState } = useCallStateHooks();
14
17
  const { microphone, selectedDevice, devices } = useMicrophoneState();
18
+ const handleChange = createCallControlHandler(
19
+ props,
20
+ async (deviceId: string) => {
21
+ await microphone.select(deviceId);
22
+ },
23
+ );
15
24
 
16
25
  return (
17
26
  <DeviceSelector
18
27
  devices={devices || []}
19
28
  selectedDeviceId={selectedDevice}
20
29
  type="audioinput"
21
- onChange={async (deviceId) => {
22
- await microphone.select(deviceId);
23
- }}
24
- title={title}
25
- visualType={visualType}
30
+ onChange={handleChange}
31
+ title={props.title}
32
+ visualType={props.visualType}
26
33
  icon="mic"
27
34
  />
28
35
  );
@@ -1,28 +1,33 @@
1
+ import {
2
+ createCallControlHandler,
3
+ PropsWithErrorHandler,
4
+ } from '../../utilities/callControlHandler';
1
5
  import { DeviceSelector } from './DeviceSelector';
2
6
  import { useCallStateHooks } from '@stream-io/video-react-bindings';
3
7
 
4
- export type DeviceSelectorVideoProps = {
8
+ export type DeviceSelectorVideoProps = PropsWithErrorHandler<{
5
9
  title?: string;
6
10
  visualType?: 'list' | 'dropdown';
7
- };
11
+ }>;
8
12
 
9
- export const DeviceSelectorVideo = ({
10
- title,
11
- visualType,
12
- }: DeviceSelectorVideoProps) => {
13
+ export const DeviceSelectorVideo = (props: DeviceSelectorVideoProps) => {
13
14
  const { useCameraState } = useCallStateHooks();
14
15
  const { camera, devices, selectedDevice } = useCameraState();
16
+ const handleChange = createCallControlHandler(
17
+ props,
18
+ async (deviceId: string) => {
19
+ await camera.select(deviceId);
20
+ },
21
+ );
15
22
 
16
23
  return (
17
24
  <DeviceSelector
18
25
  devices={devices || []}
19
26
  type="videoinput"
20
27
  selectedDeviceId={selectedDevice}
21
- onChange={async (deviceId) => {
22
- await camera.select(deviceId);
23
- }}
24
- title={title}
25
- visualType={visualType}
28
+ onChange={handleChange}
29
+ title={props.title}
30
+ visualType={props.visualType}
26
31
  icon="camera"
27
32
  />
28
33
  );
@@ -68,8 +68,14 @@ const usePersistDevicePreferences = (
68
68
  *
69
69
  * @param key the key to use for local storage.
70
70
  */
71
- const useApplyDevicePreferences = (key: string, onApplied: () => void) => {
71
+ const useApplyDevicePreferences = (
72
+ key: string,
73
+ onWillApply: () => void,
74
+ onApplied: () => void,
75
+ ) => {
72
76
  const call = useCall();
77
+ const onWillApplyRef = useRef(onWillApply);
78
+ onWillApplyRef.current = onWillApply;
73
79
  const onAppliedRef = useRef(onApplied);
74
80
  onAppliedRef.current = onApplied;
75
81
  useEffect(() => {
@@ -115,17 +121,22 @@ const useApplyDevicePreferences = (key: string, onApplied: () => void) => {
115
121
  console.warn('Failed to load device preferences', err);
116
122
  }
117
123
  if (preferences) {
118
- await initMic(preferences.mic);
119
- await initCamera(preferences.camera);
124
+ await initMic(preferences.mic).catch((err) => {
125
+ console.warn('Failed to apply microphone preferences', err);
126
+ });
127
+ await initCamera(preferences.camera).catch((err) => {
128
+ console.warn('Failed to apply camera preferences', err);
129
+ });
120
130
  initSpeaker(preferences.speaker);
121
131
  }
122
132
  };
123
133
 
134
+ onWillApplyRef.current();
124
135
  apply()
125
- .then(() => onAppliedRef.current())
126
136
  .catch((err) => {
127
137
  console.warn('Failed to apply device preferences', err);
128
- });
138
+ })
139
+ .then(() => onAppliedRef.current());
129
140
 
130
141
  return () => {
131
142
  cancel = true;
@@ -142,7 +153,11 @@ export const usePersistedDevicePreferences = (
142
153
  key: string = '@stream-io/device-preferences',
143
154
  ) => {
144
155
  const shouldPersistRef = useRef(false);
145
- useApplyDevicePreferences(key, () => (shouldPersistRef.current = true));
156
+ useApplyDevicePreferences(
157
+ key,
158
+ () => (shouldPersistRef.current = false),
159
+ () => (shouldPersistRef.current = true),
160
+ );
146
161
  usePersistDevicePreferences(key, shouldPersistRef);
147
162
  };
148
163
 
@@ -16,15 +16,15 @@ export type PropsWithErrorHandler<T = unknown> = T & {
16
16
  * @param props component props, including the onError callback
17
17
  * @param handler event handler to wrap
18
18
  */
19
- export const createCallControlHandler = (
19
+ export const createCallControlHandler = <P extends unknown[]>(
20
20
  props: PropsWithErrorHandler,
21
- handler: () => Promise<void>,
21
+ handler: (...args: P) => Promise<void>,
22
22
  ): (() => Promise<void>) => {
23
23
  const logger = getLogger(['react-sdk']);
24
24
 
25
- return async () => {
25
+ return async (...args: P) => {
26
26
  try {
27
- await handler();
27
+ await handler(...args);
28
28
  } catch (error) {
29
29
  if (props.onError) {
30
30
  props.onError(error);