From 8653ad8e24763e1a853ab7ebb2e4f7785e9b6362 Mon Sep 17 00:00:00 2001 From: Ayushya Amitabh Date: Wed, 5 Aug 2020 21:33:22 -0400 Subject: [PATCH] v1.6.0/fix video listener --- app/src/VideoListener.js | 78 ++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/app/src/VideoListener.js b/app/src/VideoListener.js index 03c0adc..71d2af2 100644 --- a/app/src/VideoListener.js +++ b/app/src/VideoListener.js @@ -74,7 +74,7 @@ export default class VideoListener { this.isUpdating = true; if (this.video.element) { // REMOVE LISTENER BEFORE SYNCING - switch(this.video.source) { + switch (this.video.source) { case PLAYER_SOURCE.CRUNCHYROLL: window.removeEventListener('watchParty', this.crunchyRollListener); default: @@ -124,12 +124,14 @@ export default class VideoListener { this.video.element.currentTime = serverPlayer.time; break; case PLAYER_SOURCE.CRUNCHYROLL: - window.postMessage(JSON.stringify({ + window.postMessage( + JSON.stringify({ watchPartyDirection: 'TO_SCRIPT', type: 'WATCH_PARTY_SEEK', status: serverPlayer.status, - time: serverPlayer.time - })); + time: serverPlayer.time, + }) + ); break; default: break; @@ -146,12 +148,14 @@ export default class VideoListener { ) { window.postMessage({ type: 'PAUSE', time: serverPlayer.time }, '*'); } else if (PLAYER_SOURCE.CRUNCHYROLL === this.video.source) { - window.postMessage(JSON.stringify({ + window.postMessage( + JSON.stringify({ watchPartyDirection: 'TO_SCRIPT', type: 'WATCH_PARTY_STATUS', status: serverPlayer.status, - time: serverPlayer.time - })); + time: serverPlayer.time, + }) + ); } else { await this.video.element.pause(); } @@ -165,12 +169,14 @@ export default class VideoListener { ) { window.postMessage({ type: 'PLAY', time: serverPlayer.time }, '*'); } else if (PLAYER_SOURCE.CRUNCHYROLL === this.video.source) { - window.postMessage(JSON.stringify({ + window.postMessage( + JSON.stringify({ watchPartyDirection: 'TO_SCRIPT', type: 'WATCH_PARTY_STATUS', status: serverPlayer.status, - time: serverPlayer.time - })); + time: serverPlayer.time, + }) + ); } else { await this.video.element .play() @@ -182,7 +188,7 @@ export default class VideoListener { } await this.timeout(500); // RE-ADD LISTENERS FOR FUTURE SYNC - switch(this.video.source) { + switch (this.video.source) { case PLAYER_SOURCE.CRUNCHYROLL: window.addEventListener('watchParty', this.crunchyRollListener); default: @@ -258,7 +264,9 @@ export default class VideoListener { ? null : peacockshow + '\n' + peacockepisode; case PLAYER_SOURCE.GOOGLEPLAY: - const playerIframe = document.querySelector('#yDmH0d > div.llhEMd.bYEzqc.LAhoGb.iWO5td > div > div.LhXUod.XL54pf.J9Nfi.iWO5td > span > div > div > iframe'); + const playerIframe = document.querySelector( + '#yDmH0d > div.llhEMd.bYEzqc.LAhoGb.iWO5td > div > div.LhXUod.XL54pf.J9Nfi.iWO5td > span > div > div > iframe' + ); var googleplayshow = ''; if (playerIframe) { const titleElement = playerIframe.contentWindow.document.querySelector('.playing-title'); @@ -288,11 +296,14 @@ export default class VideoListener { }); } async crunchyRollListener(ev) { - if (ev.detail.watchPartyDirection === 'TO_APP' && ev.detail.type === 'WATCH_PARTY_PLAYER_UPDATE') { + if ( + ev.detail.watchPartyDirection === 'TO_APP' && + ev.detail.type === 'WATCH_PARTY_PLAYER_UPDATE' + ) { this.updateStatus({ status: ev.detail.status, time: ev.detail.time, - showName: await this.getShowName() + showName: await this.getShowName(), }); } } @@ -311,10 +322,12 @@ export default class VideoListener { }); switch (this.video.source) { case PLAYER_SOURCE.CRUNCHYROLL: - window.postMessage(JSON.stringify({ + window.postMessage( + JSON.stringify({ watchPartyDirection: 'TO_SCRIPT', - type: 'WATCH_PARTY_ADD_LISTENERS' - })); + type: 'WATCH_PARTY_ADD_LISTENERS', + }) + ); window.addEventListener('watchParty', this.crunchyRollListener); break; default: @@ -341,7 +354,11 @@ export default class VideoListener { this.video.element ? null : () => { - var nve = document.getElementsByClassName('AkiraPlayer')[0]? document.getElementsByClassName('AkiraPlayer')[0].getElementsByTagName('video')[0] : null; + var nve = document.getElementsByClassName('AkiraPlayer')[0] + ? document + .getElementsByClassName('AkiraPlayer')[0] + .getElementsByTagName('video')[0] + : null; if ( nve !== null && (this.video.element !== nve || this.video.element === null) @@ -357,11 +374,12 @@ export default class VideoListener { this.video.element ? null : () => { - var nve = document.getElementsByClassName('AkiraPlayer')[0]? document.getElementsByClassName('AkiraPlayer')[0].getElementsByTagName('video')[0] : null; - if ( - nve !== null && - (this.video.element !== nve || this.video.element === null) - ) { + var nve = document.getElementsByClassName('AkiraPlayer')[0] + ? document + .getElementsByClassName('AkiraPlayer')[0] + .getElementsByTagName('video')[0] + : null; + if (nve !== null && (this.video.element !== nve || this.video.element === null)) { this.firstTimeSync(nve); } }, @@ -525,7 +543,9 @@ export default class VideoListener { } break; case PLAYER_SOURCE.GOOGLEPLAY: - const playerIframe = document.querySelector('#yDmH0d > div.llhEMd.bYEzqc.LAhoGb.iWO5td > div > div.LhXUod.XL54pf.J9Nfi.iWO5td > span > div > div > iframe'); + const playerIframe = document.querySelector( + '#yDmH0d > div.llhEMd.bYEzqc.LAhoGb.iWO5td > div > div.LhXUod.XL54pf.J9Nfi.iWO5td > span > div > div > iframe' + ); if (playerIframe) { const googlePlayVideoElement = playerIframe.contentWindow.document.querySelector('video'); if (googlePlayVideoElement) { @@ -536,7 +556,9 @@ export default class VideoListener { this.video.element ? null : () => { - const pif = document.querySelector('#yDmH0d > div.llhEMd.bYEzqc.LAhoGb.iWO5td > div > div.LhXUod.XL54pf.J9Nfi.iWO5td > span > div > div > iframe'); + const pif = document.querySelector( + '#yDmH0d > div.llhEMd.bYEzqc.LAhoGb.iWO5td > div > div.LhXUod.XL54pf.J9Nfi.iWO5td > span > div > div > iframe' + ); if (pif) { const gpve = pif.contentWindow.document.querySelector('video'); if (gpve) { @@ -585,8 +607,10 @@ export default class VideoListener { window.removeEventListener('watchParty', this.crunchyRollListener); break; default: - this.video.element.removeEventListener('playing', this.onplay); - this.video.element.removeEventListener('pause', this.onpause); + if (this.video.element) { + this.video.element.removeEventListener('playing', this.onplay); + this.video.element.removeEventListener('pause', this.onpause); + } } } }