[RN] Handle denied getUserMedia permissions
This commit is contained in:
@@ -1,5 +1,90 @@
|
||||
/* global APP */
|
||||
|
||||
import JitsiMeetJS, { JitsiTrackEvents } from '../lib-jitsi-meet';
|
||||
import { MEDIA_TYPE } from '../media';
|
||||
|
||||
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
||||
|
||||
/**
|
||||
* Create local tracks of specific types.
|
||||
*
|
||||
* @param {Object} options - The options with which the local tracks are to be
|
||||
* created.
|
||||
* @param {string|null} [options.cameraDeviceId] - Camera device id or
|
||||
* {@code undefined} to use app's settings.
|
||||
* @param {string[]} options.devices - Required track types such as 'audio'
|
||||
* and/or 'video'.
|
||||
* @param {string|null} [options.micDeviceId] - Microphone device id or
|
||||
* {@code undefined} to use app's settings.
|
||||
* @param {boolean} [firePermissionPromptIsShownEvent] - Whether lib-jitsi-meet
|
||||
* should check for a {@code getUserMedia} permission prompt and fire a
|
||||
* corresponding event.
|
||||
* @param {Object} store - The redux store in the context of which the function
|
||||
* is to execute and from which state such as {@code config} is to be retrieved.
|
||||
* @returns {Promise<JitsiLocalTrack[]>}
|
||||
*/
|
||||
export function createLocalTracks(
|
||||
options,
|
||||
firePermissionPromptIsShownEvent,
|
||||
store) {
|
||||
options || (options = {}); // eslint-disable-line no-param-reassign
|
||||
|
||||
let { cameraDeviceId, micDeviceId } = options;
|
||||
|
||||
if (typeof APP !== 'undefined') {
|
||||
// TODO The app's settings should go in the redux store and then the
|
||||
// reliance on the global variable APP will go away.
|
||||
if (typeof cameraDeviceId === 'undefined' || cameraDeviceId === null) {
|
||||
cameraDeviceId = APP.settings.getCameraDeviceId();
|
||||
}
|
||||
if (typeof micDeviceId === 'undefined' || micDeviceId === null) {
|
||||
micDeviceId = APP.settings.getMicDeviceId();
|
||||
}
|
||||
|
||||
store || (store = APP.store); // eslint-disable-line no-param-reassign
|
||||
}
|
||||
|
||||
const {
|
||||
firefox_fake_device, // eslint-disable-line camelcase
|
||||
resolution
|
||||
} = store.getState()['features/base/config'];
|
||||
|
||||
return (
|
||||
JitsiMeetJS.createLocalTracks(
|
||||
{
|
||||
cameraDeviceId,
|
||||
desktopSharingExtensionExternalInstallation:
|
||||
options.desktopSharingExtensionExternalInstallation,
|
||||
desktopSharingSources: options.desktopSharingSources,
|
||||
|
||||
// Copy array to avoid mutations inside library.
|
||||
devices: options.devices.slice(0),
|
||||
firefox_fake_device, // eslint-disable-line camelcase
|
||||
micDeviceId,
|
||||
resolution
|
||||
},
|
||||
firePermissionPromptIsShownEvent)
|
||||
.then(tracks => {
|
||||
// TODO JitsiTrackEvents.NO_DATA_FROM_SOURCE should probably be
|
||||
// dispatched in the redux store here and then
|
||||
// APP.UI.showTrackNotWorkingDialog should be in a middleware
|
||||
// somewhere else.
|
||||
if (typeof APP !== 'undefined') {
|
||||
tracks.forEach(track =>
|
||||
track.on(
|
||||
JitsiTrackEvents.NO_DATA_FROM_SOURCE,
|
||||
APP.UI.showTrackNotWorkingDialog.bind(null, track)));
|
||||
}
|
||||
|
||||
return tracks;
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Failed to create local tracks', options.devices, err);
|
||||
|
||||
return Promise.reject(err);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns local audio track.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user