@stream-io/video-react-sdk 1.7.13 → 1.7.15
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 +13 -0
- package/dist/index.cjs.js +28 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +29 -7
- package/dist/index.es.js.map +1 -1
- package/package.json +3 -3
- package/src/hooks/usePersistedDevicePreferences.ts +29 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/video-react-sdk",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.15",
|
|
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.
|
|
35
|
+
"@stream-io/video-client": "1.11.0",
|
|
36
36
|
"@stream-io/video-filters-web": "0.1.6",
|
|
37
|
-
"@stream-io/video-react-bindings": "1.1.
|
|
37
|
+
"@stream-io/video-react-bindings": "1.1.17",
|
|
38
38
|
"chart.js": "^4.4.4",
|
|
39
39
|
"clsx": "^2.0.0",
|
|
40
40
|
"react-chartjs-2": "^5.2.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { type MutableRefObject, useEffect, useRef } from 'react';
|
|
2
2
|
import { CallingState } from '@stream-io/video-client';
|
|
3
3
|
import { useCall, useCallStateHooks } from '@stream-io/video-react-bindings';
|
|
4
4
|
|
|
@@ -18,7 +18,10 @@ const defaultDevice = 'default';
|
|
|
18
18
|
*
|
|
19
19
|
* @param key the key to use for local storage.
|
|
20
20
|
*/
|
|
21
|
-
const usePersistDevicePreferences = (
|
|
21
|
+
const usePersistDevicePreferences = (
|
|
22
|
+
key: string,
|
|
23
|
+
shouldPersistRef: MutableRefObject<boolean>,
|
|
24
|
+
) => {
|
|
22
25
|
const { useMicrophoneState, useCameraState, useSpeakerState } =
|
|
23
26
|
useCallStateHooks();
|
|
24
27
|
const call = useCall();
|
|
@@ -26,6 +29,7 @@ const usePersistDevicePreferences = (key: string) => {
|
|
|
26
29
|
const camera = useCameraState();
|
|
27
30
|
const speaker = useSpeakerState();
|
|
28
31
|
useEffect(() => {
|
|
32
|
+
if (!shouldPersistRef.current) return;
|
|
29
33
|
if (!call) return;
|
|
30
34
|
if (call.state.callingState === CallingState.LEFT) return;
|
|
31
35
|
try {
|
|
@@ -55,6 +59,7 @@ const usePersistDevicePreferences = (key: string) => {
|
|
|
55
59
|
mic.isMute,
|
|
56
60
|
mic.selectedDevice,
|
|
57
61
|
speaker.selectedDevice,
|
|
62
|
+
shouldPersistRef,
|
|
58
63
|
]);
|
|
59
64
|
};
|
|
60
65
|
|
|
@@ -63,15 +68,21 @@ const usePersistDevicePreferences = (key: string) => {
|
|
|
63
68
|
*
|
|
64
69
|
* @param key the key to use for local storage.
|
|
65
70
|
*/
|
|
66
|
-
const useApplyDevicePreferences = (key: string) => {
|
|
71
|
+
const useApplyDevicePreferences = (key: string, onApplied: () => void) => {
|
|
67
72
|
const call = useCall();
|
|
73
|
+
const onAppliedRef = useRef(onApplied);
|
|
74
|
+
onAppliedRef.current = onApplied;
|
|
68
75
|
useEffect(() => {
|
|
69
76
|
if (!call) return;
|
|
70
77
|
if (call.state.callingState === CallingState.LEFT) return;
|
|
71
78
|
|
|
79
|
+
let cancel = false;
|
|
80
|
+
|
|
72
81
|
const apply = async () => {
|
|
73
82
|
const initMic = async (setting: LocalDevicePreference) => {
|
|
83
|
+
if (cancel) return;
|
|
74
84
|
await call.microphone.select(parseDeviceId(setting.selectedDeviceId));
|
|
85
|
+
if (cancel) return;
|
|
75
86
|
if (setting.muted) {
|
|
76
87
|
await call.microphone.disable();
|
|
77
88
|
} else {
|
|
@@ -80,7 +91,9 @@ const useApplyDevicePreferences = (key: string) => {
|
|
|
80
91
|
};
|
|
81
92
|
|
|
82
93
|
const initCamera = async (setting: LocalDevicePreference) => {
|
|
94
|
+
if (cancel) return;
|
|
83
95
|
await call.camera.select(parseDeviceId(setting.selectedDeviceId));
|
|
96
|
+
if (cancel) return;
|
|
84
97
|
if (setting.muted) {
|
|
85
98
|
await call.camera.disable();
|
|
86
99
|
} else {
|
|
@@ -89,6 +102,7 @@ const useApplyDevicePreferences = (key: string) => {
|
|
|
89
102
|
};
|
|
90
103
|
|
|
91
104
|
const initSpeaker = (setting: LocalDevicePreference) => {
|
|
105
|
+
if (cancel) return;
|
|
92
106
|
call.speaker.select(parseDeviceId(setting.selectedDeviceId) ?? '');
|
|
93
107
|
};
|
|
94
108
|
|
|
@@ -107,9 +121,15 @@ const useApplyDevicePreferences = (key: string) => {
|
|
|
107
121
|
}
|
|
108
122
|
};
|
|
109
123
|
|
|
110
|
-
apply()
|
|
111
|
-
|
|
112
|
-
|
|
124
|
+
apply()
|
|
125
|
+
.then(() => onAppliedRef.current())
|
|
126
|
+
.catch((err) => {
|
|
127
|
+
console.warn('Failed to apply device preferences', err);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return () => {
|
|
131
|
+
cancel = true;
|
|
132
|
+
};
|
|
113
133
|
}, [call, key]);
|
|
114
134
|
};
|
|
115
135
|
|
|
@@ -121,8 +141,9 @@ const useApplyDevicePreferences = (key: string) => {
|
|
|
121
141
|
export const usePersistedDevicePreferences = (
|
|
122
142
|
key: string = '@stream-io/device-preferences',
|
|
123
143
|
) => {
|
|
124
|
-
|
|
125
|
-
|
|
144
|
+
const shouldPersistRef = useRef(false);
|
|
145
|
+
useApplyDevicePreferences(key, () => (shouldPersistRef.current = true));
|
|
146
|
+
usePersistDevicePreferences(key, shouldPersistRef);
|
|
126
147
|
};
|
|
127
148
|
|
|
128
149
|
const parseDeviceId = (deviceId: string) =>
|