event blocker
This commit is contained in:
+40
-41
@@ -11,10 +11,10 @@ export default class VideoListener {
|
||||
source: '',
|
||||
element: null,
|
||||
};
|
||||
this.isUpdating = false;
|
||||
this.server = {
|
||||
status: PLAYER_STATUS.NOT_PLAYING,
|
||||
};
|
||||
this.caughtUp = true;
|
||||
this.listener = listener;
|
||||
this.updateStatus = this.updateStatus.bind(this);
|
||||
this.firstTimeSync = this.firstTimeSync.bind(this);
|
||||
@@ -23,53 +23,53 @@ export default class VideoListener {
|
||||
}
|
||||
updateStatus(newStatus) {
|
||||
this.video = Object.assign({}, this.video, newStatus);
|
||||
if (this.server.status !== this.video.status && this.caughtUp === true) {
|
||||
if (this.video.showName) this.listener(this.video);
|
||||
if (this.server.status !== this.video.status) {
|
||||
if (this.video.showName && !this.isUpdating) this.listener(this.video);
|
||||
}
|
||||
}
|
||||
doUpdate(serverPlayer) {
|
||||
this.server = serverPlayer;
|
||||
this.caughtUp = false;
|
||||
if (serverPlayer.updatedBy === window.localStorage.getItem('watchPartyUserUid')) {
|
||||
this.caughtUp = true;
|
||||
return;
|
||||
} else {
|
||||
// SEEK
|
||||
console.log('GETTING UPDATE', serverPlayer, this.video);
|
||||
if (this.video.element) {
|
||||
switch (this.video.source) {
|
||||
case PLAYER_SOURCE.NETFLIX:
|
||||
window.postMessage({ type: 'SEEK', time: serverPlayer.time * 1000 }, '*');
|
||||
break;
|
||||
case PLAYER_SOURCE.AMAZON:
|
||||
this.video.element.play();
|
||||
this.video.element.currentTime = serverPlayer.time;
|
||||
break;
|
||||
case PLAYER_SOURCE.DISNEY:
|
||||
this.video.element.currentTime = serverPlayer.time;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (!this.isUpdating) {
|
||||
this.isUpdating = true;
|
||||
if (serverPlayer.updatedBy === window.localStorage.getItem('watchPartyUserUid')) {
|
||||
return;
|
||||
} else {
|
||||
// SEEK
|
||||
if (this.video.element) {
|
||||
switch (this.video.source) {
|
||||
case PLAYER_SOURCE.NETFLIX:
|
||||
window.postMessage({ type: 'SEEK', time: serverPlayer.time * 1000 }, '*');
|
||||
break;
|
||||
case PLAYER_SOURCE.AMAZON:
|
||||
this.video.element.play();
|
||||
this.video.element.currentTime = serverPlayer.time;
|
||||
break;
|
||||
case PLAYER_SOURCE.DISNEY:
|
||||
this.video.element.currentTime = serverPlayer.time;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// PLAY OR PAUSE
|
||||
if (this.video.element) {
|
||||
switch (serverPlayer.status) {
|
||||
case PLAYER_STATUS.PAUSED:
|
||||
this.video.element.pause();
|
||||
break;
|
||||
case PLAYER_STATUS.NOT_PLAYING:
|
||||
this.video.element.pause();
|
||||
break;
|
||||
case PLAYER_STATUS.PLAYING:
|
||||
this.video.element.play();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
// PLAY OR PAUSE
|
||||
if (this.video.element) {
|
||||
switch (serverPlayer.status) {
|
||||
case PLAYER_STATUS.PAUSED:
|
||||
this.video.element.pause();
|
||||
break;
|
||||
case PLAYER_STATUS.NOT_PLAYING:
|
||||
this.video.element.pause();
|
||||
break;
|
||||
case PLAYER_STATUS.PLAYING:
|
||||
this.video.element.play();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.isUpdating = false;
|
||||
}
|
||||
this.caughtUp = true;
|
||||
}
|
||||
timeout(n) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -130,7 +130,6 @@ export default class VideoListener {
|
||||
});
|
||||
}
|
||||
videoElement.onplay = async (ev) => {
|
||||
console.log(ev);
|
||||
this.updateStatus({
|
||||
status: PLAYER_STATUS.PLAYING,
|
||||
time: videoElement.currentTime,
|
||||
|
||||
Reference in New Issue
Block a user