2018-04-12 19:58:20 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-03-25 11:33:41 +00:00
|
|
|
import { parseURLParams } from '../config';
|
2018-04-12 19:58:20 +00:00
|
|
|
import JitsiMeetJS from '../lib-jitsi-meet';
|
|
|
|
import { updateSettings } from '../settings';
|
|
|
|
|
2019-03-27 17:30:56 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detects the use case when the labels are not available if the A/V permissions
|
|
|
|
* are not yet granted.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {boolean} - True if the labels are already initialized and false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
export function areDeviceLabelsInitialized(state: Object) {
|
|
|
|
if (APP.conference._localTracksInitialized) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const type of [ 'audioInput', 'audioOutput', 'videoInput' ]) {
|
2019-03-28 12:21:38 +00:00
|
|
|
if (state['features/base/devices'].devices[type].find(d => Boolean(d.label))) {
|
2019-03-27 17:30:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
/**
|
|
|
|
* Get device id of the audio output device which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getAudioOutputDeviceId() {
|
|
|
|
return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-27 17:30:56 +00:00
|
|
|
* Finds a device with a label that matches the passed label and returns its id.
|
2018-04-12 19:58:20 +00:00
|
|
|
*
|
2019-03-27 17:30:56 +00:00
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @param {string} label - The label.
|
|
|
|
* @returns {string|undefined}
|
2018-04-12 19:58:20 +00:00
|
|
|
*/
|
2019-03-27 17:30:56 +00:00
|
|
|
export function getDeviceIdByLabel(state: Object, label: string) {
|
|
|
|
const types = [ 'audioInput', 'audioOutput', 'videoInput' ];
|
|
|
|
|
|
|
|
for (const type of types) {
|
|
|
|
const device
|
2019-03-28 12:21:38 +00:00
|
|
|
= state['features/base/devices'].devices[type]
|
|
|
|
.find(d => d.label === label);
|
2019-03-27 17:30:56 +00:00
|
|
|
|
|
|
|
if (device) {
|
|
|
|
return device.deviceId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the devices set in the URL.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {Object|undefined}
|
|
|
|
*/
|
|
|
|
export function getDevicesFromURL(state: Object) {
|
|
|
|
const urlParams
|
|
|
|
= parseURLParams(state['features/base/connection'].locationURL);
|
|
|
|
|
|
|
|
const audioOutput = urlParams['devices.audioOutput'];
|
|
|
|
const videoInput = urlParams['devices.videoInput'];
|
|
|
|
const audioInput = urlParams['devices.audioInput'];
|
|
|
|
|
|
|
|
if (!audioOutput && !videoInput && !audioInput) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const devices = {};
|
|
|
|
|
|
|
|
audioOutput && (devices.audioOutput = audioOutput);
|
|
|
|
videoInput && (devices.videoInput = videoInput);
|
|
|
|
audioInput && (devices.audioInput = audioInput);
|
|
|
|
|
|
|
|
return devices;
|
2018-04-12 19:58:20 +00:00
|
|
|
}
|
2019-03-25 11:33:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts an array of media devices into an object organized by device kind.
|
|
|
|
*
|
|
|
|
* @param {Array<MediaDeviceInfo>} devices - Available media devices.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} An object with the media devices split by type. The keys
|
|
|
|
* are device type and the values are arrays with devices matching the device
|
|
|
|
* type.
|
|
|
|
*/
|
|
|
|
export function groupDevicesByKind(devices: Object[]): Object {
|
|
|
|
return {
|
|
|
|
audioInput: devices.filter(device => device.kind === 'audioinput'),
|
|
|
|
audioOutput: devices.filter(device => device.kind === 'audiooutput'),
|
|
|
|
videoInput: devices.filter(device => device.kind === 'videoinput')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-27 17:30:56 +00:00
|
|
|
* Set device id of the audio output device which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
2019-03-25 11:33:41 +00:00
|
|
|
*
|
2019-03-27 17:30:56 +00:00
|
|
|
* @param {string} newId - New audio output device id.
|
|
|
|
* @param {Function} dispatch - The Redux dispatch function.
|
|
|
|
* @returns {Promise}
|
2019-03-25 11:33:41 +00:00
|
|
|
*/
|
2019-03-27 17:30:56 +00:00
|
|
|
export function setAudioOutputDeviceId(
|
|
|
|
newId: string = 'default',
|
|
|
|
dispatch: Function): Promise<*> {
|
|
|
|
return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
|
|
|
|
.then(() =>
|
|
|
|
dispatch(updateSettings({
|
|
|
|
audioOutputDeviceId: newId
|
|
|
|
})));
|
2019-03-25 11:33:41 +00:00
|
|
|
}
|