ref(conference.js): remove global promise

Get rid of global APP.conference.screenSharingPromise.
This commit is contained in:
paweldomas 2017-06-13 14:24:34 -05:00 committed by hristoterezov
parent 01ac394e92
commit e7a4318e8c
2 changed files with 28 additions and 21 deletions

View File

@ -1109,26 +1109,32 @@ export default {
}, },
videoSwitchInProgress: false, videoSwitchInProgress: false,
/**
* Toggles between screensharing and camera video.
* @param {boolean} [shareScreen]
* @return {Promise.<T>}
*/
toggleScreenSharing(shareScreen = !this.isSharingScreen) { toggleScreenSharing(shareScreen = !this.isSharingScreen) {
if (this.videoSwitchInProgress) { if (this.videoSwitchInProgress) {
logger.warn("Switch in progress."); return Promise.reject('Switch in progress.');
return;
} }
if (!this.isDesktopSharingEnabled) { if (!this.isDesktopSharingEnabled) {
logger.warn("Cannot toggle screen sharing: not supported."); return Promise.reject(
return; 'Cannot toggle screen sharing: not supported.');
} }
if (this.isAudioOnly()) { if (this.isAudioOnly()) {
this._displayAudioOnlyTooltip('screenShare'); this._displayAudioOnlyTooltip('screenShare');
return;
return Promise.reject('No screensharing in audio only mode');
} }
this.videoSwitchInProgress = true; this.videoSwitchInProgress = true;
let externalInstallation = false; let externalInstallation = false;
if (shareScreen) { if (shareScreen) {
this.screenSharingPromise = createLocalTracks({ return createLocalTracks({
devices: ['desktop'], devices: ['desktop'],
desktopSharingExtensionExternalInstallation: { desktopSharingExtensionExternalInstallation: {
interval: 500, interval: 500,
@ -1218,7 +1224,7 @@ export default {
}); });
} else { } else {
APP.remoteControl.receiver.stop(); APP.remoteControl.receiver.stop();
this.screenSharingPromise = createLocalTracks( return createLocalTracks(
{ devices: ['video'] }) { devices: ['video'] })
.then( .then(
([stream]) => this.useVideoStream(stream) ([stream]) => this.useVideoStream(stream)

View File

@ -261,25 +261,26 @@ export default class Receiver extends RemoteControlParticipant {
action: PERMISSIONS_ACTIONS.grant action: PERMISSIONS_ACTIONS.grant
}); });
} else { } else {
APP.conference.toggleScreenSharing(); APP.conference.toggleScreenSharing()
APP.conference.screenSharingPromise.then(() => { .then(() => {
if (APP.conference.isSharingScreen) { if (APP.conference.isSharingScreen) {
this.sendRemoteControlEvent(userId, { this.sendRemoteControlEvent(userId, {
type: EVENT_TYPES.permissions, type: EVENT_TYPES.permissions,
action: PERMISSIONS_ACTIONS.grant action: PERMISSIONS_ACTIONS.grant
}); });
} else { } else {
this.sendRemoteControlEvent(userId, {
type: EVENT_TYPES.permissions,
action: PERMISSIONS_ACTIONS.error
});
}
})
.catch(() => {
this.sendRemoteControlEvent(userId, { this.sendRemoteControlEvent(userId, {
type: EVENT_TYPES.permissions, type: EVENT_TYPES.permissions,
action: PERMISSIONS_ACTIONS.error action: PERMISSIONS_ACTIONS.error
}); });
}
}).catch(() => {
this.sendRemoteControlEvent(userId, {
type: EVENT_TYPES.permissions,
action: PERMISSIONS_ACTIONS.error
}); });
});
} }
} }