@stream-io/video-client 0.0.2-alpha.13 → 0.0.2-alpha.14

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.
@@ -23,6 +23,15 @@ export type SoundDetectorOptions = {
23
23
  */
24
24
  destroyStreamOnStop?: boolean;
25
25
  };
26
+ export type SoundDetectorState = {
27
+ isSoundDetected: boolean;
28
+ /**
29
+ * Represented as percentage (0-100) where 100% is defined by `audioLevelThreshold` property.
30
+ * Decrease time between samples (to 50-100ms) with `detectionFrequencyInMs` property.
31
+ */
32
+ audioLevel: number;
33
+ };
34
+ export type SoundStateChangeHandler = (state: SoundDetectorState) => void;
26
35
  /**
27
36
  * Creates a new sound detector.
28
37
  *
@@ -31,4 +40,4 @@ export type SoundDetectorOptions = {
31
40
  * @param options custom options for the sound detector.
32
41
  * @returns a clean-up function which once invoked stops the sound detector.
33
42
  */
34
- export declare const createSoundDetector: (audioStream: MediaStream, onSoundDetectedStateChanged: (isSoundDetected: boolean, audioLevel: number) => void, options?: SoundDetectorOptions) => () => Promise<void>;
43
+ export declare const createSoundDetector: (audioStream: MediaStream, onSoundDetectedStateChanged: SoundStateChangeHandler, options?: SoundDetectorOptions) => () => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-io/video-client",
3
- "version": "0.0.2-alpha.13",
3
+ "version": "0.0.2-alpha.14",
4
4
  "packageManager": "yarn@3.2.4",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -27,6 +27,17 @@ export type SoundDetectorOptions = {
27
27
  destroyStreamOnStop?: boolean;
28
28
  };
29
29
 
30
+ export type SoundDetectorState = {
31
+ isSoundDetected: boolean;
32
+ /**
33
+ * Represented as percentage (0-100) where 100% is defined by `audioLevelThreshold` property.
34
+ * Decrease time between samples (to 50-100ms) with `detectionFrequencyInMs` property.
35
+ */
36
+ audioLevel: number;
37
+ };
38
+
39
+ export type SoundStateChangeHandler = (state: SoundDetectorState) => void;
40
+
30
41
  const DETECTION_FREQUENCY_IN_MS = 500;
31
42
  const AUDIO_LEVEL_THRESHOLD = 150;
32
43
  const FFT_SIZE = 128;
@@ -41,14 +52,7 @@ const FFT_SIZE = 128;
41
52
  */
42
53
  export const createSoundDetector = (
43
54
  audioStream: MediaStream,
44
- onSoundDetectedStateChanged: (
45
- isSoundDetected: boolean,
46
- /**
47
- * Represented as percentage (0-100) where 100% is defined by `audioLevelThreshold` property.
48
- * Decrease time between samples (to 50-100ms) with `detectionFrequencyInMs` property.
49
- */
50
- audioLevel: number,
51
- ) => void,
55
+ onSoundDetectedStateChanged: SoundStateChangeHandler,
52
56
  options: SoundDetectorOptions = {},
53
57
  ) => {
54
58
  const {
@@ -78,7 +82,7 @@ export const createSoundDetector = (
78
82
  ? 100
79
83
  : Math.round((averagedDataValue / audioLevelThreshold) * 100);
80
84
 
81
- onSoundDetectedStateChanged(isSoundDetected, percentage);
85
+ onSoundDetectedStateChanged({ isSoundDetected, audioLevel: percentage });
82
86
  }, detectionFrequencyInMs);
83
87
 
84
88
  return async function stop() {