From 9a984b7f84483775d75c6796c8d2d3941c1746d9 Mon Sep 17 00:00:00 2001 From: damencho Date: Thu, 31 Mar 2016 15:32:13 -0500 Subject: [PATCH 1/4] Instantly update volume changes. --- modules/UI/shared_video/SharedVideo.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/UI/shared_video/SharedVideo.js b/modules/UI/shared_video/SharedVideo.js index 26996e397..a5a3b3316 100644 --- a/modules/UI/shared_video/SharedVideo.js +++ b/modules/UI/shared_video/SharedVideo.js @@ -119,6 +119,10 @@ export default class SharedVideoManager { self.player = event.target; + // add listener for volume changes + self.player.addEventListener( + "onVolumeChange", "onVolumeChange"); + if(self.initialAttributes) { self.processAttributes( @@ -133,6 +137,17 @@ export default class SharedVideoManager { } }; + /** + * Gets notified for volume state changed. + * @param event + */ + window.onVolumeChange = function (event) { + if(!self.player) + return; + + self.updateCheck(); + }; + window.onPlayerReady = function(event) { let player = event.target; // do not relay on autoplay as it is not sending all of the events From bede8feccc38350e7f7a7f8bf5cbe1b597ca2950 Mon Sep 17 00:00:00 2001 From: damencho Date: Fri, 1 Apr 2016 14:53:11 -0500 Subject: [PATCH 2/4] Mutes local video when shared video is playing and mutes shared video if user wants to talk. --- modules/UI/shared_video/SharedVideo.js | 77 ++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 10 deletions(-) diff --git a/modules/UI/shared_video/SharedVideo.js b/modules/UI/shared_video/SharedVideo.js index a5a3b3316..93a9023dc 100644 --- a/modules/UI/shared_video/SharedVideo.js +++ b/modules/UI/shared_video/SharedVideo.js @@ -73,6 +73,10 @@ export default class SharedVideoManager { // the owner of the video this.from = id; + //listen for local audio mute events + this.localAudioMutedListener = this.localAudioMuted.bind(this); + this.emitter.on(UIEvents.AUDIO_MUTED, this.localAudioMutedListener); + // This code loads the IFrame Player API code asynchronously. var tag = document.createElement('script'); @@ -110,7 +114,8 @@ export default class SharedVideoManager { 'onStateChange': onPlayerStateChange, 'onError': onPlayerError } - }); + }).addEventListener(// add listener for volume changes + "onVolumeChange", "onVolumeChange"); }; window.onPlayerStateChange = function(event) { @@ -119,10 +124,6 @@ export default class SharedVideoManager { self.player = event.target; - // add listener for volume changes - self.player.addEventListener( - "onVolumeChange", "onVolumeChange"); - if(self.initialAttributes) { self.processAttributes( @@ -142,10 +143,14 @@ export default class SharedVideoManager { * @param event */ window.onVolumeChange = function (event) { - if(!self.player) - return; - self.updateCheck(); + + // let's check, if player is not muted lets mute locally + if(event.data.volume > 0 && !event.data.muted + && !APP.conference.isLocalAudioMuted()){ + self.emitter.emit(UIEvents.AUDIO_MUTED, true); + self.notifyUserComfortableMicMute(true); + } }; window.onPlayerReady = function(event) { @@ -199,9 +204,11 @@ export default class SharedVideoManager { // lets check the volume if (attributes.volume !== undefined && - player.getVolume() != attributes.volume) { + player.getVolume() != attributes.volume + && APP.conference.isLocalAudioMuted()) { player.setVolume(attributes.volume); console.info("Player change of volume:" + attributes.volume); + this.notifyUserComfortableVideoMute(false); } if(playerPaused) @@ -323,6 +330,10 @@ export default class SharedVideoManager { this.intervalId = null; } + this.emitter.removeListener(UIEvents.AUDIO_MUTED, + this.localAudioMutedListener); + this.localAudioMutedListener = null; + VideoLayout.removeParticipantContainer(this.url); VideoLayout.showLargeVideoContainer(SHARED_VIDEO_CONTAINER_TYPE, false) @@ -333,7 +344,7 @@ export default class SharedVideoManager { if(this.player) { this.player.destroy(); this.player = null; - }// + } // if there is an error in player, remove that instance else if (this.errorInPlayer) { this.errorInPlayer.destroy(); this.errorInPlayer = null; @@ -344,6 +355,52 @@ export default class SharedVideoManager { this.isSharedVideoShown = false; this.initialAttributes = null; } + + /** + * Receives events for local audio mute/unmute by local user. + * @param muted boolena whether it is muted or not. + */ + localAudioMuted (muted) { + if(!this.player) + return; + + if(muted) + return; + + // if we are un-muting and player is not muted, lets muted + // to not pollute the conference + if(this.player.getVolume() > 0 || !this.player.isMuted()){ + this.player.setVolume(0); + this.notifyUserComfortableVideoMute(true); + } + } + + /** + * Notifies user for muting its audio due to video is unmuted. + * @param show boolean, show or hide the notification + */ + notifyUserComfortableMicMute (show) { + if(show) { + this.notifyUserComfortableVideoMute(false); + console.log("Your audio was muted to enjoy the video"); + } + else + console.log("Hide notification local audio muted"); + } + + /** + * Notifies user for muting the video due to audio is unmuted. + * @param show boolean, show or hide the notification + */ + notifyUserComfortableVideoMute (show) { + if(show) { + this.notifyUserComfortableMicMute(false); + console.log( + "Your shared video was muted in order to speak freely!"); + } + else + console.log("Hide notification share video muted"); + } } /** From 7dad981112565a6f072adc6222d317180a489a30 Mon Sep 17 00:00:00 2001 From: damencho Date: Fri, 1 Apr 2016 17:08:35 -0500 Subject: [PATCH 3/4] Follow seeking while player is paused. --- modules/UI/shared_video/SharedVideo.js | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/UI/shared_video/SharedVideo.js b/modules/UI/shared_video/SharedVideo.js index 93a9023dc..fb7875442 100644 --- a/modules/UI/shared_video/SharedVideo.js +++ b/modules/UI/shared_video/SharedVideo.js @@ -98,7 +98,7 @@ export default class SharedVideoManager { window.onYouTubeIframeAPIReady = function() { self.isPlayerAPILoaded = true; let showControls = APP.conference.isLocalId(self.from) ? 1 : 0; - new YT.Player('sharedVideoIFrame', { + let p = new YT.Player('sharedVideoIFrame', { height: '100%', width: '100%', videoId: self.url, @@ -114,8 +114,19 @@ export default class SharedVideoManager { 'onStateChange': onPlayerStateChange, 'onError': onPlayerError } - }).addEventListener(// add listener for volume changes + }); + + // add listener for volume changes + p.addEventListener( "onVolumeChange", "onVolumeChange"); + + if (APP.conference.isLocalId(self.from)){ + // adds progress listener that will be firing events + // while we are paused and we change the progress of the + // video (seeking forward or backward on the video) + p.addEventListener( + "onVideoProgress", "onVideoProgress"); + } }; window.onPlayerStateChange = function(event) { @@ -138,6 +149,17 @@ export default class SharedVideoManager { } }; + /** + * Track player progress while paused. + * @param event + */ + window.onVideoProgress = function (event) { + let state = event.target.getPlayerState(); + if (state == YT.PlayerState.PAUSED) { + self.updateCheck(true); + } + }; + /** * Gets notified for volume state changed. * @param event @@ -218,7 +240,7 @@ export default class SharedVideoManager { // if its not paused, pause it player.pauseVideo(); - this.processTime(player, attributes, !playerPaused); + this.processTime(player, attributes, true); } else if (attributes.state == 'stop') { this.stopSharedVideo(this.from); } @@ -233,6 +255,7 @@ export default class SharedVideoManager { processTime (player, attributes, forceSeek) { if(forceSeek) { + console.info("Player seekTo:", attributes.time); player.seekTo(attributes.time); return; } From b949ffdda1b7bf7dbdb70b2854ac909f42d5ef7a Mon Sep 17 00:00:00 2001 From: damencho Date: Fri, 1 Apr 2016 17:23:30 -0500 Subject: [PATCH 4/4] Prevents users that are not sharing the video of pausing the video and leaves the control to the user sharing the video. --- modules/UI/shared_video/SharedVideo.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/UI/shared_video/SharedVideo.js b/modules/UI/shared_video/SharedVideo.js index fb7875442..a57a41fc3 100644 --- a/modules/UI/shared_video/SharedVideo.js +++ b/modules/UI/shared_video/SharedVideo.js @@ -189,6 +189,12 @@ export default class SharedVideoManager { self.sharedVideo = new SharedVideoContainer( {url, iframe, player}); + //prevents pausing participants not sharing the video + // to pause the video + if (!APP.conference.isLocalId(self.from)) { + $("#sharedVideo").css("pointer-events","none"); + } + VideoLayout.addLargeVideoContainer( SHARED_VIDEO_CONTAINER_TYPE, self.sharedVideo); VideoLayout.handleVideoThumbClicked(self.url); @@ -372,6 +378,9 @@ export default class SharedVideoManager { this.errorInPlayer.destroy(); this.errorInPlayer = null; } + // revert to original behavior (prevents pausing + // for participants not sharing the video to pause it) + $("#sharedVideo").css("pointer-events","auto"); }); this.url = null;