-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathSwitchMicrophoneControl.js
More file actions
90 lines (82 loc) 路 2.78 KB
/
Copy pathSwitchMicrophoneControl.js
File metadata and controls
90 lines (82 loc) 路 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {concat, Observable, defer} from 'rxjs';
import {
first,
map,
concatMap,
distinctUntilChanged,
} from 'rxjs/operators';
import MeetingControl from './MeetingControl';
/**
* Display options of a meeting control.
*
* @external MeetingControlDisplay
* @see {@link https://github.com/webex/component-adapter-interfaces/blob/master/src/MeetingsAdapter.js#L58}
*/
export default class SwitchMicrophoneControl extends MeetingControl {
/**
* Switches the microphone control.
*
* @param {string} meetingID Id of the meeting for which to switch microphone
* @param {string} microphoneID Id of the microphone device to switch to
*/
async action(meetingID, microphoneID) {
await this.adapter.switchMicrophone(meetingID, microphoneID);
}
/**
* Returns an observable that emits the display data of the switch microphone control.
*
* @param {string} meetingID Id of the meeting to switch microphone
* @returns {Observable.<MeetingControlDisplay>} Observable that emits control display data
* @private
*/
display(meetingID) {
const availableMicrophones$ = this.adapter.getMeeting(meetingID).pipe(
first(),
concatMap(() => defer(() => this.adapter.getAvailableDevices(meetingID, 'audioinput'))),
);
const initialControl$ = new Observable((observer) => {
const meeting = this.adapter.fetchMeeting(meetingID);
if (meeting) {
observer.next({
ID: this.ID,
type: 'MULTISELECT',
tooltip: 'Microphone Devices',
noOptionsMessage: 'No available microphones',
options: null,
selected: null,
});
observer.complete();
} else {
observer.error(new Error(`Could not find meeting with ID "${meetingID}" to add switch microphone control`));
}
});
const controlWithOptions$ = initialControl$.pipe(
concatMap((control) => availableMicrophones$.pipe(
map((availableMicrophones) => ({
...control,
options: (availableMicrophones || []) && availableMicrophones.map((microphone) => ({
value: microphone.deviceId,
label: microphone.label || `Microphone-${microphone.deviceId}`,
microphone,
})),
})),
)),
);
const controlFromMeeting$ = controlWithOptions$.pipe(
concatMap((control) => this.adapter.getMeeting(meetingID).pipe(
map((meeting) => meeting.microphoneID),
distinctUntilChanged(),
map((microphoneID) => ({
...control,
selected: microphoneID,
})),
)),
);
return concat(initialControl$, controlWithOptions$, controlFromMeeting$).pipe(
distinctUntilChanged((prev, curr) => (
prev.selected === curr.selected
&& prev.options === curr.options
)),
);
}
}