@stream-io/video-react-sdk 1.31.0 → 1.31.2
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/CHANGELOG.md +18 -0
- package/dist/index.cjs.js +24 -87
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +25 -88
- package/dist/index.es.js.map +1 -1
- package/package.json +3 -3
- package/src/hooks/usePersistedDevicePreferences.ts +28 -96
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/video-react-sdk",
|
|
3
|
-
"version": "1.31.
|
|
3
|
+
"version": "1.31.2",
|
|
4
4
|
"main": "./dist/index.cjs.js",
|
|
5
5
|
"module": "./dist/index.es.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@floating-ui/react": "^0.27.6",
|
|
34
|
-
"@stream-io/video-client": "1.40.
|
|
34
|
+
"@stream-io/video-client": "1.40.2",
|
|
35
35
|
"@stream-io/video-filters-web": "0.7.0",
|
|
36
|
-
"@stream-io/video-react-bindings": "1.12.
|
|
36
|
+
"@stream-io/video-react-bindings": "1.12.9",
|
|
37
37
|
"chart.js": "^4.4.4",
|
|
38
38
|
"clsx": "^2.0.0",
|
|
39
39
|
"react-chartjs-2": "^5.3.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { CallingState, InputDeviceStatus } from '@stream-io/video-client';
|
|
3
|
-
import { useCallStateHooks } from '@stream-io/video-react-bindings';
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Call, CallingState, InputDeviceStatus } from '@stream-io/video-client';
|
|
3
|
+
import { useCall, useCallStateHooks } from '@stream-io/video-react-bindings';
|
|
4
4
|
|
|
5
5
|
export type LocalDevicePreference = {
|
|
6
6
|
selectedDeviceId: string;
|
|
@@ -59,6 +59,31 @@ export const usePersistedDevicePreferences = (
|
|
|
59
59
|
'idle' | 'applying' | 'applied'
|
|
60
60
|
>('idle');
|
|
61
61
|
|
|
62
|
+
const call = useCall();
|
|
63
|
+
|
|
64
|
+
// Set deferServerDefaults flag synchronously during render.
|
|
65
|
+
// Please ensure the flag is set BEFORE any call.get() or call.getOrCreate()
|
|
66
|
+
// is called, preventing server defaults from overriding user preferences.
|
|
67
|
+
const deferredCallRef = useRef<Call | null>(null);
|
|
68
|
+
if (call && deferredCallRef.current !== call) {
|
|
69
|
+
call.camera.deferServerDefaults = true;
|
|
70
|
+
call.microphone.deferServerDefaults = true;
|
|
71
|
+
deferredCallRef.current = call;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Cleanup: reset the flag when the component unmounts or call changes.
|
|
75
|
+
// This allows server defaults to apply if the hook is no longer used.
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
return () => {
|
|
78
|
+
const currentCall = deferredCallRef.current;
|
|
79
|
+
if (currentCall) {
|
|
80
|
+
currentCall.camera.deferServerDefaults = false;
|
|
81
|
+
currentCall.microphone.deferServerDefaults = false;
|
|
82
|
+
deferredCallRef.current = null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}, [call]);
|
|
86
|
+
|
|
62
87
|
// when the camera is disabled on call type level, we should discard
|
|
63
88
|
// any stored camera preferences.
|
|
64
89
|
const cameraDevices = settings?.video?.enabled ? cameraState.devices : false;
|
|
@@ -178,99 +203,6 @@ export const usePersistedDevicePreferences = (
|
|
|
178
203
|
);
|
|
179
204
|
};
|
|
180
205
|
|
|
181
|
-
// const usePersistedDevicePreference = <K extends DeviceKey>(
|
|
182
|
-
// key: string,
|
|
183
|
-
// deviceKey: K,
|
|
184
|
-
// state: DeviceState<K>,
|
|
185
|
-
// defaultMuted?: boolean,
|
|
186
|
-
// ): void => {
|
|
187
|
-
// const { useCallCallingState } = useCallStateHooks();
|
|
188
|
-
// const callingState = useCallCallingState();
|
|
189
|
-
// const [applyingState, setApplyingState] = useState<
|
|
190
|
-
// 'idle' | 'applying' | 'applied'
|
|
191
|
-
// >('idle');
|
|
192
|
-
// const manager = state[deviceKey];
|
|
193
|
-
|
|
194
|
-
// useEffect(
|
|
195
|
-
// function apply() {
|
|
196
|
-
// if (
|
|
197
|
-
// callingState === CallingState.LEFT ||
|
|
198
|
-
// !state.devices?.length ||
|
|
199
|
-
// typeof defaultMuted !== 'boolean' ||
|
|
200
|
-
// applyingState !== 'idle'
|
|
201
|
-
// ) {
|
|
202
|
-
// return;
|
|
203
|
-
// }
|
|
204
|
-
|
|
205
|
-
// const preferences = parseLocalDevicePreferences(key);
|
|
206
|
-
// const preference = preferences[deviceKey];
|
|
207
|
-
|
|
208
|
-
// setApplyingState('applying');
|
|
209
|
-
|
|
210
|
-
// if (!manager.state.selectedDevice) {
|
|
211
|
-
// const applyPromise = preference
|
|
212
|
-
// ? applyLocalDevicePreference(
|
|
213
|
-
// manager,
|
|
214
|
-
// [preference].flat(),
|
|
215
|
-
// state.devices,
|
|
216
|
-
// )
|
|
217
|
-
// : applyMutedState(manager, defaultMuted);
|
|
218
|
-
|
|
219
|
-
// applyPromise
|
|
220
|
-
// .catch((err) => {
|
|
221
|
-
// console.warn(
|
|
222
|
-
// `Failed to apply ${deviceKey} device preferences`,
|
|
223
|
-
// err,
|
|
224
|
-
// );
|
|
225
|
-
// })
|
|
226
|
-
// .finally(() => setApplyingState('applied'));
|
|
227
|
-
// } else {
|
|
228
|
-
// setApplyingState('applied');
|
|
229
|
-
// }
|
|
230
|
-
// },
|
|
231
|
-
// [
|
|
232
|
-
// applyingState,
|
|
233
|
-
// callingState,
|
|
234
|
-
// defaultMuted,
|
|
235
|
-
// deviceKey,
|
|
236
|
-
// key,
|
|
237
|
-
// manager,
|
|
238
|
-
// state.devices,
|
|
239
|
-
// ],
|
|
240
|
-
// );
|
|
241
|
-
|
|
242
|
-
// useEffect(
|
|
243
|
-
// function persist() {
|
|
244
|
-
// if (
|
|
245
|
-
// callingState === CallingState.LEFT ||
|
|
246
|
-
// !state.devices?.length ||
|
|
247
|
-
// applyingState !== 'applied'
|
|
248
|
-
// ) {
|
|
249
|
-
// return;
|
|
250
|
-
// }
|
|
251
|
-
|
|
252
|
-
// try {
|
|
253
|
-
// patchLocalDevicePreference(key, deviceKey, {
|
|
254
|
-
// devices: state.devices,
|
|
255
|
-
// selectedDevice: state.selectedDevice,
|
|
256
|
-
// isMute: state.isMute,
|
|
257
|
-
// });
|
|
258
|
-
// } catch (err) {
|
|
259
|
-
// console.warn(`Failed to save ${deviceKey} device preferences`, err);
|
|
260
|
-
// }
|
|
261
|
-
// },
|
|
262
|
-
// [
|
|
263
|
-
// applyingState,
|
|
264
|
-
// callingState,
|
|
265
|
-
// deviceKey,
|
|
266
|
-
// key,
|
|
267
|
-
// state.devices,
|
|
268
|
-
// state.isMute,
|
|
269
|
-
// state.selectedDevice,
|
|
270
|
-
// ],
|
|
271
|
-
// );
|
|
272
|
-
// };
|
|
273
|
-
|
|
274
206
|
const parseLocalDevicePreferences = (key: string): LocalDevicePreferences => {
|
|
275
207
|
const preferencesStr = window.localStorage.getItem(key);
|
|
276
208
|
let preferences: LocalDevicePreferences = {};
|