2017-10-16 19:58:38 +00:00
|
|
|
import { sendAnalyticsEvent } from '../../analytics';
|
2017-07-18 21:43:58 +00:00
|
|
|
import { JitsiTrackErrors, JitsiTrackEvents } from '../lib-jitsi-meet';
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
|
|
|
CAMERA_FACING_MODE,
|
2017-06-20 20:09:34 +00:00
|
|
|
MEDIA_TYPE,
|
|
|
|
setAudioMuted,
|
|
|
|
setVideoMuted
|
2016-10-05 14:36:59 +00:00
|
|
|
} from '../media';
|
|
|
|
import { getLocalParticipant } from '../participants';
|
|
|
|
|
2017-08-18 10:54:05 +00:00
|
|
|
import {
|
|
|
|
TRACK_ADDED,
|
2017-11-09 21:59:31 +00:00
|
|
|
TRACK_CREATE_CANCELED,
|
|
|
|
TRACK_CREATE_ERROR,
|
2017-08-18 10:54:05 +00:00
|
|
|
TRACK_REMOVED,
|
2017-11-15 15:23:22 +00:00
|
|
|
TRACK_UPDATED,
|
|
|
|
TRACK_WILL_CREATE
|
2017-08-18 10:54:05 +00:00
|
|
|
} from './actionTypes';
|
2017-08-14 13:25:37 +00:00
|
|
|
import { createLocalTracksF } from './functions';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-10-09 21:40:38 +00:00
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
2017-08-17 13:50:49 +00:00
|
|
|
/**
|
|
|
|
* Requests the creating of the desired media type tracks. Desire is expressed
|
2017-09-05 21:27:12 +00:00
|
|
|
* by base/media unless the function caller specifies desired media types
|
|
|
|
* explicitly and thus override base/media. Dispatches a
|
|
|
|
* {@code createLocalTracksA} action for the desired media types for which there
|
|
|
|
* are no existing tracks yet.
|
2017-08-17 13:50:49 +00:00
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2017-09-05 21:27:12 +00:00
|
|
|
export function createDesiredLocalTracks(...desiredTypes) {
|
2017-08-17 13:50:49 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
|
2017-09-05 21:27:12 +00:00
|
|
|
if (desiredTypes.length === 0) {
|
|
|
|
const { audio, video } = state['features/base/media'];
|
|
|
|
|
|
|
|
audio.muted || desiredTypes.push(MEDIA_TYPE.AUDIO);
|
2017-11-13 22:10:54 +00:00
|
|
|
video.muted || desiredTypes.push(MEDIA_TYPE.VIDEO);
|
2017-09-05 21:27:12 +00:00
|
|
|
}
|
2017-08-17 13:50:49 +00:00
|
|
|
|
|
|
|
const availableTypes
|
|
|
|
= state['features/base/tracks']
|
|
|
|
.filter(t => t.local)
|
|
|
|
.map(t => t.mediaType);
|
|
|
|
|
|
|
|
// We need to create the desired tracks which are not already available.
|
|
|
|
const createTypes
|
|
|
|
= desiredTypes.filter(type => availableTypes.indexOf(type) === -1);
|
|
|
|
|
|
|
|
createTypes.length
|
|
|
|
&& dispatch(createLocalTracksA({ devices: createTypes }));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Request to start capturing local audio and/or video. By default, the user
|
|
|
|
* facing camera will be selected.
|
|
|
|
*
|
|
|
|
* @param {Object} [options] - For info @see JitsiMeetJS.createLocalTracks.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2017-08-14 13:25:37 +00:00
|
|
|
export function createLocalTracksA(options = {}) {
|
2017-07-18 21:41:39 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
const devices
|
|
|
|
= options.devices || [ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ];
|
|
|
|
const store = {
|
|
|
|
dispatch,
|
|
|
|
getState
|
|
|
|
};
|
|
|
|
|
|
|
|
// The following executes on React Native only at the time of this
|
|
|
|
// writing. The effort to port Web's createInitialLocalTracksAndConnect
|
2017-08-14 13:25:37 +00:00
|
|
|
// is significant and that's where the function createLocalTracksF got
|
2017-07-18 21:41:39 +00:00
|
|
|
// born. I started with the idea a porting so that we could inherit the
|
|
|
|
// ability to getUserMedia for audio only or video only if getUserMedia
|
|
|
|
// for audio and video fails. Eventually though, I realized that on
|
|
|
|
// mobile we do not have combined permission prompts implemented anyway
|
|
|
|
// (either because there are no such prompts or it does not make sense
|
|
|
|
// to implement them) and the right thing to do is to ask for each
|
|
|
|
// device separately.
|
|
|
|
for (const device of devices) {
|
2017-11-09 21:59:31 +00:00
|
|
|
if (getState()['features/base/tracks']
|
|
|
|
.find(t => t.local && t.mediaType === device)) {
|
|
|
|
throw new Error(`Local track for ${device} already exists`);
|
|
|
|
}
|
|
|
|
|
2017-11-13 22:10:54 +00:00
|
|
|
const gumProcess
|
|
|
|
= createLocalTracksF(
|
|
|
|
{
|
|
|
|
cameraDeviceId: options.cameraDeviceId,
|
|
|
|
devices: [ device ],
|
|
|
|
facingMode:
|
|
|
|
options.facingMode || CAMERA_FACING_MODE.USER,
|
|
|
|
micDeviceId: options.micDeviceId
|
|
|
|
},
|
|
|
|
/* firePermissionPromptIsShownEvent */ false,
|
|
|
|
store)
|
|
|
|
.then(
|
|
|
|
localTracks => {
|
|
|
|
// Because GUM is called for 1 device (which is actually
|
|
|
|
// a media type 'audio', 'video', 'screen', etc.) we
|
|
|
|
// should not get more than one JitsiTrack.
|
|
|
|
if (localTracks.length !== 1) {
|
|
|
|
throw new Error(
|
|
|
|
`Expected exactly 1 track, but was given ${
|
|
|
|
localTracks.length} tracks for device: ${
|
|
|
|
device}.`);
|
|
|
|
}
|
2017-11-09 21:59:31 +00:00
|
|
|
|
2017-11-13 22:10:54 +00:00
|
|
|
if (gumProcess.canceled) {
|
|
|
|
return _disposeTracks(localTracks)
|
|
|
|
.then(() =>
|
|
|
|
dispatch(_trackCreateCanceled(device)));
|
|
|
|
}
|
2017-11-09 21:59:31 +00:00
|
|
|
|
2017-11-13 22:10:54 +00:00
|
|
|
return dispatch(trackAdded(localTracks[0]));
|
|
|
|
},
|
|
|
|
reason =>
|
|
|
|
dispatch(
|
|
|
|
gumProcess.canceled
|
|
|
|
? _trackCreateCanceled(device)
|
|
|
|
: _onCreateLocalTracksRejected(
|
|
|
|
reason,
|
|
|
|
device)));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels the {@code getUserMedia} process represented by this
|
|
|
|
* {@code Promise}.
|
|
|
|
*
|
|
|
|
* @returns {Promise} This {@code Promise} i.e. {@code gumProcess}.
|
|
|
|
*/
|
2017-11-09 21:59:31 +00:00
|
|
|
gumProcess.cancel = () => {
|
|
|
|
gumProcess.canceled = true;
|
|
|
|
|
|
|
|
return gumProcess;
|
|
|
|
};
|
|
|
|
|
|
|
|
dispatch({
|
2017-11-15 15:23:22 +00:00
|
|
|
type: TRACK_WILL_CREATE,
|
2017-11-09 21:59:31 +00:00
|
|
|
track: {
|
|
|
|
gumProcess,
|
2017-11-13 22:10:54 +00:00
|
|
|
local: true,
|
2017-11-09 21:59:31 +00:00
|
|
|
mediaType: device
|
|
|
|
}
|
|
|
|
});
|
2017-07-18 21:41:39 +00:00
|
|
|
}
|
|
|
|
};
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls JitsiLocalTrack#dispose() on all local tracks ignoring errors when
|
|
|
|
* track is already disposed. After that signals tracks to be removed.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function destroyLocalTracks() {
|
2017-11-09 21:59:31 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
// First wait until any getUserMedia in progress is settled and then get
|
|
|
|
// rid of all local tracks.
|
2017-11-13 22:10:54 +00:00
|
|
|
_cancelGUMProcesses(getState)
|
|
|
|
.then(() =>
|
|
|
|
dispatch(
|
2017-11-09 21:59:31 +00:00
|
|
|
_disposeAndRemoveTracks(
|
|
|
|
getState()['features/base/tracks']
|
|
|
|
.filter(t => t.local)
|
|
|
|
.map(t => t.jitsiTrack))));
|
|
|
|
};
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 20:09:34 +00:00
|
|
|
/**
|
|
|
|
* Replaces one track with another for one renegotiation instead of invoking
|
2017-07-18 21:43:58 +00:00
|
|
|
* two renegotiations with a separate removeTrack and addTrack. Disposes the
|
2017-06-20 20:09:34 +00:00
|
|
|
* removed track as well.
|
|
|
|
*
|
|
|
|
* @param {JitsiLocalTrack|null} oldTrack - The track to dispose.
|
|
|
|
* @param {JitsiLocalTrack|null} newTrack - The track to use instead.
|
|
|
|
* @param {JitsiConference} [conference] - The conference from which to remove
|
2017-07-18 21:43:58 +00:00
|
|
|
* and add the tracks. If one is not provided, the conference in the redux store
|
2017-06-20 20:09:34 +00:00
|
|
|
* will be used.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function replaceLocalTrack(oldTrack, newTrack, conference) {
|
|
|
|
return (dispatch, getState) => {
|
2017-08-04 21:06:42 +00:00
|
|
|
conference
|
2017-06-20 20:09:34 +00:00
|
|
|
|
2017-08-04 21:06:42 +00:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
|| (conference = getState()['features/base/conference'].conference);
|
|
|
|
|
|
|
|
return conference.replaceTrack(oldTrack, newTrack)
|
2017-06-20 20:09:34 +00:00
|
|
|
.then(() => {
|
2017-08-04 21:06:42 +00:00
|
|
|
// We call dispose after doing the replace because dispose will
|
|
|
|
// try and do a new o/a after the track removes itself. Doing it
|
|
|
|
// after means the JitsiLocalTrack.conference is already
|
|
|
|
// cleared, so it won't try and do the o/a.
|
|
|
|
const disposePromise
|
|
|
|
= oldTrack
|
|
|
|
? dispatch(_disposeAndRemoveTracks([ oldTrack ]))
|
|
|
|
: Promise.resolve();
|
2017-06-20 20:09:34 +00:00
|
|
|
|
|
|
|
return disposePromise
|
|
|
|
.then(() => {
|
|
|
|
if (newTrack) {
|
|
|
|
// The mute state of the new track should be
|
|
|
|
// reflected in the app's mute state. For example,
|
|
|
|
// if the app is currently muted and changing to a
|
|
|
|
// new track that is not muted, the app's mute
|
|
|
|
// state should be falsey. As such, emit a mute
|
|
|
|
// event here to set up the app to reflect the
|
|
|
|
// track's mute state. If this is not done, the
|
|
|
|
// current mute state of the app will be reflected
|
|
|
|
// on the track, not vice-versa.
|
2017-08-04 21:06:42 +00:00
|
|
|
const setMuted
|
|
|
|
= newTrack.isVideoTrack()
|
|
|
|
? setVideoMuted
|
|
|
|
: setAudioMuted;
|
2017-10-09 21:40:38 +00:00
|
|
|
const isMuted = newTrack.isMuted();
|
|
|
|
|
2017-10-16 19:58:38 +00:00
|
|
|
sendAnalyticsEvent(`replacetrack.${
|
|
|
|
newTrack.getType()}.${
|
2017-10-09 21:40:38 +00:00
|
|
|
isMuted ? 'muted' : 'unmuted'}`);
|
|
|
|
logger.log(`Replace ${newTrack.getType()} track - ${
|
|
|
|
isMuted ? 'muted' : 'unmuted'}`);
|
2017-06-20 20:09:34 +00:00
|
|
|
|
2017-10-17 18:20:33 +00:00
|
|
|
return dispatch(setMuted(isMuted));
|
2017-06-20 20:09:34 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
if (newTrack) {
|
|
|
|
return dispatch(_addTracks([ newTrack ]));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Create an action for when a new track has been signaled to be added to the
|
|
|
|
* conference.
|
|
|
|
*
|
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
|
|
|
|
* @returns {{ type: TRACK_ADDED, track: Track }}
|
|
|
|
*/
|
|
|
|
export function trackAdded(track) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
track.on(
|
|
|
|
JitsiTrackEvents.TRACK_MUTE_CHANGED,
|
|
|
|
() => dispatch(trackMutedChanged(track)));
|
|
|
|
track.on(
|
|
|
|
JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED,
|
|
|
|
type => dispatch(trackVideoTypeChanged(track, type)));
|
|
|
|
|
|
|
|
// participantId
|
2017-04-05 05:18:41 +00:00
|
|
|
const local = track.isLocal();
|
2016-10-05 14:36:59 +00:00
|
|
|
let participantId;
|
|
|
|
|
2017-04-05 05:18:41 +00:00
|
|
|
if (local) {
|
2016-10-05 14:36:59 +00:00
|
|
|
const participant = getLocalParticipant(getState);
|
|
|
|
|
|
|
|
if (participant) {
|
|
|
|
participantId = participant.id;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
participantId = track.getParticipantId();
|
|
|
|
}
|
|
|
|
|
|
|
|
return dispatch({
|
|
|
|
type: TRACK_ADDED,
|
|
|
|
track: {
|
|
|
|
jitsiTrack: track,
|
2017-04-05 05:18:41 +00:00
|
|
|
local,
|
2016-10-05 14:36:59 +00:00
|
|
|
mediaType: track.getType(),
|
2017-04-05 05:18:41 +00:00
|
|
|
mirror: _shouldMirror(track),
|
2016-10-05 14:36:59 +00:00
|
|
|
muted: track.isMuted(),
|
|
|
|
participantId,
|
|
|
|
videoStarted: false,
|
|
|
|
videoType: track.videoType
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an action for when a track's muted state has been signaled to be
|
|
|
|
* changed.
|
|
|
|
*
|
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
|
2017-07-18 21:43:58 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: TRACK_UPDATED,
|
|
|
|
* track: Track
|
|
|
|
* }}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
export function trackMutedChanged(track) {
|
|
|
|
return {
|
|
|
|
type: TRACK_UPDATED,
|
|
|
|
track: {
|
|
|
|
jitsiTrack: track,
|
|
|
|
muted: track.isMuted()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an action for when a track has been signaled for removal from the
|
|
|
|
* conference.
|
|
|
|
*
|
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
|
2017-07-18 21:43:58 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: TRACK_REMOVED,
|
|
|
|
* track: Track
|
|
|
|
* }}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
export function trackRemoved(track) {
|
2017-07-12 22:49:11 +00:00
|
|
|
track.removeAllListeners(JitsiTrackEvents.TRACK_MUTE_CHANGED);
|
|
|
|
track.removeAllListeners(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED);
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
|
|
|
type: TRACK_REMOVED,
|
|
|
|
track: {
|
|
|
|
jitsiTrack: track
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal that track's video started to play.
|
|
|
|
*
|
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
|
2017-07-18 21:43:58 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: TRACK_UPDATED,
|
|
|
|
* track: Track
|
|
|
|
* }}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
export function trackVideoStarted(track) {
|
|
|
|
return {
|
|
|
|
type: TRACK_UPDATED,
|
|
|
|
track: {
|
|
|
|
jitsiTrack: track,
|
|
|
|
videoStarted: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an action for when participant video type changes.
|
|
|
|
*
|
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
|
|
|
|
* @param {VIDEO_TYPE|undefined} videoType - Video type.
|
2017-07-18 21:43:58 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: TRACK_UPDATED,
|
|
|
|
* track: Track
|
|
|
|
* }}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
export function trackVideoTypeChanged(track, videoType) {
|
|
|
|
return {
|
|
|
|
type: TRACK_UPDATED,
|
|
|
|
track: {
|
|
|
|
jitsiTrack: track,
|
|
|
|
videoType
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals passed tracks to be added.
|
|
|
|
*
|
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} tracks - List of tracks.
|
|
|
|
* @private
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
function _addTracks(tracks) {
|
2017-07-18 21:43:58 +00:00
|
|
|
return dispatch => Promise.all(tracks.map(t => dispatch(trackAdded(t))));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-13 22:10:54 +00:00
|
|
|
* Cancels and waits for any {@code getUserMedia} process/currently in progress
|
|
|
|
* to complete/settle.
|
2016-10-18 14:39:17 +00:00
|
|
|
*
|
2017-11-13 22:10:54 +00:00
|
|
|
* @param {Function} getState - The redux store {@code getState} function used
|
|
|
|
* to obtain the state.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2017-11-13 22:10:54 +00:00
|
|
|
* @returns {Promise} - A {@code Promise} resolved once all
|
|
|
|
* {@code gumProcess.cancel()} {@code Promise}s are settled because all we care
|
|
|
|
* about here is to be sure that the {@code getUserMedia} callbacks have
|
|
|
|
* completed (i.e. returned from the native side).
|
2016-10-18 14:39:17 +00:00
|
|
|
*/
|
2017-11-13 22:10:54 +00:00
|
|
|
function _cancelGUMProcesses(getState) {
|
2017-11-09 21:59:31 +00:00
|
|
|
const logError
|
|
|
|
= error =>
|
2017-11-13 22:10:54 +00:00
|
|
|
logger.error('gumProcess.cancel failed', JSON.stringify(error));
|
2017-11-09 21:59:31 +00:00
|
|
|
|
|
|
|
return Promise.all(
|
|
|
|
getState()['features/base/tracks']
|
|
|
|
.filter(t => t.local)
|
2017-11-13 22:10:54 +00:00
|
|
|
.map(({ gumProcess }) =>
|
|
|
|
gumProcess && gumProcess.cancel().catch(logError)));
|
2016-10-18 14:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-09 21:59:31 +00:00
|
|
|
* Disposes passed tracks and signals them to be removed.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-11-09 21:59:31 +00:00
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} tracks - List of tracks.
|
|
|
|
* @protected
|
|
|
|
* @returns {Function}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-11-09 21:59:31 +00:00
|
|
|
export function _disposeAndRemoveTracks(tracks) {
|
|
|
|
return dispatch =>
|
|
|
|
_disposeTracks(tracks)
|
2017-11-13 22:10:54 +00:00
|
|
|
.then(() =>
|
|
|
|
Promise.all(tracks.map(t => dispatch(trackRemoved(t)))));
|
2017-11-09 21:59:31 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-11-09 21:59:31 +00:00
|
|
|
/**
|
|
|
|
* Disposes passed tracks.
|
|
|
|
*
|
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} tracks - List of tracks.
|
2017-11-13 22:10:54 +00:00
|
|
|
* @private
|
2017-11-09 21:59:31 +00:00
|
|
|
* @returns {Promise} - A Promise resolved once {@link JitsiTrack.dispose()} is
|
|
|
|
* done for every track from the list.
|
|
|
|
*/
|
|
|
|
function _disposeTracks(tracks) {
|
|
|
|
return Promise.all(
|
|
|
|
tracks.map(t =>
|
|
|
|
t.dispose()
|
|
|
|
.catch(err => {
|
2017-11-13 22:10:54 +00:00
|
|
|
// Track might be already disposed so ignore such an error.
|
|
|
|
// Of course, re-throw any other error(s).
|
2017-11-09 21:59:31 +00:00
|
|
|
if (err.name !== JitsiTrackErrors.TRACK_IS_DISPOSED) {
|
|
|
|
throw err;
|
|
|
|
}
|
2017-11-13 22:10:54 +00:00
|
|
|
})));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 21:36:25 +00:00
|
|
|
/**
|
2017-10-01 06:35:19 +00:00
|
|
|
* Implements the {@code Promise} rejection handler of
|
|
|
|
* {@code createLocalTracksA} and {@code createLocalTracksF}.
|
2017-08-22 21:36:25 +00:00
|
|
|
*
|
2017-10-01 06:35:19 +00:00
|
|
|
* @param {Object} reason - The {@code Promise} rejection reason.
|
|
|
|
* @param {string} device - The device/{@code MEDIA_TYPE} associated with the
|
2017-08-22 21:36:25 +00:00
|
|
|
* rejection.
|
|
|
|
* @private
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
function _onCreateLocalTracksRejected({ gum }, device) {
|
|
|
|
return dispatch => {
|
|
|
|
// If permissions are not allowed, alert the user.
|
|
|
|
if (gum) {
|
|
|
|
const { error } = gum;
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
// FIXME For whatever reason (which is probably an
|
|
|
|
// implementation fault), react-native-webrtc will give the
|
|
|
|
// error in one of the following formats depending on whether it
|
|
|
|
// is attached to a remote debugger or not. (The remote debugger
|
|
|
|
// scenario suggests that react-native-webrtc is at fault
|
|
|
|
// because the remote debugger is Google Chrome and then its
|
|
|
|
// JavaScript engine will define DOMException. I suspect I wrote
|
|
|
|
// react-native-webrtc to return the error in the alternative
|
|
|
|
// format if DOMException is not defined.)
|
|
|
|
let trackPermissionError;
|
|
|
|
|
|
|
|
switch (error.name) {
|
|
|
|
case 'DOMException':
|
|
|
|
trackPermissionError = error.message === 'NotAllowedError';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'NotAllowedError':
|
|
|
|
trackPermissionError = error instanceof DOMException;
|
|
|
|
break;
|
|
|
|
}
|
2017-11-09 21:59:31 +00:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: TRACK_CREATE_ERROR,
|
|
|
|
permissionDenied: trackPermissionError,
|
2017-08-22 21:36:25 +00:00
|
|
|
trackType: device
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-28 23:28:13 +00:00
|
|
|
/**
|
2017-11-13 22:10:54 +00:00
|
|
|
* Returns true if the provided {@code JitsiTrack} should be rendered as a
|
|
|
|
* mirror.
|
2017-01-28 23:28:13 +00:00
|
|
|
*
|
|
|
|
* We only want to show a video in mirrored mode when:
|
|
|
|
* 1) The video source is local, and not remote.
|
|
|
|
* 2) The video source is a camera, not a desktop (capture).
|
|
|
|
* 3) The camera is capturing the user, not the environment.
|
|
|
|
*
|
|
|
|
* TODO Similar functionality is part of lib-jitsi-meet. This function should be
|
|
|
|
* removed after https://github.com/jitsi/lib-jitsi-meet/pull/187 is merged.
|
|
|
|
*
|
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
|
|
|
|
* @private
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
function _shouldMirror(track) {
|
|
|
|
return (
|
|
|
|
track
|
|
|
|
&& track.isLocal()
|
|
|
|
&& track.isVideoTrack()
|
|
|
|
|
2017-05-08 14:43:55 +00:00
|
|
|
// XXX The type of the return value of JitsiLocalTrack's
|
|
|
|
// getCameraFacingMode happens to be named CAMERA_FACING_MODE as
|
|
|
|
// well, it's defined by lib-jitsi-meet. Note though that the type
|
|
|
|
// of the value on the right side of the equality check is defined
|
|
|
|
// by jitsi-meet. The type definitions are surely compatible today
|
|
|
|
// but that may not be the case tomorrow.
|
2017-07-18 21:43:58 +00:00
|
|
|
&& track.getCameraFacingMode() === CAMERA_FACING_MODE.USER);
|
2017-01-28 23:28:13 +00:00
|
|
|
}
|
2017-11-13 22:10:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that track create operation for given media track has been canceled.
|
|
|
|
* Will clean up local track stub from the redux state which holds the
|
|
|
|
* {@code gumProcess} reference.
|
|
|
|
*
|
|
|
|
* @param {MEDIA_TYPE} mediaType - The type of the media for which the track was
|
|
|
|
* being created.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
|
|
|
* type,
|
|
|
|
* trackType: MEDIA_TYPE
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _trackCreateCanceled(mediaType) {
|
|
|
|
return {
|
|
|
|
type: TRACK_CREATE_CANCELED,
|
|
|
|
trackType: mediaType
|
|
|
|
};
|
|
|
|
}
|