Skip to content

Commit 02aab99

Browse files
RegaddiAlexHayton
andcommitted
add interval parameter to useAudioLevelObserver
Co-Authored-By: Alex Hayton <alex.hayton@gmail.com>
1 parent 10be992 commit 02aab99

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/hooks/useAudioLevelObserver.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ type ErrorCallback = (errorMsg: string) => void;
1212
* @param id The session_id of the participant to observe.
1313
* @param cb The function to execute when the volume changes. Can be used to visualise audio output.
1414
* @param errorCb Error callback. Called when local audio level observer is not available in browser.
15+
* @param interval Callbacks will be executed at this freqency. If unspecified, Daily's default frequency is used.
1516
*/
1617
export const useAudioLevelObserver = (
1718
id: string,
1819
cb: AudioLevelCallback,
19-
errorCb?: ErrorCallback
20+
errorCb?: ErrorCallback,
21+
interval?: number
2022
) => {
2123
const daily = useDaily();
2224
const localSessionId = useLocalSessionId();
@@ -49,20 +51,20 @@ export const useAudioLevelObserver = (
4951
if (!daily || daily.isDestroyed() || !isLocal) return;
5052
if (daily.isLocalAudioLevelObserverRunning()) return;
5153
try {
52-
daily.startLocalAudioLevelObserver();
54+
daily.startLocalAudioLevelObserver(interval);
5355
} catch {
5456
errorCb?.('Local audio level observer not supported in this browser');
5557
}
5658
},
57-
[daily, errorCb, isLocal]
59+
[daily, errorCb, interval, isLocal]
5860
);
5961

6062
useEffect(
6163
function maybeStartRemoteAudioObserver() {
6264
if (!daily || daily.isDestroyed() || isLocal) return;
6365
if (daily.isRemoteParticipantsAudioLevelObserverRunning()) return;
64-
daily.startRemoteParticipantsAudioLevelObserver();
66+
daily.startRemoteParticipantsAudioLevelObserver(interval);
6567
},
66-
[daily, isLocal]
68+
[daily, interval, isLocal]
6769
);
6870
};

0 commit comments

Comments
 (0)