2018-06-20 20:19:53 +00:00
|
|
|
// @flow
|
2019-03-27 17:30:56 +00:00
|
|
|
|
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2019-03-21 12:33:40 +00:00
|
|
|
import {
|
2019-03-27 17:30:56 +00:00
|
|
|
addPendingDeviceRequest,
|
|
|
|
areDeviceLabelsInitialized,
|
2019-03-21 12:33:40 +00:00
|
|
|
getAudioOutputDeviceId,
|
2019-03-25 11:33:41 +00:00
|
|
|
getAvailableDevices,
|
2019-03-27 17:30:56 +00:00
|
|
|
getDeviceIdByLabel,
|
2019-03-25 11:33:41 +00:00
|
|
|
groupDevicesByKind,
|
2019-03-21 12:33:40 +00:00
|
|
|
setAudioInputDevice,
|
|
|
|
setAudioOutputDeviceId,
|
|
|
|
setVideoInputDevice
|
|
|
|
} from '../base/devices';
|
2018-06-20 20:19:53 +00:00
|
|
|
import JitsiMeetJS from '../base/lib-jitsi-meet';
|
|
|
|
import { toState } from '../base/redux';
|
2019-05-07 08:53:01 +00:00
|
|
|
import {
|
|
|
|
getUserSelectedCameraDeviceId,
|
|
|
|
getUserSelectedMicDeviceId,
|
|
|
|
getUserSelectedOutputDeviceId
|
|
|
|
} from '../base/settings';
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the properties for the device selection dialog from Redux state.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful -The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state.
|
|
|
|
* @returns {Object} - The properties for the device selection dialog.
|
|
|
|
*/
|
|
|
|
export function getDeviceSelectionDialogProps(stateful: Object | Function) {
|
|
|
|
const state = toState(stateful);
|
|
|
|
const settings = state['features/base/settings'];
|
2019-05-01 14:13:25 +00:00
|
|
|
const { conference } = state['features/base/conference'];
|
2021-02-02 00:20:39 +00:00
|
|
|
const { permissions } = state['features/base/devices'];
|
2019-05-01 14:13:25 +00:00
|
|
|
let disableAudioInputChange = !JitsiMeetJS.mediaDevices.isMultipleAudioInputSupported();
|
|
|
|
let selectedAudioInputId = settings.micDeviceId;
|
|
|
|
let selectedAudioOutputId = getAudioOutputDeviceId();
|
|
|
|
let selectedVideoInputId = settings.cameraDeviceId;
|
2018-06-20 20:19:53 +00:00
|
|
|
|
2019-05-01 14:13:25 +00:00
|
|
|
// audio input change will be a problem only when we are in a
|
|
|
|
// conference and this is not supported, when we open device selection on
|
|
|
|
// welcome page changing input devices will not be a problem
|
|
|
|
// on welcome page we also show only what we have saved as user selected devices
|
|
|
|
if (!conference) {
|
|
|
|
disableAudioInputChange = false;
|
2019-05-07 08:53:01 +00:00
|
|
|
selectedAudioInputId = getUserSelectedMicDeviceId(state);
|
|
|
|
selectedAudioOutputId = getUserSelectedOutputDeviceId(state);
|
|
|
|
selectedVideoInputId = getUserSelectedCameraDeviceId(state);
|
2019-05-01 14:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// we fill the device selection dialog with the devices that are currently
|
|
|
|
// used or if none are currently used with what we have in settings(user selected)
|
2018-06-20 20:19:53 +00:00
|
|
|
return {
|
2019-03-28 16:29:30 +00:00
|
|
|
availableDevices: state['features/base/devices'].availableDevices,
|
2019-05-01 14:13:25 +00:00
|
|
|
disableAudioInputChange,
|
2018-06-20 20:19:53 +00:00
|
|
|
disableDeviceChange:
|
|
|
|
!JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(),
|
2021-02-02 00:20:39 +00:00
|
|
|
hasAudioPermission: permissions.audio,
|
|
|
|
hasVideoPermission: permissions.video,
|
2018-06-20 20:19:53 +00:00
|
|
|
hideAudioInputPreview:
|
|
|
|
!JitsiMeetJS.isCollectingLocalStats(),
|
|
|
|
hideAudioOutputSelect: !JitsiMeetJS.mediaDevices
|
|
|
|
.isDeviceChangeAvailable('output'),
|
2019-05-01 14:13:25 +00:00
|
|
|
selectedAudioInputId,
|
|
|
|
selectedAudioOutputId,
|
|
|
|
selectedVideoInputId
|
2018-06-20 20:19:53 +00:00
|
|
|
};
|
|
|
|
}
|
2019-03-21 12:33:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes device requests from external applications.
|
|
|
|
*
|
|
|
|
* @param {Dispatch} dispatch - The redux {@code dispatch} function.
|
|
|
|
* @param {Function} getState - The redux function that gets/retrieves the redux
|
|
|
|
* state.
|
|
|
|
* @param {Object} request - The request to be processed.
|
|
|
|
* @param {Function} responseCallback - The callback that will send the
|
|
|
|
* response.
|
2019-03-28 16:29:30 +00:00
|
|
|
* @returns {boolean} - True if the request has been processed and false otherwise.
|
2019-03-21 12:33:40 +00:00
|
|
|
*/
|
2019-03-28 16:29:30 +00:00
|
|
|
export function processExternalDeviceRequest( // eslint-disable-line max-params
|
2019-03-27 17:30:56 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2019-03-25 11:33:41 +00:00
|
|
|
getState: Function,
|
|
|
|
request: Object,
|
|
|
|
responseCallback: Function) {
|
2019-03-28 16:29:30 +00:00
|
|
|
if (request.type !== 'devices') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const state = getState();
|
|
|
|
const settings = state['features/base/settings'];
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
switch (request.name) {
|
|
|
|
case 'isDeviceListAvailable':
|
|
|
|
responseCallback(JitsiMeetJS.mediaDevices.isDeviceListAvailable());
|
|
|
|
break;
|
|
|
|
case 'isDeviceChangeAvailable':
|
|
|
|
responseCallback(
|
|
|
|
JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(
|
|
|
|
request.deviceType));
|
|
|
|
break;
|
|
|
|
case 'isMultipleAudioInputSupported':
|
|
|
|
responseCallback(JitsiMeetJS.isMultipleAudioInputSupported());
|
|
|
|
break;
|
|
|
|
case 'getCurrentDevices':
|
|
|
|
dispatch(getAvailableDevices()).then(devices => {
|
|
|
|
if (areDeviceLabelsInitialized(state)) {
|
2019-04-03 15:06:41 +00:00
|
|
|
const deviceDescriptions = {
|
|
|
|
audioInput: undefined,
|
|
|
|
audioOutput: undefined,
|
|
|
|
videoInput: undefined
|
|
|
|
};
|
|
|
|
const currentlyUsedDeviceIds = new Set([
|
|
|
|
getAudioOutputDeviceId(),
|
|
|
|
settings.micDeviceId,
|
|
|
|
settings.cameraDeviceId
|
|
|
|
]);
|
2019-03-28 16:29:30 +00:00
|
|
|
|
|
|
|
devices.forEach(device => {
|
2019-04-03 15:06:41 +00:00
|
|
|
const { deviceId, kind } = device;
|
2019-03-28 16:29:30 +00:00
|
|
|
|
2019-04-03 15:06:41 +00:00
|
|
|
if (currentlyUsedDeviceIds.has(deviceId)) {
|
|
|
|
switch (kind) {
|
|
|
|
case 'audioinput':
|
|
|
|
deviceDescriptions.audioInput = device;
|
|
|
|
break;
|
|
|
|
case 'audiooutput':
|
|
|
|
deviceDescriptions.audioOutput = device;
|
|
|
|
break;
|
|
|
|
case 'videoinput':
|
|
|
|
deviceDescriptions.videoInput = device;
|
|
|
|
break;
|
|
|
|
}
|
2019-03-28 16:29:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-03 15:06:41 +00:00
|
|
|
responseCallback(deviceDescriptions);
|
2019-03-28 16:29:30 +00:00
|
|
|
} else {
|
|
|
|
// The labels are not available if the A/V permissions are
|
|
|
|
// not yet granted.
|
2019-03-27 17:30:56 +00:00
|
|
|
dispatch(addPendingDeviceRequest({
|
|
|
|
type: 'devices',
|
2019-03-28 16:29:30 +00:00
|
|
|
name: 'getCurrentDevices',
|
2019-03-27 17:30:56 +00:00
|
|
|
responseCallback
|
|
|
|
}));
|
|
|
|
}
|
2019-03-28 16:29:30 +00:00
|
|
|
});
|
2019-03-27 17:30:56 +00:00
|
|
|
|
2019-03-28 16:29:30 +00:00
|
|
|
break;
|
|
|
|
case 'getAvailableDevices':
|
|
|
|
dispatch(getAvailableDevices()).then(devices => {
|
|
|
|
if (areDeviceLabelsInitialized(state)) {
|
|
|
|
responseCallback(groupDevicesByKind(devices));
|
2019-03-27 17:30:56 +00:00
|
|
|
} else {
|
2019-03-28 16:29:30 +00:00
|
|
|
// The labels are not available if the A/V permissions are
|
|
|
|
// not yet granted.
|
|
|
|
dispatch(addPendingDeviceRequest({
|
|
|
|
type: 'devices',
|
|
|
|
name: 'getAvailableDevices',
|
|
|
|
responseCallback
|
|
|
|
}));
|
2019-03-21 12:33:40 +00:00
|
|
|
}
|
2019-03-28 16:29:30 +00:00
|
|
|
});
|
2019-03-21 12:33:40 +00:00
|
|
|
|
2019-03-28 16:29:30 +00:00
|
|
|
break;
|
|
|
|
case 'setDevice': {
|
|
|
|
const { device } = request;
|
|
|
|
|
2020-08-25 22:31:38 +00:00
|
|
|
if (!areDeviceLabelsInitialized(state)) {
|
2019-03-28 16:29:30 +00:00
|
|
|
dispatch(addPendingDeviceRequest({
|
|
|
|
type: 'devices',
|
|
|
|
name: 'setDevice',
|
|
|
|
device,
|
|
|
|
responseCallback
|
|
|
|
}));
|
|
|
|
|
|
|
|
return true;
|
2019-03-21 12:33:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 16:29:30 +00:00
|
|
|
const { label, id } = device;
|
2019-04-08 17:03:45 +00:00
|
|
|
const deviceId = label
|
|
|
|
? getDeviceIdByLabel(state, device.label, device.kind)
|
|
|
|
: id;
|
2019-03-28 16:29:30 +00:00
|
|
|
|
|
|
|
if (deviceId) {
|
|
|
|
switch (device.kind) {
|
|
|
|
case 'audioinput': {
|
|
|
|
dispatch(setAudioInputDevice(deviceId));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'audiooutput':
|
|
|
|
setAudioOutputDeviceId(deviceId, dispatch);
|
|
|
|
break;
|
|
|
|
case 'videoinput':
|
|
|
|
dispatch(setVideoInputDevice(deviceId));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = false;
|
2019-03-21 12:33:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 16:29:30 +00:00
|
|
|
responseCallback(result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
2019-03-21 12:33:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 16:29:30 +00:00
|
|
|
return true;
|
2019-03-21 12:33:40 +00:00
|
|
|
}
|
2019-03-28 16:29:30 +00:00
|
|
|
|