ソースを参照

feat(ts) migrate ActiveDeviceDetector to TS

master
Naman Jain 4ヶ月前
コミット
868ed78280
コミッターのメールアドレスに関連付けられたアカウントが存在しません
1個のファイルの変更22行の追加13行の削除
  1. 22
    13
      modules/detection/ActiveDeviceDetector.ts

modules/detection/ActiveDeviceDetector.js → modules/detection/ActiveDeviceDetector.ts ファイルの表示

@@ -1,9 +1,14 @@
1 1
 import { getLogger } from '@jitsi/logger';
2 2
 
3 3
 import * as JitsiTrackEvents from '../../JitsiTrackEvents';
4
+import JitsiLocalTrack from '../RTC/JitsiLocalTrack';
4 5
 import RTC from '../RTC/RTC';
5 6
 import Statistics from '../statistics/statistics';
6 7
 
8
+export interface IActiveDeviceInfo {
9
+    deviceId: string;
10
+    deviceLabel: string;
11
+}
7 12
 
8 13
 const logger = getLogger('modules/detection/ActiveDeviceDetector');
9 14
 
@@ -15,19 +20,21 @@ const DETECTION_TIMEOUT = 3000;
15 20
 /**
16 21
  * Go through all audio devices on the system and return one that is active, i.e. has audio signal.
17 22
  *
18
- * @returns Promise<Object> - Object containing information about the found device.
23
+ * @returns Promise<IActiveDeviceInfo> - Object containing information about the found device.
19 24
  */
20
-export default function getActiveAudioDevice() {
25
+export default function getActiveAudioDevice(): Promise<IActiveDeviceInfo> {
21 26
 
22 27
     return new Promise(resolve => {
23
-        RTC.enumerateDevices(devices => {
28
+        RTC.enumerateDevices((devices: MediaDeviceInfo[]) => {
24 29
             const audioDevices = devices.filter(device => device.kind === 'audioinput');
25
-            const devicePromiseArray = [];
30
+            const devicePromiseArray: Promise<JitsiLocalTrack>[] = [];
26 31
 
27 32
 
28 33
             for (const micDevice of audioDevices) {
29
-                const devicePromise = RTC.obtainAudioAndVideoPermissions({ devices: [ 'audio' ],
30
-                    micDeviceId: micDevice.deviceId }).then(tracks => {
34
+                const devicePromise = RTC.obtainAudioAndVideoPermissions({
35
+                    devices: [ 'audio' ],
36
+                    micDeviceId: micDevice.deviceId
37
+                }).then((tracks: JitsiLocalTrack[]) => {
31 38
 
32 39
                     // We expect a single device to be available when obtained from obtainAudioAndVideoPermissions
33 40
                     // that's  why only take p.value[0].
@@ -46,8 +53,8 @@ export default function getActiveAudioDevice() {
46 53
                 const rejectedPromises = outcomeArray.filter(p => p.status === 'rejected');
47 54
 
48 55
 
49
-                const availableDevices = successfulPromises.map(p => p.value);
50
-                const rejectReasons = rejectedPromises.map(p => p.value);
56
+                const availableDevices = successfulPromises.map(p => (p as PromiseFulfilledResult<JitsiLocalTrack>).value);
57
+                const rejectReasons = rejectedPromises.map(p => (p as any).value);
51 58
 
52 59
                 for (const reason of rejectReasons) {
53 60
                     logger.error('Failed to acquire audio device with error: ', reason);
@@ -62,8 +69,10 @@ export default function getActiveAudioDevice() {
62 69
                         // no input.
63 70
                         if (audioLevel > 0.008) {
64 71
                             stopActiveDevices(availableDevices);
65
-                            resolve({ deviceId: device.deviceId,
66
-                                deviceLabel: device.track.label });
72
+                            resolve({
73
+                                deviceId: device.deviceId,
74
+                                deviceLabel: device.track.label
75
+                            });
67 76
                         }
68 77
                     });
69 78
                 }
@@ -73,8 +82,8 @@ export default function getActiveAudioDevice() {
73 82
                     stopActiveDevices(availableDevices);
74 83
                     resolve({
75 84
                         deviceId: '',
76
-                        deviceLabel: '' }
77
-                    );
85
+                        deviceLabel: ''
86
+                    });
78 87
                 }, DETECTION_TIMEOUT);
79 88
 
80 89
             });
@@ -89,7 +98,7 @@ export default function getActiveAudioDevice() {
89 98
  * @param {Array<JitsiLocalTrack>} deviceList - Array of JitsiLocalTracks to stop.
90 99
  * @returns {void}
91 100
  */
92
-function stopActiveDevices(deviceList) {
101
+function stopActiveDevices(deviceList: JitsiLocalTrack[]): void {
93 102
     for (const device of deviceList) {
94 103
         device.stopStream();
95 104
     }

読み込み中…
キャンセル
保存