Handle cases when new media devices are added/removed more precisely and more predictable
This commit is contained in:
parent
b270256a7a
commit
c1807c3649
|
@ -22,6 +22,7 @@ const TrackEvents = JitsiMeetJS.events.track;
|
||||||
const TrackErrors = JitsiMeetJS.errors.track;
|
const TrackErrors = JitsiMeetJS.errors.track;
|
||||||
|
|
||||||
let room, connection, localAudio, localVideo, roomLocker;
|
let room, connection, localAudio, localVideo, roomLocker;
|
||||||
|
let currentAudioInputDevices, currentVideoInputDevices;
|
||||||
|
|
||||||
import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/LargeVideo";
|
import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/LargeVideo";
|
||||||
|
|
||||||
|
@ -197,6 +198,17 @@ function createLocalTracks (devices, cameraDeviceId, micDeviceId) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores lists of current 'audioinput' and 'videoinput' devices
|
||||||
|
* @param {MediaDeviceInfo[]} devices
|
||||||
|
*/
|
||||||
|
function setCurrentMediaDevices(devices) {
|
||||||
|
currentAudioInputDevices = devices.filter(
|
||||||
|
d => d.kind === 'audioinput');
|
||||||
|
currentVideoInputDevices = devices.filter(
|
||||||
|
d => d.kind === 'videoinput');
|
||||||
|
}
|
||||||
|
|
||||||
class ConferenceConnector {
|
class ConferenceConnector {
|
||||||
constructor(resolve, reject) {
|
constructor(resolve, reject) {
|
||||||
this._resolve = resolve;
|
this._resolve = resolve;
|
||||||
|
@ -408,6 +420,8 @@ export default {
|
||||||
localVideo.getDeviceId());
|
localVideo.getDeviceId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCurrentMediaDevices(devices);
|
||||||
|
|
||||||
APP.UI.onAvailableDevicesChanged(devices);
|
APP.UI.onAvailableDevicesChanged(devices);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -419,6 +433,8 @@ export default {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
checkLocalDevicesAfterDeviceListChanged(devices)
|
checkLocalDevicesAfterDeviceListChanged(devices)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
setCurrentMediaDevices(devices);
|
||||||
|
|
||||||
APP.UI.onAvailableDevicesChanged(devices);
|
APP.UI.onAvailableDevicesChanged(devices);
|
||||||
});
|
});
|
||||||
}, 0);
|
}, 0);
|
||||||
|
@ -453,6 +469,12 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkLocalDevicesAfterDeviceListChanged(newDevices) {
|
function checkLocalDevicesAfterDeviceListChanged(newDevices) {
|
||||||
|
// Event handler can be fire before direct enumerateDevices()
|
||||||
|
// call, so handle this situation here.
|
||||||
|
if (!currentAudioInputDevices && !currentVideoInputDevices) {
|
||||||
|
setCurrentMediaDevices(newDevices);
|
||||||
|
}
|
||||||
|
|
||||||
checkAudioOutputDeviceAfterDeviceListChanged(newDevices);
|
checkAudioOutputDeviceAfterDeviceListChanged(newDevices);
|
||||||
|
|
||||||
let availableAudioInputDevices = newDevices.filter(
|
let availableAudioInputDevices = newDevices.filter(
|
||||||
|
@ -555,39 +577,49 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTracksCreated(tracks) {
|
function onTracksCreated(tracks) {
|
||||||
tracks && tracks.forEach(track => {
|
return Promise.all((tracks || []).map(track => {
|
||||||
if (track.isAudioTrack()) {
|
if (track.isAudioTrack()) {
|
||||||
self.useAudioStream(track).then(() => {
|
let audioWasMuted = self.audioMuted;
|
||||||
|
|
||||||
|
return self.useAudioStream(track).then(() => {
|
||||||
console.log('switched local audio');
|
console.log('switched local audio');
|
||||||
|
|
||||||
// If we have more than 1 device - mute.
|
// If we plugged-in new device (and switched to
|
||||||
// We check with 2 for audio, because
|
// it), but video was muted before, or we
|
||||||
// it always has 'default' if device is
|
// unplugged current device and selected new
|
||||||
// available at all.
|
// one, then mute new video track.
|
||||||
// TODO: this is not 100% solution - need
|
if (audioWasMuted ||
|
||||||
// to investigate more
|
currentAudioInputDevices.length >
|
||||||
if (availableAudioInputDevices.length > 2) {
|
availableAudioInputDevices.length) {
|
||||||
muteLocalAudio(true);
|
muteLocalAudio(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (track.isVideoTrack()) {
|
} else if (track.isVideoTrack()) {
|
||||||
self.useVideoStream(track).then(() => {
|
let videoWasMuted = self.videoMuted;
|
||||||
|
|
||||||
|
return self.useVideoStream(track).then(() => {
|
||||||
console.log('switched local video');
|
console.log('switched local video');
|
||||||
|
|
||||||
// TODO: maybe make video large if we
|
// TODO: maybe make video large if we
|
||||||
// are not in conference yet
|
// are not in conference yet
|
||||||
// If we have more than 1 device - mute.
|
|
||||||
// TODO: this is not 100% solution - need
|
// If we plugged-in new device (and switched to
|
||||||
// to investigate more
|
// it), but video was muted before, or we
|
||||||
if (availableVideoInputDevices.length > 1) {
|
// unplugged current device and selected new
|
||||||
|
// one, then mute new video track.
|
||||||
|
if (videoWasMuted ||
|
||||||
|
(currentVideoInputDevices.length >
|
||||||
|
availableVideoInputDevices.length)) {
|
||||||
muteLocalVideo(true);
|
muteLocalVideo(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error("Ignored not an audio nor a "
|
console.error("Ignored not an audio nor a "
|
||||||
+ "video track: ", track);
|
+ "video track: ", track);
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue