@stream-io/video-react-native-sdk 1.32.3 → 1.33.0

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/commonjs/components/Participant/ParticipantView/ParticipantLabel.js +10 -1
  3. package/dist/commonjs/components/Participant/ParticipantView/ParticipantLabel.js.map +1 -1
  4. package/dist/commonjs/contexts/BackgroundFilters.js +50 -9
  5. package/dist/commonjs/contexts/BackgroundFilters.js.map +1 -1
  6. package/dist/commonjs/hooks/index.js +0 -11
  7. package/dist/commonjs/hooks/index.js.map +1 -1
  8. package/dist/commonjs/utils/StreamVideoRN/index.js +5 -3
  9. package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
  10. package/dist/commonjs/utils/internal/registerSDKGlobals.js +13 -0
  11. package/dist/commonjs/utils/internal/registerSDKGlobals.js.map +1 -1
  12. package/dist/commonjs/utils/push/setupCallingExpEvents.js +4 -19
  13. package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +1 -1
  14. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js +1 -6
  15. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js.map +1 -1
  16. package/dist/commonjs/version.js +1 -1
  17. package/dist/module/components/Participant/ParticipantView/ParticipantLabel.js +12 -3
  18. package/dist/module/components/Participant/ParticipantView/ParticipantLabel.js.map +1 -1
  19. package/dist/module/contexts/BackgroundFilters.js +51 -10
  20. package/dist/module/contexts/BackgroundFilters.js.map +1 -1
  21. package/dist/module/hooks/index.js +0 -1
  22. package/dist/module/hooks/index.js.map +1 -1
  23. package/dist/module/utils/StreamVideoRN/index.js +5 -3
  24. package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
  25. package/dist/module/utils/internal/registerSDKGlobals.js +13 -0
  26. package/dist/module/utils/internal/registerSDKGlobals.js.map +1 -1
  27. package/dist/module/utils/push/setupCallingExpEvents.js +4 -19
  28. package/dist/module/utils/push/setupCallingExpEvents.js.map +1 -1
  29. package/dist/module/utils/push/setupIosVoipPushEvents.js +1 -6
  30. package/dist/module/utils/push/setupIosVoipPushEvents.js.map +1 -1
  31. package/dist/module/version.js +1 -1
  32. package/dist/typescript/components/Participant/ParticipantView/ParticipantLabel.d.ts.map +1 -1
  33. package/dist/typescript/contexts/BackgroundFilters.d.ts.map +1 -1
  34. package/dist/typescript/hooks/index.d.ts +0 -1
  35. package/dist/typescript/hooks/index.d.ts.map +1 -1
  36. package/dist/typescript/utils/internal/registerSDKGlobals.d.ts.map +1 -1
  37. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +1 -1
  38. package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
  39. package/dist/typescript/version.d.ts +1 -1
  40. package/package.json +6 -6
  41. package/src/components/Participant/ParticipantView/ParticipantLabel.tsx +24 -2
  42. package/src/contexts/BackgroundFilters.tsx +55 -9
  43. package/src/hooks/index.ts +0 -1
  44. package/src/utils/StreamVideoRN/index.ts +5 -5
  45. package/src/utils/internal/registerSDKGlobals.ts +13 -0
  46. package/src/utils/push/setupCallingExpEvents.ts +8 -22
  47. package/src/utils/push/setupIosVoipPushEvents.ts +2 -13
  48. package/src/version.ts +1 -1
  49. package/dist/commonjs/hooks/useSpeechDetection.js +0 -39
  50. package/dist/commonjs/hooks/useSpeechDetection.js.map +0 -1
  51. package/dist/module/hooks/useSpeechDetection.js +0 -34
  52. package/dist/module/hooks/useSpeechDetection.js.map +0 -1
  53. package/dist/typescript/hooks/useSpeechDetection.d.ts +0 -8
  54. package/dist/typescript/hooks/useSpeechDetection.d.ts.map +0 -1
  55. package/src/hooks/useSpeechDetection.ts +0 -35
@@ -2,6 +2,7 @@ import React, {
2
2
  type PropsWithChildren,
3
3
  useCallback,
4
4
  useContext,
5
+ useEffect,
5
6
  useMemo,
6
7
  useRef,
7
8
  useState,
@@ -76,6 +77,10 @@ export const BackgroundFiltersProvider = ({ children }: PropsWithChildren) => {
76
77
  const isBackgroundBlurRegisteredRef = useRef(false);
77
78
  const isVideoBlurRegisteredRef = useRef(false);
78
79
  const registeredImageFiltersSetRef = useRef(new Set<string>());
80
+ // The currently applied native filter name. Used to reapply on track
81
+ // replacement, and as a staleness signal so a later apply/disable can
82
+ // invalidate an in-flight apply() call.
83
+ const lastAppliedFilterNameRef = useRef<string | null>(null);
79
84
 
80
85
  const [currentBackgroundFilter, setCurrentBackgroundFilter] =
81
86
  useState<CurrentBackgroundFilter>();
@@ -85,16 +90,19 @@ export const BackgroundFiltersProvider = ({ children }: PropsWithChildren) => {
85
90
  if (!isSupported) {
86
91
  return;
87
92
  }
88
- if (!isBackgroundBlurRegisteredRef.current) {
89
- await videoFiltersModule?.registerBackgroundBlurVideoFilters();
90
- isBackgroundBlurRegisteredRef.current = true;
91
- }
92
93
  let filterName = 'BackgroundBlurMedium';
93
94
  if (blurIntensity === 'heavy') {
94
95
  filterName = 'BackgroundBlurHeavy';
95
96
  } else if (blurIntensity === 'light') {
96
97
  filterName = 'BackgroundBlurLight';
97
98
  }
99
+ // Set before awaiting so a later apply/disable can mark this call stale.
100
+ lastAppliedFilterNameRef.current = filterName;
101
+ if (!isBackgroundBlurRegisteredRef.current) {
102
+ await videoFiltersModule?.registerBackgroundBlurVideoFilters();
103
+ if (lastAppliedFilterNameRef.current !== filterName) return;
104
+ isBackgroundBlurRegisteredRef.current = true;
105
+ }
98
106
  call?.tracer.trace('backgroundFilters.apply', filterName);
99
107
  (call?.camera.state.mediaStream as MediaStream | undefined)
100
108
  ?.getVideoTracks()
@@ -111,16 +119,18 @@ export const BackgroundFiltersProvider = ({ children }: PropsWithChildren) => {
111
119
  if (!isSupported) {
112
120
  return;
113
121
  }
114
- if (!isVideoBlurRegisteredRef.current) {
115
- await videoFiltersModule?.registerBlurVideoFilters();
116
- isVideoBlurRegisteredRef.current = true;
117
- }
118
122
  let filterName = 'BlurMedium';
119
123
  if (blurIntensity === 'heavy') {
120
124
  filterName = 'BlurHeavy';
121
125
  } else if (blurIntensity === 'light') {
122
126
  filterName = 'BlurLight';
123
127
  }
128
+ lastAppliedFilterNameRef.current = filterName;
129
+ if (!isVideoBlurRegisteredRef.current) {
130
+ await videoFiltersModule?.registerBlurVideoFilters();
131
+ if (lastAppliedFilterNameRef.current !== filterName) return;
132
+ isVideoBlurRegisteredRef.current = true;
133
+ }
124
134
  call?.tracer.trace('videoFilters.apply', filterName);
125
135
  (call?.camera.state.mediaStream as MediaStream | undefined)
126
136
  ?.getVideoTracks()
@@ -139,12 +149,14 @@ export const BackgroundFiltersProvider = ({ children }: PropsWithChildren) => {
139
149
  }
140
150
  const source = Image.resolveAssetSource(imageSource);
141
151
  const imageUri = source.uri;
152
+ const filterName = `VirtualBackground-${imageUri}`;
153
+ lastAppliedFilterNameRef.current = filterName;
142
154
  const registeredImageFiltersSet = registeredImageFiltersSetRef.current;
143
155
  if (!registeredImageFiltersSet.has(imageUri)) {
144
156
  await videoFiltersModule?.registerVirtualBackgroundFilter(imageSource);
157
+ if (lastAppliedFilterNameRef.current !== filterName) return;
145
158
  registeredImageFiltersSetRef.current.add(imageUri);
146
159
  }
147
- const filterName = `VirtualBackground-${imageUri}`;
148
160
  call?.tracer.trace('backgroundFilters.apply', filterName);
149
161
  (call?.camera.state.mediaStream as MediaStream | undefined)
150
162
  ?.getVideoTracks()
@@ -161,6 +173,8 @@ export const BackgroundFiltersProvider = ({ children }: PropsWithChildren) => {
161
173
  return;
162
174
  }
163
175
  call?.tracer.trace('backgroundFilters.disableAll', null);
176
+ // Clearing the ref invalidates any in-flight apply — its stale check will bail.
177
+ lastAppliedFilterNameRef.current = null;
164
178
  (call?.camera.state.mediaStream as MediaStream | undefined)
165
179
  ?.getVideoTracks()
166
180
  .forEach((track) => {
@@ -169,6 +183,38 @@ export const BackgroundFiltersProvider = ({ children }: PropsWithChildren) => {
169
183
  setCurrentBackgroundFilter(undefined);
170
184
  }, [call]);
171
185
 
186
+ // Reapplies the filter on track replacement (flip, enable-after-disable).
187
+ // Releases native filter state on unmount / call change.
188
+ useEffect(() => {
189
+ if (!call || !isSupported) return;
190
+ const registeredImageFiltersSet = registeredImageFiltersSetRef.current;
191
+ const subscription = call.camera.state.mediaStream$.subscribe(() => {
192
+ const name = lastAppliedFilterNameRef.current;
193
+ if (!name) return;
194
+ (call.camera.state.mediaStream as MediaStream | undefined)
195
+ ?.getVideoTracks()
196
+ .forEach((track) => {
197
+ track._setVideoEffect(name);
198
+ });
199
+ });
200
+ return () => {
201
+ subscription.unsubscribe();
202
+ (call.camera.state.mediaStream as MediaStream | undefined)
203
+ ?.getVideoTracks()
204
+ .forEach((track) => {
205
+ track._setVideoEffect(null);
206
+ });
207
+ // Drop native processor refs so they can be deallocated. Otherwise the
208
+ // ProcessorProvider registry holds them for the app's lifetime.
209
+ videoFiltersModule?.unregisterAllFilters?.().catch(() => {});
210
+ lastAppliedFilterNameRef.current = null;
211
+ isBackgroundBlurRegisteredRef.current = false;
212
+ isVideoBlurRegisteredRef.current = false;
213
+ registeredImageFiltersSet.clear();
214
+ setCurrentBackgroundFilter(undefined);
215
+ };
216
+ }, [call]);
217
+
172
218
  const value = useMemo(
173
219
  () => ({
174
220
  currentBackgroundFilter,
@@ -9,5 +9,4 @@ export * from './useScreenShareButton';
9
9
  export * from './useScreenShareAudioMixing';
10
10
  export * from './useTrackDimensions';
11
11
  export * from './useScreenshot';
12
- export * from './useSpeechDetection';
13
12
  export * from './useModeration';
@@ -148,12 +148,12 @@ export class StreamVideoRN {
148
148
  * Typically used on user logout.
149
149
  */
150
150
  static onPushLogout() {
151
- if (pushLogoutCallbacks.current) {
152
- return Promise.all(
153
- pushLogoutCallbacks.current.map((callback) => callback()),
154
- ).then(() => {});
151
+ const callbacks = pushLogoutCallbacks.current;
152
+ if (!callbacks) {
153
+ return Promise.resolve();
155
154
  }
156
- return Promise.resolve();
155
+ pushLogoutCallbacks.current = [];
156
+ return Promise.all(callbacks.map((callback) => callback())).then(() => {});
157
157
  }
158
158
 
159
159
  static clearPushLogoutCallbacks() {
@@ -1,5 +1,6 @@
1
1
  import { StreamRNVideoSDKGlobals } from '@stream-io/video-client';
2
2
  import { NativeModules, PermissionsAndroid, Platform } from 'react-native';
3
+ import { audioDeviceModuleEvents } from '@stream-io/react-native-webrtc';
3
4
  import { getCallingxLibIfAvailable } from '../push/libs/callingx';
4
5
  import {
5
6
  endCallingxCall,
@@ -85,6 +86,18 @@ const streamRNVideoSDKGlobals: StreamRNVideoSDKGlobals = {
85
86
  );
86
87
  },
87
88
  },
89
+ nativeEvents: {
90
+ speechActivity: {
91
+ subscribe(cb) {
92
+ const subscription = audioDeviceModuleEvents.addSpeechActivityListener(
93
+ (data) => {
94
+ cb({ isSoundDetected: data.event === 'started' });
95
+ },
96
+ );
97
+ return () => subscription.remove();
98
+ },
99
+ },
100
+ },
88
101
  };
89
102
 
90
103
  // Note: The global type declaration for `streamRNVideoSDK` is defined in
@@ -4,7 +4,6 @@ import {
4
4
  clearPushWSEventSubscriptions,
5
5
  processCallFromPushInBackground,
6
6
  } from './internal/utils';
7
- import { setPushLogoutCallback } from '../internal/pushLogoutCallback';
8
7
  import { resolvePendingAudioSession } from '../internal/callingx/audioSessionPromise';
9
8
  import {
10
9
  getCallingxLib,
@@ -31,25 +30,19 @@ export function setupCallingExpEvents(pushConfig: NonNullable<PushConfig>) {
31
30
 
32
31
  const callingx = getCallingxLib();
33
32
 
34
- const { remove: removeAnswerCall } = callingx.addEventListener(
35
- 'answerCall',
36
- (params) => {
37
- onAcceptCall(pushConfig)(params);
38
- },
39
- );
33
+ callingx.addEventListener('answerCall', (params) => {
34
+ onAcceptCall(pushConfig)(params);
35
+ });
40
36
 
41
- const { remove: removeEndCall } = callingx.addEventListener(
42
- 'endCall',
43
- (params) => {
44
- onEndCall(pushConfig)(params);
45
- },
46
- );
37
+ callingx.addEventListener('endCall', (params) => {
38
+ onEndCall(pushConfig)(params);
39
+ });
47
40
 
48
- const { remove: removeDidActivateAudioSession } = callingx.addEventListener(
41
+ callingx.addEventListener(
49
42
  'didActivateAudioSession',
50
43
  onDidActivateAudioSession,
51
44
  );
52
- const { remove: removeDidDeactivateAudioSession } = callingx.addEventListener(
45
+ callingx.addEventListener(
53
46
  'didDeactivateAudioSession',
54
47
  onDidDeactivateAudioSession,
55
48
  );
@@ -71,13 +64,6 @@ export function setupCallingExpEvents(pushConfig: NonNullable<PushConfig>) {
71
64
  onDidDeactivateAudioSession();
72
65
  }
73
66
  });
74
-
75
- setPushLogoutCallback(async () => {
76
- removeAnswerCall();
77
- removeEndCall();
78
- removeDidActivateAudioSession();
79
- removeDidDeactivateAudioSession();
80
- });
81
67
  }
82
68
 
83
69
  const onDidActivateAudioSession = () => {
@@ -2,7 +2,6 @@
2
2
 
3
3
  import { Platform } from 'react-native';
4
4
  import { onVoipNotificationReceived } from './internal/ios';
5
- import { setPushLogoutCallback } from '../internal/pushLogoutCallback';
6
5
  import { StreamVideoConfig } from '../StreamVideoRN/types';
7
6
  import { videoLoggerSystem } from '@stream-io/video-client';
8
7
  import { getCallingxLib } from './libs';
@@ -23,17 +22,7 @@ export function setupIosVoipPushEvents(
23
22
  }
24
23
 
25
24
  const callingx = getCallingxLib();
26
- const voipNotificationReceivedListener = callingx.addEventListener(
27
- 'voipNotificationReceived',
28
- (params) => {
29
- onVoipNotificationReceived(params, pushConfig);
30
- },
31
- );
32
-
33
- setPushLogoutCallback(async () => {
34
- videoLoggerSystem
35
- .getLogger('setPushLogoutCallback')
36
- .debug('notification event listener removed');
37
- voipNotificationReceivedListener.remove();
25
+ callingx.addEventListener('voipNotificationReceived', (params) => {
26
+ onVoipNotificationReceived(params, pushConfig);
38
27
  });
39
28
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.32.3';
1
+ export const version = '1.33.0';
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useSpeechDetection = useSpeechDetection;
7
- var _react = require("react");
8
- var _videoClient = require("@stream-io/video-client");
9
- var _videoReactBindings = require("@stream-io/video-react-bindings");
10
- /**
11
- * Hook that provides speech detection info using the RNSpeechDetector.
12
- *
13
- * @returns An object containing the current audio level (0 - 1) and whether sound is detected.
14
- */
15
- function useSpeechDetection() {
16
- const [audioState, setAudioState] = (0, _react.useState)({
17
- isSoundDetected: false,
18
- audioLevel: 0
19
- });
20
- const {
21
- useMicrophoneState
22
- } = (0, _videoReactBindings.useCallStateHooks)();
23
- const {
24
- isEnabled,
25
- mediaStream
26
- } = useMicrophoneState();
27
- (0, _react.useEffect)(() => {
28
- if (!isEnabled) return;
29
- const detector = new _videoClient.RNSpeechDetector(mediaStream);
30
- const start = detector.start(state => {
31
- setAudioState(state);
32
- });
33
- return () => {
34
- start.then(stop => stop());
35
- };
36
- }, [mediaStream, isEnabled]);
37
- return audioState;
38
- }
39
- //# sourceMappingURL=useSpeechDetection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_videoClient","_videoReactBindings","useSpeechDetection","audioState","setAudioState","useState","isSoundDetected","audioLevel","useMicrophoneState","useCallStateHooks","isEnabled","mediaStream","useEffect","detector","RNSpeechDetector","start","state","then","stop"],"sourceRoot":"../../../src","sources":["hooks/useSpeechDetection.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAIA,IAAAE,mBAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACO,SAASG,kBAAkBA,CAAA,EAAG;EACnC,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAqB;IAC/DC,eAAe,EAAE,KAAK;IACtBC,UAAU,EAAE;EACd,CAAC,CAAC;EACF,MAAM;IAAEC;EAAmB,CAAC,GAAG,IAAAC,qCAAiB,EAAC,CAAC;EAClD,MAAM;IAAEC,SAAS;IAAEC;EAAY,CAAC,GAAGH,kBAAkB,CAAC,CAAC;EAEvD,IAAAI,gBAAS,EAAC,MAAM;IACd,IAAI,CAACF,SAAS,EAAE;IAEhB,MAAMG,QAAQ,GAAG,IAAIC,6BAAgB,CAACH,WAAW,CAAC;IAClD,MAAMI,KAAK,GAAGF,QAAQ,CAACE,KAAK,CAAEC,KAAyB,IAAK;MAC1DZ,aAAa,CAACY,KAAK,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,MAAM;MACXD,KAAK,CAACE,IAAI,CAAEC,IAAI,IAAKA,IAAI,CAAC,CAAC,CAAC;IAC9B,CAAC;EACH,CAAC,EAAE,CAACP,WAAW,EAAED,SAAS,CAAC,CAAC;EAE5B,OAAOP,UAAU;AACnB","ignoreList":[]}
@@ -1,34 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { RNSpeechDetector } from '@stream-io/video-client';
3
- import { useCallStateHooks } from '@stream-io/video-react-bindings';
4
-
5
- /**
6
- * Hook that provides speech detection info using the RNSpeechDetector.
7
- *
8
- * @returns An object containing the current audio level (0 - 1) and whether sound is detected.
9
- */
10
- export function useSpeechDetection() {
11
- const [audioState, setAudioState] = useState({
12
- isSoundDetected: false,
13
- audioLevel: 0
14
- });
15
- const {
16
- useMicrophoneState
17
- } = useCallStateHooks();
18
- const {
19
- isEnabled,
20
- mediaStream
21
- } = useMicrophoneState();
22
- useEffect(() => {
23
- if (!isEnabled) return;
24
- const detector = new RNSpeechDetector(mediaStream);
25
- const start = detector.start(state => {
26
- setAudioState(state);
27
- });
28
- return () => {
29
- start.then(stop => stop());
30
- };
31
- }, [mediaStream, isEnabled]);
32
- return audioState;
33
- }
34
- //# sourceMappingURL=useSpeechDetection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useState","RNSpeechDetector","useCallStateHooks","useSpeechDetection","audioState","setAudioState","isSoundDetected","audioLevel","useMicrophoneState","isEnabled","mediaStream","detector","start","state","then","stop"],"sourceRoot":"../../../src","sources":["hooks/useSpeechDetection.ts"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAEEC,gBAAgB,QACX,yBAAyB;AAChC,SAASC,iBAAiB,QAAQ,iCAAiC;;AAEnE;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAA,EAAG;EACnC,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGL,QAAQ,CAAqB;IAC/DM,eAAe,EAAE,KAAK;IACtBC,UAAU,EAAE;EACd,CAAC,CAAC;EACF,MAAM;IAAEC;EAAmB,CAAC,GAAGN,iBAAiB,CAAC,CAAC;EAClD,MAAM;IAAEO,SAAS;IAAEC;EAAY,CAAC,GAAGF,kBAAkB,CAAC,CAAC;EAEvDT,SAAS,CAAC,MAAM;IACd,IAAI,CAACU,SAAS,EAAE;IAEhB,MAAME,QAAQ,GAAG,IAAIV,gBAAgB,CAACS,WAAW,CAAC;IAClD,MAAME,KAAK,GAAGD,QAAQ,CAACC,KAAK,CAAEC,KAAyB,IAAK;MAC1DR,aAAa,CAACQ,KAAK,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,MAAM;MACXD,KAAK,CAACE,IAAI,CAAEC,IAAI,IAAKA,IAAI,CAAC,CAAC,CAAC;IAC9B,CAAC;EACH,CAAC,EAAE,CAACL,WAAW,EAAED,SAAS,CAAC,CAAC;EAE5B,OAAOL,UAAU;AACnB","ignoreList":[]}
@@ -1,8 +0,0 @@
1
- import { type SoundDetectorState } from '@stream-io/video-client';
2
- /**
3
- * Hook that provides speech detection info using the RNSpeechDetector.
4
- *
5
- * @returns An object containing the current audio level (0 - 1) and whether sound is detected.
6
- */
7
- export declare function useSpeechDetection(): SoundDetectorState;
8
- //# sourceMappingURL=useSpeechDetection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSpeechDetection.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSpeechDetection.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,yBAAyB,CAAC;AAGjC;;;;GAIG;AACH,wBAAgB,kBAAkB,uBAsBjC"}
@@ -1,35 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import {
3
- type SoundDetectorState,
4
- RNSpeechDetector,
5
- } from '@stream-io/video-client';
6
- import { useCallStateHooks } from '@stream-io/video-react-bindings';
7
-
8
- /**
9
- * Hook that provides speech detection info using the RNSpeechDetector.
10
- *
11
- * @returns An object containing the current audio level (0 - 1) and whether sound is detected.
12
- */
13
- export function useSpeechDetection() {
14
- const [audioState, setAudioState] = useState<SoundDetectorState>({
15
- isSoundDetected: false,
16
- audioLevel: 0,
17
- });
18
- const { useMicrophoneState } = useCallStateHooks();
19
- const { isEnabled, mediaStream } = useMicrophoneState();
20
-
21
- useEffect(() => {
22
- if (!isEnabled) return;
23
-
24
- const detector = new RNSpeechDetector(mediaStream);
25
- const start = detector.start((state: SoundDetectorState) => {
26
- setAudioState(state);
27
- });
28
-
29
- return () => {
30
- start.then((stop) => stop());
31
- };
32
- }, [mediaStream, isEnabled]);
33
-
34
- return audioState;
35
- }