v1.6.0/fix video listener

This commit is contained in:
2020-08-05 21:33:22 -04:00
parent 9d4a9ca0ad
commit 8653ad8e24
+51 -27
View File
@@ -74,7 +74,7 @@ export default class VideoListener {
this.isUpdating = true; this.isUpdating = true;
if (this.video.element) { if (this.video.element) {
// REMOVE LISTENER BEFORE SYNCING // REMOVE LISTENER BEFORE SYNCING
switch(this.video.source) { switch (this.video.source) {
case PLAYER_SOURCE.CRUNCHYROLL: case PLAYER_SOURCE.CRUNCHYROLL:
window.removeEventListener('watchParty', this.crunchyRollListener); window.removeEventListener('watchParty', this.crunchyRollListener);
default: default:
@@ -124,12 +124,14 @@ export default class VideoListener {
this.video.element.currentTime = serverPlayer.time; this.video.element.currentTime = serverPlayer.time;
break; break;
case PLAYER_SOURCE.CRUNCHYROLL: case PLAYER_SOURCE.CRUNCHYROLL:
window.postMessage(JSON.stringify({ window.postMessage(
JSON.stringify({
watchPartyDirection: 'TO_SCRIPT', watchPartyDirection: 'TO_SCRIPT',
type: 'WATCH_PARTY_SEEK', type: 'WATCH_PARTY_SEEK',
status: serverPlayer.status, status: serverPlayer.status,
time: serverPlayer.time time: serverPlayer.time,
})); })
);
break; break;
default: default:
break; break;
@@ -146,12 +148,14 @@ export default class VideoListener {
) { ) {
window.postMessage({ type: 'PAUSE', time: serverPlayer.time }, '*'); window.postMessage({ type: 'PAUSE', time: serverPlayer.time }, '*');
} else if (PLAYER_SOURCE.CRUNCHYROLL === this.video.source) { } else if (PLAYER_SOURCE.CRUNCHYROLL === this.video.source) {
window.postMessage(JSON.stringify({ window.postMessage(
JSON.stringify({
watchPartyDirection: 'TO_SCRIPT', watchPartyDirection: 'TO_SCRIPT',
type: 'WATCH_PARTY_STATUS', type: 'WATCH_PARTY_STATUS',
status: serverPlayer.status, status: serverPlayer.status,
time: serverPlayer.time time: serverPlayer.time,
})); })
);
} else { } else {
await this.video.element.pause(); await this.video.element.pause();
} }
@@ -165,12 +169,14 @@ export default class VideoListener {
) { ) {
window.postMessage({ type: 'PLAY', time: serverPlayer.time }, '*'); window.postMessage({ type: 'PLAY', time: serverPlayer.time }, '*');
} else if (PLAYER_SOURCE.CRUNCHYROLL === this.video.source) { } else if (PLAYER_SOURCE.CRUNCHYROLL === this.video.source) {
window.postMessage(JSON.stringify({ window.postMessage(
JSON.stringify({
watchPartyDirection: 'TO_SCRIPT', watchPartyDirection: 'TO_SCRIPT',
type: 'WATCH_PARTY_STATUS', type: 'WATCH_PARTY_STATUS',
status: serverPlayer.status, status: serverPlayer.status,
time: serverPlayer.time time: serverPlayer.time,
})); })
);
} else { } else {
await this.video.element await this.video.element
.play() .play()
@@ -182,7 +188,7 @@ export default class VideoListener {
} }
await this.timeout(500); await this.timeout(500);
// RE-ADD LISTENERS FOR FUTURE SYNC // RE-ADD LISTENERS FOR FUTURE SYNC
switch(this.video.source) { switch (this.video.source) {
case PLAYER_SOURCE.CRUNCHYROLL: case PLAYER_SOURCE.CRUNCHYROLL:
window.addEventListener('watchParty', this.crunchyRollListener); window.addEventListener('watchParty', this.crunchyRollListener);
default: default:
@@ -258,7 +264,9 @@ export default class VideoListener {
? null ? null
: peacockshow + '\n' + peacockepisode; : peacockshow + '\n' + peacockepisode;
case PLAYER_SOURCE.GOOGLEPLAY: 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 = ''; var googleplayshow = '';
if (playerIframe) { if (playerIframe) {
const titleElement = playerIframe.contentWindow.document.querySelector('.playing-title'); const titleElement = playerIframe.contentWindow.document.querySelector('.playing-title');
@@ -288,11 +296,14 @@ export default class VideoListener {
}); });
} }
async crunchyRollListener(ev) { 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({ this.updateStatus({
status: ev.detail.status, status: ev.detail.status,
time: ev.detail.time, time: ev.detail.time,
showName: await this.getShowName() showName: await this.getShowName(),
}); });
} }
} }
@@ -311,10 +322,12 @@ export default class VideoListener {
}); });
switch (this.video.source) { switch (this.video.source) {
case PLAYER_SOURCE.CRUNCHYROLL: case PLAYER_SOURCE.CRUNCHYROLL:
window.postMessage(JSON.stringify({ window.postMessage(
JSON.stringify({
watchPartyDirection: 'TO_SCRIPT', watchPartyDirection: 'TO_SCRIPT',
type: 'WATCH_PARTY_ADD_LISTENERS' type: 'WATCH_PARTY_ADD_LISTENERS',
})); })
);
window.addEventListener('watchParty', this.crunchyRollListener); window.addEventListener('watchParty', this.crunchyRollListener);
break; break;
default: default:
@@ -341,7 +354,11 @@ export default class VideoListener {
this.video.element this.video.element
? null ? 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 ( if (
nve !== null && nve !== null &&
(this.video.element !== nve || this.video.element === null) (this.video.element !== nve || this.video.element === null)
@@ -357,11 +374,12 @@ export default class VideoListener {
this.video.element this.video.element
? null ? null
: () => { : () => {
var nve = document.getElementsByClassName('AkiraPlayer')[0]? document.getElementsByClassName('AkiraPlayer')[0].getElementsByTagName('video')[0] : null; var nve = document.getElementsByClassName('AkiraPlayer')[0]
if ( ? document
nve !== null && .getElementsByClassName('AkiraPlayer')[0]
(this.video.element !== nve || this.video.element === null) .getElementsByTagName('video')[0]
) { : null;
if (nve !== null && (this.video.element !== nve || this.video.element === null)) {
this.firstTimeSync(nve); this.firstTimeSync(nve);
} }
}, },
@@ -525,7 +543,9 @@ export default class VideoListener {
} }
break; break;
case PLAYER_SOURCE.GOOGLEPLAY: 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) { if (playerIframe) {
const googlePlayVideoElement = playerIframe.contentWindow.document.querySelector('video'); const googlePlayVideoElement = playerIframe.contentWindow.document.querySelector('video');
if (googlePlayVideoElement) { if (googlePlayVideoElement) {
@@ -536,7 +556,9 @@ export default class VideoListener {
this.video.element this.video.element
? null ? 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) { if (pif) {
const gpve = pif.contentWindow.document.querySelector('video'); const gpve = pif.contentWindow.document.querySelector('video');
if (gpve) { if (gpve) {
@@ -585,8 +607,10 @@ export default class VideoListener {
window.removeEventListener('watchParty', this.crunchyRollListener); window.removeEventListener('watchParty', this.crunchyRollListener);
break; break;
default: default:
this.video.element.removeEventListener('playing', this.onplay); if (this.video.element) {
this.video.element.removeEventListener('pause', this.onpause); this.video.element.removeEventListener('playing', this.onplay);
this.video.element.removeEventListener('pause', this.onpause);
}
} }
} }
} }