Refactor shared video manager
This commit is contained in:
parent
4a4e25de28
commit
c2f46a5cfe
|
@ -762,7 +762,7 @@ export default {
|
||||||
console.log('USER %s LEFT', id, user);
|
console.log('USER %s LEFT', id, user);
|
||||||
APP.API.notifyUserLeft(id);
|
APP.API.notifyUserLeft(id);
|
||||||
APP.UI.removeUser(id, user.getDisplayName());
|
APP.UI.removeUser(id, user.getDisplayName());
|
||||||
APP.UI.stopSharedVideo(id);
|
APP.UI.onSharedVideoStop(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1130,14 +1130,14 @@ export default {
|
||||||
this.commands.defaults.SHARED_VIDEO, ({value, attributes}, id) => {
|
this.commands.defaults.SHARED_VIDEO, ({value, attributes}, id) => {
|
||||||
|
|
||||||
if (attributes.state === 'stop') {
|
if (attributes.state === 'stop') {
|
||||||
APP.UI.stopSharedVideo(id, attributes);
|
APP.UI.onSharedVideoStop(id, attributes);
|
||||||
}
|
}
|
||||||
else if (attributes.state === 'start') {
|
else if (attributes.state === 'start') {
|
||||||
APP.UI.showSharedVideo(id, value, attributes);
|
APP.UI.onSharedVideoStart(id, value, attributes);
|
||||||
}
|
}
|
||||||
else if (attributes.state === 'playing'
|
else if (attributes.state === 'playing'
|
||||||
|| attributes.state === 'pause') {
|
|| attributes.state === 'pause') {
|
||||||
APP.UI.updateSharedVideo(id, value, attributes);
|
APP.UI.onSharedVideoUpdate(id, value, attributes);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1116,9 +1116,9 @@ UI.updateDevicesAvailability = function (id, devices) {
|
||||||
* @param {string} url video url
|
* @param {string} url video url
|
||||||
* @param {string} attributes
|
* @param {string} attributes
|
||||||
*/
|
*/
|
||||||
UI.showSharedVideo = function (id, url, attributes) {
|
UI.onSharedVideoStart = function (id, url, attributes) {
|
||||||
if (sharedVideoManager)
|
if (sharedVideoManager)
|
||||||
sharedVideoManager.showSharedVideo(id, url, attributes);
|
sharedVideoManager.onSharedVideoStart(id, url, attributes);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1127,9 +1127,9 @@ UI.showSharedVideo = function (id, url, attributes) {
|
||||||
* @param {string} url video url
|
* @param {string} url video url
|
||||||
* @param {string} attributes
|
* @param {string} attributes
|
||||||
*/
|
*/
|
||||||
UI.updateSharedVideo = function (id, url, attributes) {
|
UI.onSharedVideoUpdate = function (id, url, attributes) {
|
||||||
if (sharedVideoManager)
|
if (sharedVideoManager)
|
||||||
sharedVideoManager.updateSharedVideo(id, url, attributes);
|
sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1137,9 +1137,9 @@ UI.updateSharedVideo = function (id, url, attributes) {
|
||||||
* @param {string} id the id of the sender of the command
|
* @param {string} id the id of the sender of the command
|
||||||
* @param {string} attributes
|
* @param {string} attributes
|
||||||
*/
|
*/
|
||||||
UI.stopSharedVideo = function (id, attributes) {
|
UI.onSharedVideoStop = function (id, attributes) {
|
||||||
if (sharedVideoManager)
|
if (sharedVideoManager)
|
||||||
sharedVideoManager.stopSharedVideo(id, attributes);
|
sharedVideoManager.onSharedVideoStop(id, attributes);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = UI;
|
module.exports = UI;
|
||||||
|
|
|
@ -79,13 +79,14 @@ export default class SharedVideoManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the player component and starts the checking function
|
* Shows the player component and starts the process that will be sending
|
||||||
* that will be sending updates, if we are the one shared the video
|
* updates, if we are the one shared the video.
|
||||||
|
*
|
||||||
* @param id the id of the sender of the command
|
* @param id the id of the sender of the command
|
||||||
* @param url the video url
|
* @param url the video url
|
||||||
* @param attributes
|
* @param attributes
|
||||||
*/
|
*/
|
||||||
showSharedVideo (id, url, attributes) {
|
onSharedVideoStart (id, url, attributes) {
|
||||||
if (this.isSharedVideoShown)
|
if (this.isSharedVideoShown)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -153,6 +154,10 @@ export default class SharedVideoManager {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that a change in state has occurred for the shared video.
|
||||||
|
* @param event the event notifying us of the change
|
||||||
|
*/
|
||||||
window.onPlayerStateChange = function(event) {
|
window.onPlayerStateChange = function(event) {
|
||||||
if (event.data == YT.PlayerState.PLAYING) {
|
if (event.data == YT.PlayerState.PLAYING) {
|
||||||
|
|
||||||
|
@ -160,19 +165,19 @@ export default class SharedVideoManager {
|
||||||
|
|
||||||
if(self.initialAttributes)
|
if(self.initialAttributes)
|
||||||
{
|
{
|
||||||
self.processAttributes(
|
// If a network update has occurred already now is the
|
||||||
|
// time to process it.
|
||||||
|
self.processVideoUpdate(
|
||||||
self.player,
|
self.player,
|
||||||
self.initialAttributes,
|
self.initialAttributes);
|
||||||
false);
|
|
||||||
|
|
||||||
self.initialAttributes = null;
|
self.initialAttributes = null;
|
||||||
}
|
}
|
||||||
self.smartMute();
|
self.smartAudioMute();
|
||||||
self.updateCheck();
|
|
||||||
} else if (event.data == YT.PlayerState.PAUSED) {
|
} else if (event.data == YT.PlayerState.PAUSED) {
|
||||||
self.smartUnmute();
|
self.smartAudioUnmute();
|
||||||
self.updateCheck(true);
|
|
||||||
}
|
}
|
||||||
|
self.fireSharedVideoEvent(event.data == YT.PlayerState.PAUSED);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,7 +187,7 @@ export default class SharedVideoManager {
|
||||||
window.onVideoProgress = function (event) {
|
window.onVideoProgress = function (event) {
|
||||||
let state = event.target.getPlayerState();
|
let state = event.target.getPlayerState();
|
||||||
if (state == YT.PlayerState.PAUSED) {
|
if (state == YT.PlayerState.PAUSED) {
|
||||||
self.updateCheck(true);
|
self.fireSharedVideoEvent(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -191,14 +196,14 @@ export default class SharedVideoManager {
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
window.onVolumeChange = function (event) {
|
window.onVolumeChange = function (event) {
|
||||||
self.updateCheck();
|
self.fireSharedVideoEvent();
|
||||||
|
|
||||||
// let's check, if player is not muted lets mute locally
|
// let's check, if player is not muted lets mute locally
|
||||||
if(event.data.volume > 0 && !event.data.muted) {
|
if(event.data.volume > 0 && !event.data.muted) {
|
||||||
self.smartMute();
|
self.smartAudioMute();
|
||||||
}
|
}
|
||||||
else if (event.data.volume <=0 || event.data.muted) {
|
else if (event.data.volume <=0 || event.data.muted) {
|
||||||
self.smartUnmute();
|
self.smartAudioUnmute();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -230,7 +235,7 @@ export default class SharedVideoManager {
|
||||||
// we need to continuously send the player current time position
|
// we need to continuously send the player current time position
|
||||||
if(APP.conference.isLocalId(self.from)) {
|
if(APP.conference.isLocalId(self.from)) {
|
||||||
self.intervalId = setInterval(
|
self.intervalId = setInterval(
|
||||||
self.updateCheck.bind(self),
|
self.fireSharedVideoEvent.bind(self),
|
||||||
updateInterval);
|
updateInterval);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -246,28 +251,24 @@ export default class SharedVideoManager {
|
||||||
* Process attributes, whether player needs to be paused or seek.
|
* Process attributes, whether player needs to be paused or seek.
|
||||||
* @param player the player to operate over
|
* @param player the player to operate over
|
||||||
* @param attributes the attributes with the player state we want
|
* @param attributes the attributes with the player state we want
|
||||||
* @param playerPaused current saved state for the player
|
|
||||||
*/
|
*/
|
||||||
processAttributes (player, attributes, playerPaused)
|
processVideoUpdate (player, attributes)
|
||||||
{
|
{
|
||||||
if(!attributes)
|
if(!attributes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (attributes.state == 'playing') {
|
if (attributes.state == 'playing') {
|
||||||
|
|
||||||
this.processTime(player, attributes, playerPaused);
|
let isPlayerPaused
|
||||||
|
= (this.player.getPlayerState() === YT.PlayerState.PAUSED);
|
||||||
|
|
||||||
|
// If our player is currently paused force the seek.
|
||||||
|
this.processTime(player, attributes, isPlayerPaused);
|
||||||
|
|
||||||
|
// Process mute.
|
||||||
let isAttrMuted = (attributes.muted === "true");
|
let isAttrMuted = (attributes.muted === "true");
|
||||||
|
if (player.isMuted() !== isAttrMuted) {
|
||||||
// Process player unmute
|
this.smartPlayerMute(isAttrMuted, true);
|
||||||
if (player.isMuted() && !isAttrMuted) {
|
|
||||||
console.log("Process player unmute and smart mike mute.");
|
|
||||||
this.mutePlayer(false);
|
|
||||||
}
|
|
||||||
// Process player mute
|
|
||||||
else if (!player.isMuted() && isAttrMuted) {
|
|
||||||
console.log("Process player mute and smart mike unmute.");
|
|
||||||
this.mutePlayer(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process volume
|
// Process volume
|
||||||
|
@ -280,7 +281,7 @@ export default class SharedVideoManager {
|
||||||
this.showSharedVideoMutedPopup(false);
|
this.showSharedVideoMutedPopup(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerPaused)
|
if (isPlayerPaused)
|
||||||
player.playVideo();
|
player.playVideo();
|
||||||
|
|
||||||
} else if (attributes.state == 'pause') {
|
} else if (attributes.state == 'pause') {
|
||||||
|
@ -288,8 +289,6 @@ export default class SharedVideoManager {
|
||||||
player.pauseVideo();
|
player.pauseVideo();
|
||||||
|
|
||||||
this.processTime(player, attributes, true);
|
this.processTime(player, attributes, true);
|
||||||
} else if (attributes.state == 'stop') {
|
|
||||||
this.stopSharedVideo(this.from);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +322,7 @@ export default class SharedVideoManager {
|
||||||
/**
|
/**
|
||||||
* Checks current state of the player and fire an event with the values.
|
* Checks current state of the player and fire an event with the values.
|
||||||
*/
|
*/
|
||||||
updateCheck(sendPauseEvent)
|
fireSharedVideoEvent(sendPauseEvent)
|
||||||
{
|
{
|
||||||
// ignore update checks if we are not the owner of the video
|
// ignore update checks if we are not the owner of the video
|
||||||
// or there is still no player defined or we are stopped
|
// or there is still no player defined or we are stopped
|
||||||
|
@ -356,22 +355,21 @@ export default class SharedVideoManager {
|
||||||
* @param url the video url
|
* @param url the video url
|
||||||
* @param attributes
|
* @param attributes
|
||||||
*/
|
*/
|
||||||
updateSharedVideo (id, url, attributes) {
|
onSharedVideoUpdate (id, url, attributes) {
|
||||||
// if we are sending the event ignore
|
// if we are sending the event ignore
|
||||||
if(APP.conference.isLocalId(this.from)) {
|
if(APP.conference.isLocalId(this.from)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.isSharedVideoShown) {
|
if(!this.isSharedVideoShown) {
|
||||||
this.showSharedVideo(id, url, attributes);
|
this.onSharedVideoStart(id, url, attributes);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.player)
|
if(!this.player)
|
||||||
this.initialAttributes = attributes;
|
this.initialAttributes = attributes;
|
||||||
else {
|
else {
|
||||||
this.processAttributes(this.player, attributes,
|
this.processVideoUpdate(this.player, attributes);
|
||||||
(this.player.getPlayerState() === YT.PlayerState.PAUSED));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,7 +379,7 @@ export default class SharedVideoManager {
|
||||||
* left and we want to remove video if the user sharing it left).
|
* left and we want to remove video if the user sharing it left).
|
||||||
* @param id the id of the sender of the command
|
* @param id the id of the sender of the command
|
||||||
*/
|
*/
|
||||||
stopSharedVideo (id, attributes) {
|
onSharedVideoStop (id, attributes) {
|
||||||
if (!this.isSharedVideoShown)
|
if (!this.isSharedVideoShown)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -421,7 +419,7 @@ export default class SharedVideoManager {
|
||||||
this.errorInPlayer.destroy();
|
this.errorInPlayer.destroy();
|
||||||
this.errorInPlayer = null;
|
this.errorInPlayer = null;
|
||||||
}
|
}
|
||||||
this.smartUnmute();
|
this.smartAudioUnmute();
|
||||||
// revert to original behavior (prevents pausing
|
// revert to original behavior (prevents pausing
|
||||||
// for participants not sharing the video to pause it)
|
// for participants not sharing the video to pause it)
|
||||||
$("#sharedVideo").css("pointer-events","auto");
|
$("#sharedVideo").css("pointer-events","auto");
|
||||||
|
@ -446,27 +444,32 @@ export default class SharedVideoManager {
|
||||||
this.mutedWithUserInteraction = userInteraction;
|
this.mutedWithUserInteraction = userInteraction;
|
||||||
}
|
}
|
||||||
else if (this.player.getPlayerState() !== YT.PlayerState.PAUSED) {
|
else if (this.player.getPlayerState() !== YT.PlayerState.PAUSED) {
|
||||||
this.mutePlayer(true);
|
this.smartPlayerMute(true, false);
|
||||||
|
// Check if we need to update other participants
|
||||||
|
this.fireSharedVideoEvent();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutes / unmutes the player.
|
* Mutes / unmutes the player.
|
||||||
* @param mute true to mute the shared video, false - otherwise.
|
* @param mute true to mute the shared video, false - otherwise.
|
||||||
|
* @param {boolean} Indicates if this mute is a consequence of a network
|
||||||
|
* video update or is called locally.
|
||||||
*/
|
*/
|
||||||
mutePlayer(mute) {
|
smartPlayerMute(mute, isVideoUpdate) {
|
||||||
if (!this.player.isMuted() && mute) {
|
if (!this.player.isMuted() && mute) {
|
||||||
this.player.mute();
|
this.player.mute();
|
||||||
this.smartUnmute();
|
|
||||||
|
if (isVideoUpdate)
|
||||||
|
this.smartAudioUnmute();
|
||||||
}
|
}
|
||||||
else if (this.player.isMuted() && !mute) {
|
else if (this.player.isMuted() && !mute) {
|
||||||
this.player.unMute();
|
this.player.unMute();
|
||||||
this.smartMute();
|
if (isVideoUpdate)
|
||||||
|
this.smartAudioMute();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we need to update other participants
|
|
||||||
this.updateCheck();
|
|
||||||
|
|
||||||
this.showSharedVideoMutedPopup(mute);
|
this.showSharedVideoMutedPopup(mute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +478,7 @@ export default class SharedVideoManager {
|
||||||
* by the user via the mike button and the volume of the shared video is on
|
* by the user via the mike button and the volume of the shared video is on
|
||||||
* we're unmuting the mike automatically.
|
* we're unmuting the mike automatically.
|
||||||
*/
|
*/
|
||||||
smartUnmute() {
|
smartAudioUnmute() {
|
||||||
if (APP.conference.isLocalAudioMuted()
|
if (APP.conference.isLocalAudioMuted()
|
||||||
&& !this.mutedWithUserInteraction
|
&& !this.mutedWithUserInteraction
|
||||||
&& !this.isSharedVideoVolumeOn()) {
|
&& !this.isSharedVideoVolumeOn()) {
|
||||||
|
@ -489,7 +492,7 @@ export default class SharedVideoManager {
|
||||||
* Smart mike mute. If the mike isn't currently muted and the shared video
|
* Smart mike mute. If the mike isn't currently muted and the shared video
|
||||||
* volume is on we mute the mike.
|
* volume is on we mute the mike.
|
||||||
*/
|
*/
|
||||||
smartMute() {
|
smartAudioMute() {
|
||||||
if (!APP.conference.isLocalAudioMuted()
|
if (!APP.conference.isLocalAudioMuted()
|
||||||
&& this.isSharedVideoVolumeOn()) {
|
&& this.isSharedVideoVolumeOn()) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue