浏览代码

feat(ts) migrate detection/NoAudioSignalDetection to TS

master
Naman Jain 4 个月前
父节点
当前提交
22fff447eb
没有帐户链接到提交者的电子邮件
共有 2 个文件被更改,包括 30 次插入17 次删除
  1. 2
    1
      globals.d.ts
  2. 28
    16
      modules/detection/NoAudioSignalDetection.ts

+ 2
- 1
globals.d.ts 查看文件

1
 export {};
1
 export {};
2
 
2
 
3
-declare global {
3
+declare global {    
4
+    type Timeout = ReturnType<typeof setTimeout>;
4
     interface Window {
5
     interface Window {
5
         connectionTimes: any;
6
         connectionTimes: any;
6
     }
7
     }

modules/detection/NoAudioSignalDetection.js → modules/detection/NoAudioSignalDetection.ts 查看文件

1
-import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
2
-import * as JitsiTrackEvents from '../../JitsiTrackEvents';
3
 import EventEmitter from '../util/EventEmitter';
1
 import EventEmitter from '../util/EventEmitter';
4
-
2
+import { JitsiConferenceEvents } from '../../JitsiConferenceEvents';
3
+import { JitsiTrackEvents } from '../../JitsiTrackEvents';
5
 import * as DetectionEvents from './DetectionEvents';
4
 import * as DetectionEvents from './DetectionEvents';
6
 
5
 
6
+import type JitsiLocalTrack from '../RTC/JitsiLocalTrack';
7
+import type JitsiConference from '../../JitsiConference';
8
+import type TraceablePeerConnection from '../RTC/TraceablePeerConnection';
9
+
7
 // We wait a certain time interval for constant silence input from the current device to account for
10
 // We wait a certain time interval for constant silence input from the current device to account for
8
 // potential abnormalities and for a better use experience i.e. don't generate event the instant
11
 // potential abnormalities and for a better use experience i.e. don't generate event the instant
9
 // an audio track is added to the tcr.
12
 // an audio track is added to the tcr.
17
  * @fires DetectionEvents.NO_AUDIO_INPUT
20
  * @fires DetectionEvents.NO_AUDIO_INPUT
18
  */
21
  */
19
 export default class NoAudioSignalDetection extends EventEmitter {
22
 export default class NoAudioSignalDetection extends EventEmitter {
23
+    private _conference: JitsiConference;
24
+    private _timeoutTrigger: Timeout | null;
25
+    private _hasAudioInput: boolean | null;
26
+    private _audioTrack: JitsiLocalTrack | null;
27
+    private _eventFired: boolean;
28
+
20
     /**
29
     /**
21
      * Creates new NoAudioSignalDetection.
30
      * Creates new NoAudioSignalDetection.
22
      *
31
      *
23
      * @param conference the JitsiConference instance that created us.
32
      * @param conference the JitsiConference instance that created us.
24
      * @constructor
33
      * @constructor
25
      */
34
      */
26
-    constructor(conference) {
35
+    constructor(conference: JitsiConference) {
27
         super();
36
         super();
28
 
37
 
29
         this._conference = conference;
38
         this._conference = conference;
30
         this._timeoutTrigger = null;
39
         this._timeoutTrigger = null;
31
         this._hasAudioInput = null;
40
         this._hasAudioInput = null;
41
+        this._audioTrack = null;
42
+        this._eventFired = false;
32
 
43
 
33
         conference.on(JitsiConferenceEvents.TRACK_ADDED, this._trackAdded.bind(this));
44
         conference.on(JitsiConferenceEvents.TRACK_ADDED, this._trackAdded.bind(this));
34
     }
45
     }
36
     /**
47
     /**
37
      * Clear the timeout state.
48
      * Clear the timeout state.
38
      */
49
      */
39
-    _clearTriggerTimeout() {
40
-        clearTimeout(this._timeoutTrigger);
41
-        this._timeoutTrigger = null;
50
+    private _clearTriggerTimeout(): void {
51
+        if (this._timeoutTrigger) {
52
+            clearTimeout(this._timeoutTrigger);
53
+            this._timeoutTrigger = null;
54
+        }
42
     }
55
     }
43
 
56
 
44
-
45
     /**
57
     /**
46
      * Generated event triggered by a change in the current conference audio input state.
58
      * Generated event triggered by a change in the current conference audio input state.
47
      *
59
      *
48
-     * @param {*} audioLevel - The audio level of the ssrc.
60
+     * @param {number} audioLevel - The audio level of the ssrc.
49
      * @fires DetectionEvents.AUDIO_INPUT_STATE_CHANGE
61
      * @fires DetectionEvents.AUDIO_INPUT_STATE_CHANGE
50
      */
62
      */
51
-    _handleAudioInputStateChange(audioLevel) {
63
+    private _handleAudioInputStateChange(audioLevel: number): void {
52
         // Current audio input state of the active local track in the conference, true for audio input false for no
64
         // Current audio input state of the active local track in the conference, true for audio input false for no
53
         // audio input.
65
         // audio input.
54
         const status = audioLevel !== 0;
66
         const status = audioLevel !== 0;
67
      * @param {number} audioLevel - The audio level of the ssrc.
79
      * @param {number} audioLevel - The audio level of the ssrc.
68
      * @fires DetectionEvents.NO_AUDIO_INPUT
80
      * @fires DetectionEvents.NO_AUDIO_INPUT
69
      */
81
      */
70
-    _handleNoAudioInputDetection(audioLevel) {
82
+    private _handleNoAudioInputDetection(audioLevel: number): void {
71
         if (this._eventFired) {
83
         if (this._eventFired) {
72
             return;
84
             return;
73
         }
85
         }
92
      * @param {number} audioLevel - The audio level of the ssrc.
104
      * @param {number} audioLevel - The audio level of the ssrc.
93
      * @param {boolean} isLocal - true for local/send streams or false for remote/receive streams.
105
      * @param {boolean} isLocal - true for local/send streams or false for remote/receive streams.
94
      */
106
      */
95
-    _audioLevel(tpc, ssrc, audioLevel, isLocal) {
107
+    private _audioLevel(tpc: TraceablePeerConnection, ssrc: number, audioLevel: number, isLocal: boolean): void {
96
         // We are interested in the local audio streams
108
         // We are interested in the local audio streams
97
         if (!isLocal || !this._audioTrack) {
109
         if (!isLocal || !this._audioTrack) {
98
             return;
110
             return;
103
 
115
 
104
         // Only target the current active track in the tpc. For some reason audio levels for previous
116
         // Only target the current active track in the tpc. For some reason audio levels for previous
105
         // devices are also picked up from the PeerConnection so we filter them out.
117
         // devices are also picked up from the PeerConnection so we filter them out.
106
-        if (!localSSRCs || !localSSRCs.ssrcs.includes(ssrc)) {
118
+        if (!localSSRCs?.ssrcs.includes(ssrc)) {
107
             return;
119
             return;
108
         }
120
         }
109
 
121
 
119
      *
131
      *
120
      * @param {JitsiTrack} track - The added JitsiTrack.
132
      * @param {JitsiTrack} track - The added JitsiTrack.
121
      */
133
      */
122
-    _trackAdded(track) {
134
+    private _trackAdded(track: JitsiLocalTrack): void {
123
         if (track.isLocalAudioTrack()) {
135
         if (track.isLocalAudioTrack()) {
124
             // Reset state for the new track.
136
             // Reset state for the new track.
125
             this._audioTrack = track;
137
             this._audioTrack = track;
129
             // Listen for the audio levels on the newly added audio track
141
             // Listen for the audio levels on the newly added audio track
130
             track.on(
142
             track.on(
131
                 JitsiTrackEvents.NO_AUDIO_INPUT,
143
                 JitsiTrackEvents.NO_AUDIO_INPUT,
132
-                audioLevel => {
144
+                (audioLevel: number) => {
133
                     this._handleNoAudioInputDetection(audioLevel);
145
                     this._handleNoAudioInputDetection(audioLevel);
134
                 }
146
                 }
135
             );
147
             );
136
             track.on(
148
             track.on(
137
                 JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
149
                 JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
138
-                audioLevel => {
150
+                (audioLevel: number) => {
139
                     this._handleNoAudioInputDetection(audioLevel);
151
                     this._handleNoAudioInputDetection(audioLevel);
140
                     this._handleAudioInputStateChange(audioLevel);
152
                     this._handleAudioInputStateChange(audioLevel);
141
                 }
153
                 }

正在加载...
取消
保存