Skip to content

Commit

Permalink
feat(ts) TypeScript conversion of DetectionEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
garyhuntddn authored Feb 28, 2022
1 parent 6d428ca commit bf3c588
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 124 deletions.
60 changes: 0 additions & 60 deletions modules/detection/DetectionEvents.js

This file was deleted.

21 changes: 11 additions & 10 deletions modules/detection/DetectionEvents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe( "/modules/detection/DetectionEvents members", () => {
VAD_TALK_WHILE_MUTED,
DetectionEvents,
...others
} = exported as any; // TODO: remove cast after typescript conversion
} = exported;

it( "known members", () => {
expect( DETECTOR_STATE_CHANGE ).toBe( 'detector_state_change' );
Expand All @@ -23,15 +23,16 @@ describe( "/modules/detection/DetectionEvents members", () => {
expect( VAD_REPORT_PUBLISHED ).toBe( 'vad-report-published' );
expect( VAD_SCORE_PUBLISHED ).toBe( 'detection.vad_score_published' );
expect( VAD_TALK_WHILE_MUTED ).toBe( 'detection.vad_talk_while_muted' );
if ( DetectionEvents ) {
expect( DetectionEvents.DETECTOR_STATE_CHANGE ).toBe( 'detector_state_change' );
expect( DetectionEvents.AUDIO_INPUT_STATE_CHANGE ).toBe( 'audio_input_state_changed' );
expect( DetectionEvents.NO_AUDIO_INPUT ).toBe( 'no_audio_input_detected' );
expect( DetectionEvents.VAD_NOISY_DEVICE ).toBe( 'detection.vad_noise_device' );
expect( DetectionEvents.VAD_REPORT_PUBLISHED ).toBe( 'vad-report-published' );
expect( DetectionEvents.VAD_SCORE_PUBLISHED ).toBe( 'detection.vad_score_published' );
expect( DetectionEvents.VAD_TALK_WHILE_MUTED ).toBe( 'detection.vad_talk_while_muted' );
}

expect( DetectionEvents ).toBeDefined();

expect( DetectionEvents.DETECTOR_STATE_CHANGE ).toBe( 'detector_state_change' );
expect( DetectionEvents.AUDIO_INPUT_STATE_CHANGE ).toBe( 'audio_input_state_changed' );
expect( DetectionEvents.NO_AUDIO_INPUT ).toBe( 'no_audio_input_detected' );
expect( DetectionEvents.VAD_NOISY_DEVICE ).toBe( 'detection.vad_noise_device' );
expect( DetectionEvents.VAD_REPORT_PUBLISHED ).toBe( 'vad-report-published' );
expect( DetectionEvents.VAD_SCORE_PUBLISHED ).toBe( 'detection.vad_score_published' );
expect( DetectionEvents.VAD_TALK_WHILE_MUTED ).toBe( 'detection.vad_talk_while_muted' );
} );

it( "unknown members", () => {
Expand Down
71 changes: 71 additions & 0 deletions modules/detection/DetectionEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export enum DetectionEvents {
/**
* Event triggered by a audio detector indicating that its active state has changed from active to inactive or vice
* versa.
* @event
* @type {boolean} - true when service has changed to active false otherwise.
*/
DETECTOR_STATE_CHANGE = 'detector_state_change',

/** Event triggered by {@link NoAudioSignalDetector} when the local audio device associated with a JitsiConference
* starts receiving audio levels with the value of 0 meaning no audio is being captured on that device, or when
* it starts receiving audio levels !== 0 after being in a state of no audio.
* @event
* @type {boolean} - true when the current conference audio track has audio input false otherwise.
*/
AUDIO_INPUT_STATE_CHANGE = 'audio_input_state_changed',

/** Event triggered by NoAudioSignalDetector when the local audio device associated with a JitsiConference goes silent
* for a period of time, meaning that the device is either broken or hardware/software muted.
* @event
* @type {void}
*/
NO_AUDIO_INPUT = 'no_audio_input_detected',

/**
* Event generated by {@link VADNoiseDetection} when the tracked device is considered noisy.
* @event
* @type {Object}
*/
VAD_NOISY_DEVICE = 'detection.vad_noise_device',

/**
* Event generated by VADReportingService when if finishes creating a VAD report for the monitored devices.
* The generated objects are of type Array<Object>, one score for each monitored device.
* @event VAD_REPORT_PUBLISHED
* @type Array<Object> with the following structure:
* @property {Date} timestamp - Timestamp at which the compute took place.
* @property {number} avgVAD - Average VAD score over monitored period of time.
* @property {string} deviceId - Associate local audio device ID.
*/
VAD_REPORT_PUBLISHED = 'vad-report-published',

/**
* Event generated by {@link TrackVADEmitter} when PCM sample VAD score is available.
*
* @event
* @type {Object}
* @property {Date} timestamp - Exact time at which processed PCM sample was generated.
* @property {number} score - VAD score on a scale from 0 to 1 (i.e. 0.7)
* @property {Float32Array} pcmData - Raw PCM data with which the VAD score was calculated.
* @property {string} deviceId - Device id of the associated track.
*/
VAD_SCORE_PUBLISHED = 'detection.vad_score_published',

/**
* Event generated by {@link VADTalkMutedDetection} when a user is talking while the mic is muted.
*
* @event
* @type {Object}
*/
VAD_TALK_WHILE_MUTED = 'detection.vad_talk_while_muted'
};

// exported for backward compatibility
export const DETECTOR_STATE_CHANGE = DetectionEvents.DETECTOR_STATE_CHANGE;
export const AUDIO_INPUT_STATE_CHANGE = DetectionEvents.AUDIO_INPUT_STATE_CHANGE;
export const NO_AUDIO_INPUT = DetectionEvents.NO_AUDIO_INPUT;
export const VAD_NOISY_DEVICE = DetectionEvents.VAD_NOISY_DEVICE;
export const VAD_REPORT_PUBLISHED = DetectionEvents.VAD_REPORT_PUBLISHED;
export const VAD_SCORE_PUBLISHED = DetectionEvents.VAD_SCORE_PUBLISHED;
export const VAD_TALK_WHILE_MUTED = DetectionEvents.VAD_TALK_WHILE_MUTED;
117 changes: 63 additions & 54 deletions types/auto/modules/detection/DetectionEvents.d.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,63 @@
/**
* Event triggered by a audio detector indicating that its active state has changed from active to inactive or vice
* versa.
* @event
* @type {boolean} - true when service has changed to active false otherwise.
*/
export const DETECTOR_STATE_CHANGE: boolean;
/** Event triggered by {@link NoAudioSignalDetector} when the local audio device associated with a JitsiConference
* starts receiving audio levels with the value of 0 meaning no audio is being captured on that device, or when
* it starts receiving audio levels !== 0 after being in a state of no audio.
* @event
* @type {boolean} - true when the current conference audio track has audio input false otherwise.
*/
export const AUDIO_INPUT_STATE_CHANGE: boolean;
/** Event triggered by NoAudioSignalDetector when the local audio device associated with a JitsiConference goes silent
* for a period of time, meaning that the device is either broken or hardware/software muted.
* @event
* @type {void}
*/
export const NO_AUDIO_INPUT: void;
/**
* Event generated by {@link VADNoiseDetection} when the tracked device is considered noisy.
* @event
* @type {Object}
*/
export const VAD_NOISY_DEVICE: any;
/**
* Event generated by VADReportingService when if finishes creating a VAD report for the monitored devices.
* The generated objects are of type Array<Object>, one score for each monitored device.
* @event VAD_REPORT_PUBLISHED
* @type Array<Object> with the following structure:
* @property {Date} timestamp - Timestamp at which the compute took place.
* @property {number} avgVAD - Average VAD score over monitored period of time.
* @property {string} deviceId - Associate local audio device ID.
*/
export const VAD_REPORT_PUBLISHED: Array<any>;
/**
* Event generated by {@link TrackVADEmitter} when PCM sample VAD score is available.
*
* @event
* @type {Object}
* @property {Date} timestamp - Exact time at which processed PCM sample was generated.
* @property {number} score - VAD score on a scale from 0 to 1 (i.e. 0.7)
* @property {Float32Array} pcmData - Raw PCM data with which the VAD score was calculated.
* @property {string} deviceId - Device id of the associated track.
*/
export const VAD_SCORE_PUBLISHED: any;
/**
* Event generated by {@link VADTalkMutedDetection} when a user is talking while the mic is muted.
*
* @event
* @type {Object}
*/
export const VAD_TALK_WHILE_MUTED: any;
export declare enum DetectionEvents {
/**
* Event triggered by a audio detector indicating that its active state has changed from active to inactive or vice
* versa.
* @event
* @type {boolean} - true when service has changed to active false otherwise.
*/
DETECTOR_STATE_CHANGE = "detector_state_change",
/** Event triggered by {@link NoAudioSignalDetector} when the local audio device associated with a JitsiConference
* starts receiving audio levels with the value of 0 meaning no audio is being captured on that device, or when
* it starts receiving audio levels !== 0 after being in a state of no audio.
* @event
* @type {boolean} - true when the current conference audio track has audio input false otherwise.
*/
AUDIO_INPUT_STATE_CHANGE = "audio_input_state_changed",
/** Event triggered by NoAudioSignalDetector when the local audio device associated with a JitsiConference goes silent
* for a period of time, meaning that the device is either broken or hardware/software muted.
* @event
* @type {void}
*/
NO_AUDIO_INPUT = "no_audio_input_detected",
/**
* Event generated by {@link VADNoiseDetection} when the tracked device is considered noisy.
* @event
* @type {Object}
*/
VAD_NOISY_DEVICE = "detection.vad_noise_device",
/**
* Event generated by VADReportingService when if finishes creating a VAD report for the monitored devices.
* The generated objects are of type Array<Object>, one score for each monitored device.
* @event VAD_REPORT_PUBLISHED
* @type Array<Object> with the following structure:
* @property {Date} timestamp - Timestamp at which the compute took place.
* @property {number} avgVAD - Average VAD score over monitored period of time.
* @property {string} deviceId - Associate local audio device ID.
*/
VAD_REPORT_PUBLISHED = "vad-report-published",
/**
* Event generated by {@link TrackVADEmitter} when PCM sample VAD score is available.
*
* @event
* @type {Object}
* @property {Date} timestamp - Exact time at which processed PCM sample was generated.
* @property {number} score - VAD score on a scale from 0 to 1 (i.e. 0.7)
* @property {Float32Array} pcmData - Raw PCM data with which the VAD score was calculated.
* @property {string} deviceId - Device id of the associated track.
*/
VAD_SCORE_PUBLISHED = "detection.vad_score_published",
/**
* Event generated by {@link VADTalkMutedDetection} when a user is talking while the mic is muted.
*
* @event
* @type {Object}
*/
VAD_TALK_WHILE_MUTED = "detection.vad_talk_while_muted"
}
export declare const DETECTOR_STATE_CHANGE = DetectionEvents.DETECTOR_STATE_CHANGE;
export declare const AUDIO_INPUT_STATE_CHANGE = DetectionEvents.AUDIO_INPUT_STATE_CHANGE;
export declare const NO_AUDIO_INPUT = DetectionEvents.NO_AUDIO_INPUT;
export declare const VAD_NOISY_DEVICE = DetectionEvents.VAD_NOISY_DEVICE;
export declare const VAD_REPORT_PUBLISHED = DetectionEvents.VAD_REPORT_PUBLISHED;
export declare const VAD_SCORE_PUBLISHED = DetectionEvents.VAD_SCORE_PUBLISHED;
export declare const VAD_TALK_WHILE_MUTED = DetectionEvents.VAD_TALK_WHILE_MUTED;

0 comments on commit bf3c588

Please sign in to comment.