speculative loop fix

This commit is contained in:
Ayushya Amitabh
2020-05-06 12:57:44 -04:00
parent c4bb242d7a
commit 41c3f73f34
+12 -11
View File
@@ -14,6 +14,7 @@ export default class VideoListener {
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);
@@ -22,24 +23,23 @@ 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) { if (this.server.status !== this.video.status && this.caughtUp === true) {
if (this.video.showName) this.listener(this.video); if (this.video.showName) this.listener(this.video);
} }
} }
doUpdate(serverPlayer) { doUpdate(serverPlayer) {
this.server = serverPlayer; this.server = serverPlayer;
if (serverPlayer.updatedBy === window.localStorage.getItem('watchPartyUserUid')) return; this.caughtUp = false;
else { if (serverPlayer.updatedBy === window.localStorage.getItem('watchPartyUserUid')) {
this.caughtUp = true;
return;
} else {
// SEEK // SEEK
console.log('GETTING UPDATE', serverPlayer, this.video); 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:
if ( this.video.element.pause();
this.server.status === PLAYER_STATUS.PAUSED &&
this.video.status === PLAYER_STATUS.PLAYING
)
this.video.element.pause();
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:
@@ -70,6 +70,7 @@ export default class VideoListener {
} }
} }
} }
this.caughtUp = true;
} }
timeout(n) { timeout(n) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -143,9 +144,9 @@ export default class VideoListener {
time: videoElement.currentTime, time: videoElement.currentTime,
showName: await this.getShowName(), showName: await this.getShowName(),
}); });
videoElement.onended = async (ev) => { // videoElement.onended = async (ev) => {
this.updateStatus({ status: PLAYER_STATUS.NOT_PLAYING, showName: '', time: 0 }); // this.updateStatus({ status: PLAYER_STATUS.NOT_PLAYING, showName: '', time: 0 });
}; // };
} }
async start() { async start() {
this.updateStatus({ source: getPlayerSource(), showName: await this.getShowName() }); this.updateStatus({ source: getPlayerSource(), showName: await this.getShowName() });