diff --git a/react/features/base/tracks/actions.js b/react/features/base/tracks/actions.js
index b5d375814..747b5d3c0 100644
--- a/react/features/base/tracks/actions.js
+++ b/react/features/base/tracks/actions.js
@@ -26,9 +26,9 @@ const JitsiTrackEvents = JitsiMeetJS.events.track;
export function createLocalTracks(options = {}) {
return dispatch =>
JitsiMeetJS.createLocalTracks({
+ cameraDeviceId: options.cameraDeviceId,
devices: options.devices || [ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ],
facingMode: options.facingMode || CAMERA_FACING_MODE.USER,
- cameraDeviceId: options.cameraDeviceId,
micDeviceId: options.micDeviceId
})
.then(localTracks => dispatch(_updateLocalTracks(localTracks)))
@@ -233,10 +233,31 @@ function _disposeAndRemoveTracks(tracks) {
}
/**
- * Determines which local media tracks should be added, and which - removed.
+ * Finds the first JitsiLocalTrack in a specific array/list of
+ * JitsiTracks which is of a specific MEDIA_TYPE.
+ *
+ * @param {JitsiTrack[]} tracks - The array/list of JitsiTracks to look
+ * through.
+ * @param {MEDIA_TYPE} mediaType - The MEDIA_TYPE of the first
+ * JitsiLocalTrack to be returned.
+ * @returns {JitsiLocalTrack} The first JitsiLocalTrack, if any, in the
+ * specified tracks of the specified mediaType.
+ */
+function _getLocalTrack(tracks, mediaType) {
+ return tracks.find(track =>
+ track.isLocal()
+
+ // XXX JitsiTrack#getType() returns a MEDIA_TYPE value in the terms
+ // of lib-jitsi-meet while mediaType is in the terms of
+ // jitsi-meet-react.
+ && track.getType() === mediaType);
+}
+
+/**
+ * Determines which local media tracks should be added and which removed.
*
* @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} currentTracks - List of
- * existing media tracks.
+ * current/existing media tracks.
* @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} newTracks - List of new media
* tracks.
* @private
@@ -246,22 +267,18 @@ function _disposeAndRemoveTracks(tracks) {
* }}
*/
function _getLocalTracksToChange(currentTracks, newTracks) {
- const currentLocalAudio
- = currentTracks.find(t => t.isLocal() && t.isAudioTrack());
- const currentLocalVideo
- = currentTracks.find(t => t.isLocal() && t.isVideoTrack());
- const newLocalAudio = newTracks.find(t => t.isLocal() && t.isAudioTrack());
- const newLocalVideo = newTracks.find(t => t.isLocal() && t.isVideoTrack());
- const tracksToRemove = [];
const tracksToAdd = [];
+ const tracksToRemove = [];
- if (newLocalAudio) {
- tracksToAdd.push(newLocalAudio);
- currentLocalAudio && tracksToRemove.push(currentLocalAudio);
- }
- if (newLocalVideo) {
- tracksToAdd.push(newLocalVideo);
- currentLocalVideo && tracksToRemove.push(currentLocalVideo);
+ for (const mediaType of [ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ]) {
+ const newTrack = _getLocalTrack(newTracks, mediaType);
+
+ if (newTrack) {
+ const currentTrack = _getLocalTrack(currentTracks, mediaType);
+
+ tracksToAdd.push(newTrack);
+ currentTrack && tracksToRemove.push(currentTrack);
+ }
}
return {