diff --git a/conference.js b/conference.js index dc2ba02490..bc8775e817 100644 --- a/conference.js +++ b/conference.js @@ -1110,7 +1110,7 @@ export default { Commands.SHARED_VIDEO, ({value, attributes}, id) => { if (attributes.state === 'stop') { - APP.UI.stopSharedVideo(id); + APP.UI.stopSharedVideo(id, attributes); } else if (attributes.state === 'start') { APP.UI.showSharedVideo(id, value, attributes); } else if (attributes.state === 'playing' diff --git a/index.html b/index.html index ba9ebf38d0..2a31fa12a8 100644 --- a/index.html +++ b/index.html @@ -126,7 +126,7 @@ - + diff --git a/lang/main.json b/lang/main.json index 59b812737b..7ac013ca43 100644 --- a/lang/main.json +++ b/lang/main.json @@ -55,7 +55,7 @@ "invite": "Invite others", "chat": "Open / close chat", "etherpad": "Shared document", - "sharedvideo": "Shared video", + "sharedvideo": "Share a YouTube video", "sharescreen": "Share screen", "fullscreen": "Enter / Exit Full Screen", "sip": "Call SIP number", diff --git a/modules/UI/UI.js b/modules/UI/UI.js index ce34923320..a60c276aae 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -1115,7 +1115,7 @@ UI.updateSharedVideo = function (id, url, attributes) { */ UI.stopSharedVideo = function (id, attributes) { if (sharedVideoManager) - sharedVideoManager.stopSharedVideo(id); + sharedVideoManager.stopSharedVideo(id, attributes); }; module.exports = UI; diff --git a/modules/UI/shared_video/SharedVideo.js b/modules/UI/shared_video/SharedVideo.js index 7b32f79903..26996e3974 100644 --- a/modules/UI/shared_video/SharedVideo.js +++ b/modules/UI/shared_video/SharedVideo.js @@ -44,7 +44,8 @@ export default class SharedVideoManager { if(APP.conference.isLocalId(this.from)) { showStopVideoPropmpt().then(() => - this.emitter.emit(UIEvents.UPDATE_SHARED_VIDEO, null, 'stop')); + this.emitter.emit( + UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop')); } else { messageHandler.openMessageDialog( "dialog.shareVideoTitle", @@ -64,6 +65,8 @@ export default class SharedVideoManager { if (this.isSharedVideoShown) return; + this.isSharedVideoShown = true; + // the video url this.url = url; @@ -82,7 +85,7 @@ export default class SharedVideoManager { // we need to operate with player after start playing // self.player will be defined once it start playing // and will process any initial attributes if any - this.initialAttributes = null; + this.initialAttributes = attributes; var self = this; if(self.isPlayerAPILoaded) @@ -148,8 +151,6 @@ export default class SharedVideoManager { SHARED_VIDEO_CONTAINER_TYPE, self.sharedVideo); VideoLayout.handleVideoThumbClicked(self.url); - self.isSharedVideoShown = true; - // If we are sending the command and we are starting the player // we need to continuously send the player current time position if(APP.conference.isLocalId(self.from)) { @@ -157,17 +158,12 @@ export default class SharedVideoManager { self.updateCheck.bind(self), updateInterval); } - - if(self.player) - self.processAttributes( - self.player, attributes, self.playerPaused); - else { - self.initialAttributes = attributes; - } }; window.onPlayerError = function(event) { - console.error("Error in the player:" + event.data); + console.error("Error in the player:", event.data); + // store the error player, so we can remove it + self.errorInPlayer = event.target; }; } @@ -184,7 +180,7 @@ export default class SharedVideoManager { if (attributes.state == 'playing') { - this.processTime(player, attributes); + this.processTime(player, attributes, playerPaused); // lets check the volume if (attributes.volume !== undefined && @@ -200,7 +196,9 @@ export default class SharedVideoManager { // if its not paused, pause it player.pauseVideo(); - this.processTime(player, attributes); + this.processTime(player, attributes, !playerPaused); + } else if (attributes.state == 'stop') { + this.stopSharedVideo(this.from); } } @@ -208,9 +206,15 @@ export default class SharedVideoManager { * Check for time in attributes and if needed seek in current player * @param player the player to operate over * @param attributes the attributes with the player state we want + * @param forceSeek whether seek should be forced */ - processTime (player, attributes) + processTime (player, attributes, forceSeek) { + if(forceSeek) { + player.seekTo(attributes.time); + return; + } + // check received time and current time let currentPosition = player.getCurrentTime(); let diff = Math.abs(attributes.time - currentPosition); @@ -230,8 +234,10 @@ export default class SharedVideoManager { updateCheck(sendPauseEvent) { // ignore update checks if we are not the owner of the video - // or there is still no player defined - if(!APP.conference.isLocalId(this.from) || !this.player) + // or there is still no player defined or we are stopped + // (in a process of stopping) + if(!APP.conference.isLocalId(this.from) || !this.player + || !this.isSharedVideoShown) return; let state = this.player.getPlayerState(); @@ -281,13 +287,22 @@ export default class SharedVideoManager { * left and we want to remove video if the user sharing it left). * @param id the id of the sender of the command */ - stopSharedVideo (id) { + stopSharedVideo (id, attributes) { if (!this.isSharedVideoShown) return; if(this.from !== id) return; + if(!this.player){ + // if there is no error in the player till now, + // store the initial attributes + if (!this.errorInPlayer) { + this.initialAttributes = attributes; + return; + } + } + if(this.intervalId) { clearInterval(this.intervalId); this.intervalId = null; @@ -300,12 +315,19 @@ export default class SharedVideoManager { VideoLayout.removeLargeVideoContainer( SHARED_VIDEO_CONTAINER_TYPE); - this.player.destroy(); - this.player = null; + if(this.player) { + this.player.destroy(); + this.player = null; + }// + else if (this.errorInPlayer) { + this.errorInPlayer.destroy(); + this.errorInPlayer = null; + } }); this.url = null; this.isSharedVideoShown = false; + this.initialAttributes = null; } }