feat: add config.startWithAudioMuted config.startWithVideoMuted

This commit is contained in:
paweldomas 2017-07-24 18:10:31 +02:00 committed by yanas
parent 68f4a4ae9f
commit d2e8b13add
2 changed files with 68 additions and 24 deletions

View File

@ -493,6 +493,10 @@ export default {
* on. * on.
* @param {boolean} options.startScreenSharing=false - if <tt>true</tt> * @param {boolean} options.startScreenSharing=false - if <tt>true</tt>
* should start with screensharing instead of camera video. * should start with screensharing instead of camera video.
* @param {boolean} options.startWithAudioMuted - will start the conference
* without any audio tracks.
* @param {boolean} options.startWithVideoMuted - will start the conference
* without any video tracks.
* @returns {Promise.<JitsiLocalTrack[], JitsiConnection>} * @returns {Promise.<JitsiLocalTrack[], JitsiConnection>}
*/ */
createInitialLocalTracksAndConnect(roomName, options = {}) { createInitialLocalTracksAndConnect(roomName, options = {}) {
@ -500,6 +504,20 @@ export default {
audioOnlyError, audioOnlyError,
screenSharingError, screenSharingError,
videoOnlyError; videoOnlyError;
const initialDevices = [];
let requestedAudio = false;
let requestedVideo = false;
if (!options.startWithAudioMuted) {
initialDevices.push('audio');
requestedAudio = true;
}
if (!options.startWithVideoMuted
&& !options.startAudioOnly
&& !options.startScreenSharing) {
initialDevices.push('video');
requestedVideo = true;
}
JitsiMeetJS.mediaDevices.addEventListener( JitsiMeetJS.mediaDevices.addEventListener(
JitsiMeetJS.events.mediaDevices.PERMISSION_PROMPT_IS_SHOWN, JitsiMeetJS.events.mediaDevices.PERMISSION_PROMPT_IS_SHOWN,
@ -508,26 +526,21 @@ export default {
mediaPermissionPromptVisibilityChanged(true, browser)) mediaPermissionPromptVisibilityChanged(true, browser))
); );
// First try to retrieve both audio and video.
let tryCreateLocalTracks; let tryCreateLocalTracks;
// FIXME the logic about trying to go audio only on error is duplicated // Enable audio only mode
if (options.startAudioOnly) { if (config.startAudioOnly) {
tryCreateLocalTracks APP.store.dispatch(toggleAudioOnly());
= createLocalTracks({ devices: ['audio'] }, true) }
.catch(err => {
audioOnlyError = err;
return []; // FIXME is there any simpler way to rewrite this spaghetti below ?
}); if (options.startScreenSharing) {
// Enable audio only mode
if (config.startAudioOnly) {
APP.store.dispatch(toggleAudioOnly());
}
} else if (options.startScreenSharing) {
tryCreateLocalTracks = this._createDesktopTrack() tryCreateLocalTracks = this._createDesktopTrack()
.then(desktopStream => { .then(desktopStream => {
if (!requestedAudio) {
return [desktopStream];
}
return createLocalTracks({ devices: ['audio'] }, true) return createLocalTracks({ devices: ['audio'] }, true)
.then(([audioStream]) => { .then(([audioStream]) => {
return [desktopStream, audioStream]; return [desktopStream, audioStream];
@ -539,26 +552,53 @@ export default {
}).catch(error => { }).catch(error => {
logger.error('Failed to obtain desktop stream', error); logger.error('Failed to obtain desktop stream', error);
screenSharingError = error; screenSharingError = error;
return createLocalTracks({ devices: ['audio'] }, true); return requestedAudio
? createLocalTracks({ devices: ['audio'] }, true)
: [];
}).catch(error => { }).catch(error => {
audioOnlyError = error; audioOnlyError = error;
return []; return [];
}); });
} else if (!requestedAudio && !requestedVideo) {
// Resolve with no tracks
tryCreateLocalTracks = Promise.resolve([]);
} else { } else {
tryCreateLocalTracks = createLocalTracks( tryCreateLocalTracks = createLocalTracks(
{devices: ['audio', 'video']}, true) { devices: initialDevices }, true)
.catch(err => {
// If failed then try to retrieve only audio.
audioAndVideoError = err;
return createLocalTracks({devices: ['audio']}, true);
})
.catch(err => { .catch(err => {
if (requestedAudio && requestedVideo) {
// Try audio only...
audioAndVideoError = err;
return createLocalTracks({devices: ['audio']}, true);
} else if (requestedAudio && !requestedVideo) {
audioOnlyError = err;
return [];
} else if (requestedVideo && !requestedAudio) {
videoOnlyError = err;
return [];
}
logger.error('Should never happen');
}).catch(err => {
// Log this just in case...
if (!requestedAudio) {
logger.error('The impossible just happened', err);
}
audioOnlyError = err; audioOnlyError = err;
// Try video only... // Try video only...
return createLocalTracks({devices: ['video']}, true); return requestedVideo
? createLocalTracks({devices: ['video']}, true)
: [];
}) })
.catch(err => { .catch(err => {
// Log this just in case...
if (!requestedVideo) {
logger.error('The impossible just happened', err);
}
videoOnlyError = err; videoOnlyError = err;
return []; return [];
@ -634,7 +674,9 @@ export default {
return this.createInitialLocalTracksAndConnect( return this.createInitialLocalTracksAndConnect(
options.roomName, { options.roomName, {
startAudioOnly: config.startAudioOnly, startAudioOnly: config.startAudioOnly,
startScreenSharing: config.startScreenSharing startScreenSharing: config.startScreenSharing,
startWithAudioMuted: config.startWithAudioMuted,
startWithVideoMuted: config.startWithVideoMuted,
}); });
}).then(([tracks, con]) => { }).then(([tracks, con]) => {
tracks.forEach(track => { tracks.forEach(track => {

View File

@ -80,6 +80,8 @@ var config = { // eslint-disable-line no-unused-vars
startScreenSharing: false, // Will try to start with screensharing instead of camera startScreenSharing: false, // Will try to start with screensharing instead of camera
// startAudioMuted: 10, // every participant after the Nth will start audio muted // startAudioMuted: 10, // every participant after the Nth will start audio muted
// startVideoMuted: 10, // every participant after the Nth will start video muted // startVideoMuted: 10, // every participant after the Nth will start video muted
startWithAudioMuted: false, // will start with the microphone muted
startWithVideoMuted: false, // will start with the camera turned off
// defaultLanguage: "en", // defaultLanguage: "en",
// To enable sending statistics to callstats.io you should provide Applicaiton ID and Secret. // To enable sending statistics to callstats.io you should provide Applicaiton ID and Secret.
// callStatsID: "", // Application ID for callstats.io API // callStatsID: "", // Application ID for callstats.io API