@100mslive/hms-video-store
Version:
@100mslive Core SDK which abstracts the complexities of webRTC while providing a reactive store for data management with a unidirectional data flow
40 lines (39 loc) • 1.42 kB
TypeScript
import { HMSInternalEvent } from '../events/HMSInternalEvent';
import { HMSLocalAudioTrack } from '../internal';
export interface ITrackAudioLevelUpdate {
track: HMSLocalAudioTrack;
audioLevel: number;
}
export declare class TrackAudioLevelMonitor {
private track;
private audioLevelEvent;
private silenceEvent;
private readonly TAG;
private audioLevel;
private analyserNode?;
private dataArray?;
private isMonitored;
/** Frequency of polling audio level from track */
private interval;
/** Store past audio levels for this duration */
private historyInterval;
private history;
constructor(track: HMSLocalAudioTrack, audioLevelEvent: HMSInternalEvent<ITrackAudioLevelUpdate>, silenceEvent: HMSInternalEvent<{
track: HMSLocalAudioTrack;
}>);
/**
* To detect silence we check if the track is unmuted and silent in the current moment
* periodically. If the track is found to be silent more than a threshold number of times
* we send the event. The threshold number of time is there to reduce the chance of false
* positives.
*/
detectSilence: () => Promise<void>;
start(): void;
stop(): void;
private loop;
private sendAudioLevel;
private getMaxAudioLevelOverPeriod;
private calculateAudioLevel;
isSilentThisInstant(): boolean | undefined;
private createAnalyserNodeForStream;
}