event blocker

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