Merge pull request #552 from damencho/shared-video-fixes

Shared video fixes
This commit is contained in:
yanas 2016-03-24 17:42:13 -05:00
commit 1e7cd06555
5 changed files with 56 additions and 27 deletions

View File

@ -402,6 +402,15 @@ export default {
listMembersIds () {
return room.getParticipants().map(p => p.getId());
},
/**
* Checks whether the participant identified by id is a moderator.
* @id id to search for participant
* @return {boolean} whether the participant is moderator
*/
isParticipantModerator (id) {
let user = room.getParticipantById(id);
return user && user.isModerator();
},
/**
* Check if SIP is supported.
* @returns {boolean}
@ -737,7 +746,7 @@ export default {
console.log('USER %s LEFT', id, user);
APP.API.notifyUserLeft(id);
APP.UI.removeUser(id, user.getDisplayName());
APP.UI.stopSharedVideo({from: id});
APP.UI.stopSharedVideo(id);
});
@ -1083,7 +1092,6 @@ export default {
room.sendCommandOnce(Commands.SHARED_VIDEO, {
value: url,
attributes: {
from: APP.conference.localId,
state: state,
time: time,
volume: volume
@ -1096,7 +1104,6 @@ export default {
room.sendCommand(Commands.SHARED_VIDEO, {
value: url,
attributes: {
from: APP.conference.localId,
state: state,
time: time,
volume: volume
@ -1105,14 +1112,25 @@ export default {
}
});
room.addCommandListener(
Commands.SHARED_VIDEO, ({value, attributes}) => {
Commands.SHARED_VIDEO, ({value, attributes}, id) => {
// if we are not the moderator or
// the command is coming from a user which is not the moderator
if (!(this.isLocalId(id) && room.isModerator())
&& !this.isParticipantModerator(id))
{
console.warn('Received shared video command ' +
'not from moderator');
return;
}
if (attributes.state === 'stop') {
APP.UI.stopSharedVideo(attributes);
APP.UI.stopSharedVideo(id, attributes);
} else if (attributes.state === 'start') {
APP.UI.showSharedVideo(value, attributes);
APP.UI.showSharedVideo(id, value, attributes);
} else if (attributes.state === 'playing'
|| attributes.state === 'pause') {
APP.UI.updateSharedVideo(value, attributes);
APP.UI.updateSharedVideo(id, value, attributes);
}
});
}

View File

@ -270,7 +270,12 @@ class FollowMe {
if (this._conference.isLocalId(id))
return;
// TODO Don't obey commands issued by non-moderators.
if (!this._conference.isParticipantModerator(id))
{
console.warn('Received follow-me command ' +
'not from moderator');
return;
}
// Applies the received/remote command to the user experience/interface
// of the local participant.

View File

@ -1107,32 +1107,35 @@ UI.updateDevicesAvailability = function (id, devices) {
};
/**
* Show shared video.
* @param {string} url video url
* @param {string} attributes
* Show shared video.
* @param {string} id the id of the sender of the command
* @param {string} url video url
* @param {string} attributes
*/
UI.showSharedVideo = function (url, attributes) {
UI.showSharedVideo = function (id, url, attributes) {
if (sharedVideoManager)
sharedVideoManager.showSharedVideo(url, attributes);
sharedVideoManager.showSharedVideo(id, url, attributes);
};
/**
* Update shared video.
* @param {string} id the id of the sender of the command
* @param {string} url video url
* @param {string} attributes
*/
UI.updateSharedVideo = function (url, attributes) {
UI.updateSharedVideo = function (id, url, attributes) {
if (sharedVideoManager)
sharedVideoManager.updateSharedVideo(url, attributes);
sharedVideoManager.updateSharedVideo(id, url, attributes);
};
/**
* Stop showing shared video.
* @param {string} id the id of the sender of the command
* @param {string} attributes
*/
UI.stopSharedVideo = function (attributes) {
UI.stopSharedVideo = function (id, attributes) {
if (sharedVideoManager)
sharedVideoManager.stopSharedVideo(attributes);
sharedVideoManager.stopSharedVideo(id, attributes);
};
module.exports = UI;

View File

@ -50,10 +50,11 @@ export default class SharedVideoManager {
/**
* Shows the player component and starts the checking function
* that will be sending updates, if we are the one shared the video
* @param id the id of the sender of the command
* @param url the video url
* @param attributes
*/
showSharedVideo (url, attributes) {
showSharedVideo (id, url, attributes) {
if (this.isSharedVideoShown)
return;
@ -61,7 +62,7 @@ export default class SharedVideoManager {
this.url = url;
// the owner of the video
this.from = attributes.from;
this.from = id;
// This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
@ -184,10 +185,11 @@ export default class SharedVideoManager {
/**
* Updates video, if its not playing and needs starting or
* if its playing and needs to be paysed
* @param id the id of the sender of the command
* @param url the video url
* @param attributes
*/
updateSharedVideo (url, attributes) {
updateSharedVideo (id, url, attributes) {
// if we are sending the event ignore
if(APP.conference.isLocalId(this.from)) {
return;
@ -196,7 +198,7 @@ export default class SharedVideoManager {
if (attributes.state == 'playing') {
if(!this.isSharedVideoShown) {
this.showSharedVideo(url, attributes);
this.showSharedVideo(id, url, attributes);
return;
}
@ -239,22 +241,23 @@ export default class SharedVideoManager {
else {
// if not shown show it, passing attributes so it can
// be shown paused
this.showSharedVideo(url, attributes);
this.showSharedVideo(id, url, attributes);
}
}
}
/**
* Stop shared video if it is currently showed. If the user started the
* shared video is the one in the attributes.from (called when user
* shared video is the one in the id (called when user
* left and we want to remove video if the user sharing it left).
* @param id the id of the sender of the command
* @param attributes
*/
stopSharedVideo (attributes) {
stopSharedVideo (id, attributes) {
if (!this.isSharedVideoShown)
return;
if(this.from !== attributes.from)
if(this.from !== id)
return;
if(this.intervalId) {

View File

@ -922,7 +922,8 @@ var VideoLayout = {
let currentId = largeVideo.id;
if (!isOnLarge || forceUpdate) {
if (id !== currentId) {
let videoType = this.getRemoteVideoType(id);
if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
}
if (currentId) {
@ -931,7 +932,6 @@ var VideoLayout = {
let smallVideo = this.getSmallVideo(id);
let videoType = this.getRemoteVideoType(id);
largeVideo.updateLargeVideo(
id,
smallVideo.videoStream,