2018-08-06 15:24:59 +00:00
|
|
|
import JitsiMeetJS from '../lib-jitsi-meet';
|
2019-05-07 08:53:01 +00:00
|
|
|
import {
|
|
|
|
getUserSelectedOutputDeviceId,
|
|
|
|
updateSettings
|
|
|
|
} from '../settings';
|
2018-08-06 15:24:59 +00:00
|
|
|
|
2017-03-29 17:43:30 +00:00
|
|
|
import {
|
2019-03-27 17:30:56 +00:00
|
|
|
ADD_PENDING_DEVICE_REQUEST,
|
2019-05-03 17:25:33 +00:00
|
|
|
CHECK_AND_NOTIFY_FOR_NEW_DEVICE,
|
2019-03-27 17:30:56 +00:00
|
|
|
REMOVE_PENDING_DEVICE_REQUESTS,
|
2017-03-29 17:43:30 +00:00
|
|
|
SET_AUDIO_INPUT_DEVICE,
|
|
|
|
SET_VIDEO_INPUT_DEVICE,
|
|
|
|
UPDATE_DEVICE_LIST
|
|
|
|
} from './actionTypes';
|
2019-03-27 17:30:56 +00:00
|
|
|
import {
|
|
|
|
areDeviceLabelsInitialized,
|
|
|
|
getDeviceIdByLabel,
|
2019-04-04 15:10:01 +00:00
|
|
|
getDevicesFromURL,
|
|
|
|
setAudioOutputDeviceId
|
2019-03-27 17:30:56 +00:00
|
|
|
} from './functions';
|
|
|
|
|
2019-04-04 15:10:01 +00:00
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
2019-03-27 17:30:56 +00:00
|
|
|
/**
|
|
|
|
* Adds a pending device request.
|
|
|
|
*
|
|
|
|
* @param {Object} request - The request to be added.
|
|
|
|
* @returns {{
|
|
|
|
* type: ADD_PENDING_DEVICE_REQUEST,
|
|
|
|
* request: Object
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function addPendingDeviceRequest(request) {
|
|
|
|
return {
|
|
|
|
type: ADD_PENDING_DEVICE_REQUEST,
|
|
|
|
request
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configures the initial A/V devices before the conference has started.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function configureInitialDevices() {
|
2019-04-04 15:10:01 +00:00
|
|
|
return (dispatch, getState) => {
|
2019-03-27 17:30:56 +00:00
|
|
|
const deviceLabels = getDevicesFromURL(getState());
|
2019-04-04 15:10:01 +00:00
|
|
|
let updateSettingsPromise;
|
2019-03-27 17:30:56 +00:00
|
|
|
|
|
|
|
if (deviceLabels) {
|
2019-04-04 15:10:01 +00:00
|
|
|
updateSettingsPromise = dispatch(getAvailableDevices()).then(() => {
|
2019-03-27 17:30:56 +00:00
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
if (!areDeviceLabelsInitialized(state)) {
|
|
|
|
// The labels are not available if the A/V permissions are
|
|
|
|
// not yet granted.
|
|
|
|
|
|
|
|
Object.keys(deviceLabels).forEach(key => {
|
|
|
|
dispatch(addPendingDeviceRequest({
|
|
|
|
type: 'devices',
|
|
|
|
name: 'setDevice',
|
|
|
|
device: {
|
|
|
|
kind: key.toLowerCase(),
|
|
|
|
label: deviceLabels[key]
|
|
|
|
},
|
|
|
|
// eslint-disable-next-line no-empty-function
|
|
|
|
responseCallback() {}
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const newSettings = {};
|
|
|
|
const devicesKeysToSettingsKeys = {
|
|
|
|
audioInput: 'micDeviceId',
|
|
|
|
audioOutput: 'audioOutputDeviceId',
|
|
|
|
videoInput: 'cameraDeviceId'
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(deviceLabels).forEach(key => {
|
|
|
|
const label = deviceLabels[key];
|
2019-04-08 17:03:45 +00:00
|
|
|
const deviceId = getDeviceIdByLabel(state, label, key);
|
2019-03-27 17:30:56 +00:00
|
|
|
|
|
|
|
if (deviceId) {
|
|
|
|
newSettings[devicesKeysToSettingsKeys[key]] = deviceId;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch(updateSettings(newSettings));
|
|
|
|
});
|
|
|
|
} else {
|
2019-04-04 15:10:01 +00:00
|
|
|
updateSettingsPromise = Promise.resolve();
|
2019-03-27 17:30:56 +00:00
|
|
|
}
|
2019-04-04 15:10:01 +00:00
|
|
|
|
|
|
|
return updateSettingsPromise
|
|
|
|
.then(() => {
|
2019-05-07 08:53:01 +00:00
|
|
|
const userSelectedAudioOutputDeviceId = getUserSelectedOutputDeviceId(getState());
|
2019-04-04 15:10:01 +00:00
|
|
|
|
2019-05-01 14:13:25 +00:00
|
|
|
return setAudioOutputDeviceId(userSelectedAudioOutputDeviceId, dispatch)
|
2019-04-04 15:10:01 +00:00
|
|
|
.catch(ex => logger.warn(`Failed to set audio output device.
|
|
|
|
Default audio output device will be used instead ${ex}`));
|
|
|
|
});
|
|
|
|
};
|
2019-03-27 17:30:56 +00:00
|
|
|
}
|
2017-03-29 17:43:30 +00:00
|
|
|
|
|
|
|
/**
|
2018-08-06 15:24:59 +00:00
|
|
|
* Queries for connected A/V input and output devices and updates the redux
|
|
|
|
* state of known devices.
|
2017-03-29 17:43:30 +00:00
|
|
|
*
|
2018-08-06 15:24:59 +00:00
|
|
|
* @returns {Function}
|
2017-03-29 17:43:30 +00:00
|
|
|
*/
|
2018-08-06 15:24:59 +00:00
|
|
|
export function getAvailableDevices() {
|
|
|
|
return dispatch => new Promise(resolve => {
|
|
|
|
const { mediaDevices } = JitsiMeetJS;
|
|
|
|
|
|
|
|
if (mediaDevices.isDeviceListAvailable()
|
|
|
|
&& mediaDevices.isDeviceChangeAvailable()) {
|
|
|
|
mediaDevices.enumerateDevices(devices => {
|
|
|
|
dispatch(updateDeviceList(devices));
|
|
|
|
|
|
|
|
resolve(devices);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
resolve([]);
|
|
|
|
}
|
|
|
|
});
|
2017-03-29 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 17:30:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all pending device requests.
|
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: REMOVE_PENDING_DEVICE_REQUESTS
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function removePendingDeviceRequests() {
|
|
|
|
return {
|
|
|
|
type: REMOVE_PENDING_DEVICE_REQUESTS
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:43:30 +00:00
|
|
|
/**
|
2018-08-06 15:24:59 +00:00
|
|
|
* Signals to update the currently used audio input device.
|
2017-03-29 17:43:30 +00:00
|
|
|
*
|
2018-08-06 15:24:59 +00:00
|
|
|
* @param {string} deviceId - The id of the new audio input device.
|
2017-03-29 17:43:30 +00:00
|
|
|
* @returns {{
|
2018-08-06 15:24:59 +00:00
|
|
|
* type: SET_AUDIO_INPUT_DEVICE,
|
2017-03-29 17:43:30 +00:00
|
|
|
* deviceId: string
|
|
|
|
* }}
|
|
|
|
*/
|
2018-08-06 15:24:59 +00:00
|
|
|
export function setAudioInputDevice(deviceId) {
|
2017-03-29 17:43:30 +00:00
|
|
|
return {
|
2018-08-06 15:24:59 +00:00
|
|
|
type: SET_AUDIO_INPUT_DEVICE,
|
2017-03-29 17:43:30 +00:00
|
|
|
deviceId
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals to update the currently used video input device.
|
|
|
|
*
|
|
|
|
* @param {string} deviceId - The id of the new video input device.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_VIDEO_INPUT_DEVICE,
|
|
|
|
* deviceId: string
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setVideoInputDevice(deviceId) {
|
|
|
|
return {
|
|
|
|
type: SET_VIDEO_INPUT_DEVICE,
|
|
|
|
deviceId
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals to update the list of known audio and video devices.
|
|
|
|
*
|
|
|
|
* @param {Array<MediaDeviceInfo>} devices - All known available audio input,
|
|
|
|
* audio output, and video input devices.
|
|
|
|
* @returns {{
|
|
|
|
* type: UPDATE_DEVICE_LIST,
|
|
|
|
* devices: Array<MediaDeviceInfo>
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function updateDeviceList(devices) {
|
|
|
|
return {
|
|
|
|
type: UPDATE_DEVICE_LIST,
|
|
|
|
devices
|
|
|
|
};
|
|
|
|
}
|
2019-03-25 11:33:41 +00:00
|
|
|
|
2019-05-03 17:25:33 +00:00
|
|
|
/**
|
|
|
|
* Signals to check new and old devices for newly added devices and notify.
|
|
|
|
*
|
|
|
|
* @param {Array<MediaDeviceInfo>} newDevices - Array of the new devices.
|
|
|
|
* @param {Array<MediaDeviceInfo>} oldDevices - Array of the old devices.
|
|
|
|
* @returns {{
|
|
|
|
* type: CHECK_AND_NOTIFY_FOR_NEW_DEVICE,
|
|
|
|
* newDevices: Array<MediaDeviceInfo>,
|
|
|
|
* oldDevices: Array<MediaDeviceInfo>
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function checkAndNotifyForNewDevice(newDevices, oldDevices) {
|
|
|
|
return {
|
|
|
|
type: CHECK_AND_NOTIFY_FOR_NEW_DEVICE,
|
|
|
|
newDevices,
|
|
|
|
oldDevices
|
|
|
|
};
|
|
|
|
}
|