Remove source code duplication
An error was discovered and fixed by GitHub user blackneck in jitsi/jitsi-meet PR #1017. The faulty source code was a piece of duplication though. Remove the source code duplication there to reduce the risks of bugs.
This commit is contained in:
parent
cf3ea2b8af
commit
a91deca6cd
|
@ -26,9 +26,9 @@ const JitsiTrackEvents = JitsiMeetJS.events.track;
|
||||||
export function createLocalTracks(options = {}) {
|
export function createLocalTracks(options = {}) {
|
||||||
return dispatch =>
|
return dispatch =>
|
||||||
JitsiMeetJS.createLocalTracks({
|
JitsiMeetJS.createLocalTracks({
|
||||||
|
cameraDeviceId: options.cameraDeviceId,
|
||||||
devices: options.devices || [ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ],
|
devices: options.devices || [ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ],
|
||||||
facingMode: options.facingMode || CAMERA_FACING_MODE.USER,
|
facingMode: options.facingMode || CAMERA_FACING_MODE.USER,
|
||||||
cameraDeviceId: options.cameraDeviceId,
|
|
||||||
micDeviceId: options.micDeviceId
|
micDeviceId: options.micDeviceId
|
||||||
})
|
})
|
||||||
.then(localTracks => dispatch(_updateLocalTracks(localTracks)))
|
.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 <tt>JitsiLocalTrack</tt> in a specific array/list of
|
||||||
|
* <tt>JitsiTrack</tt>s which is of a specific <tt>MEDIA_TYPE</tt>.
|
||||||
|
*
|
||||||
|
* @param {JitsiTrack[]} tracks - The array/list of <tt>JitsiTrack</tt>s to look
|
||||||
|
* through.
|
||||||
|
* @param {MEDIA_TYPE} mediaType - The <tt>MEDIA_TYPE</tt> of the first
|
||||||
|
* <tt>JitsiLocalTrack</tt> to be returned.
|
||||||
|
* @returns {JitsiLocalTrack} The first <tt>JitsiLocalTrack</tt>, if any, in the
|
||||||
|
* specified <tt>tracks</tt> of the specified <tt>mediaType</tt>.
|
||||||
|
*/
|
||||||
|
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
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} currentTracks - List of
|
||||||
* existing media tracks.
|
* current/existing media tracks.
|
||||||
* @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} newTracks - List of new media
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} newTracks - List of new media
|
||||||
* tracks.
|
* tracks.
|
||||||
* @private
|
* @private
|
||||||
|
@ -246,22 +267,18 @@ function _disposeAndRemoveTracks(tracks) {
|
||||||
* }}
|
* }}
|
||||||
*/
|
*/
|
||||||
function _getLocalTracksToChange(currentTracks, newTracks) {
|
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 tracksToAdd = [];
|
||||||
|
const tracksToRemove = [];
|
||||||
|
|
||||||
if (newLocalAudio) {
|
for (const mediaType of [ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ]) {
|
||||||
tracksToAdd.push(newLocalAudio);
|
const newTrack = _getLocalTrack(newTracks, mediaType);
|
||||||
currentLocalAudio && tracksToRemove.push(currentLocalAudio);
|
|
||||||
}
|
if (newTrack) {
|
||||||
if (newLocalVideo) {
|
const currentTrack = _getLocalTrack(currentTracks, mediaType);
|
||||||
tracksToAdd.push(newLocalVideo);
|
|
||||||
currentLocalVideo && tracksToRemove.push(currentLocalVideo);
|
tracksToAdd.push(newTrack);
|
||||||
|
currentTrack && tracksToRemove.push(currentTrack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue