v1.6.1/dynamic video selectors

This commit is contained in:
2020-08-13 19:21:53 -04:00
parent 8530f4e727
commit 3c4fffe598
4 changed files with 265 additions and 381 deletions
+39 -59
View File
@@ -9,33 +9,27 @@ ALL CONTENT ON WATCH PARTY'S WEBSITE OR IN WATCH PARTY'S CHROME EXTENSION APP, U
CITED ARE THE SOLE INTELECTUAL PROPERTY OF AYUSHYA AMITABH, AND MAY NOT BE CITED ARE THE SOLE INTELECTUAL PROPERTY OF AYUSHYA AMITABH, AND MAY NOT BE
COPIED, EDITED, OR REPRODUCED WITHOUT PERMISSION. COPIED, EDITED, OR REPRODUCED WITHOUT PERMISSION.
************************************************************************/ ************************************************************************/
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from 'react';
import Router from "route-lite"; import Router from 'route-lite';
import { import { Fab, createMuiTheme, ThemeProvider, Snackbar, Tooltip } from '@material-ui/core';
Fab, import Create from './Create';
createMuiTheme, import Loading from './Loading';
ThemeProvider, import firebase from 'firebase/app';
Snackbar, import 'firebase/firestore';
Tooltip, import Inactive from './Inactive';
} from "@material-ui/core"; import { getUserUid, getPlayerSource, PLAYER_SOURCE } from './Api';
import Create from "./Create";
import Loading from "./Loading";
import firebase from "firebase/app";
import "firebase/firestore";
import Inactive from "./Inactive";
import { getUserUid, getPlayerSource, PLAYER_SOURCE } from "./Api";
const APP_VERSION = "1.6.1"; const APP_VERSION = '1.6.1';
const APP_VERSION_STRING = APP_VERSION.replace(/\./g, ""); const APP_VERSION_STRING = APP_VERSION.replace(/\./g, '');
const darkTheme = createMuiTheme({ const darkTheme = createMuiTheme({
palette: { palette: {
type: "dark", type: 'dark',
primary: { primary: {
main: "#FF0000", main: '#FF0000',
}, },
secondary: { secondary: {
main: "#c0f300", main: '#c0f300',
}, },
}, },
}); });
@@ -48,41 +42,32 @@ const Routes = (props) => (
const resetResize = () => { const resetResize = () => {
const checkedX = 400; const checkedX = 400;
document.documentElement.style.setProperty("--party-width", `${checkedX}px`); document.documentElement.style.setProperty('--party-width', `${checkedX}px`);
document.documentElement.style.setProperty( document.documentElement.style.setProperty('--neg-party-width', `-${checkedX}px`);
"--neg-party-width",
`-${checkedX}px`
);
}; };
const doResize = (ev) => { const doResize = (ev) => {
const checkedX = const checkedX =
window.innerWidth - window.innerWidth -
Math.min( Math.min(window.innerWidth - 300, Math.max(window.innerWidth * 0.5, ev.clientX));
window.innerWidth - 300, document.documentElement.style.setProperty('--party-width', `${checkedX}px`);
Math.max(window.innerWidth * 0.5, ev.clientX) document.documentElement.style.setProperty('--neg-party-width', `-${checkedX}px`);
);
document.documentElement.style.setProperty("--party-width", `${checkedX}px`);
document.documentElement.style.setProperty(
"--neg-party-width",
`-${checkedX}px`
);
}; };
const stopResize = (ev) => { const stopResize = (ev) => {
document.documentElement.removeEventListener("mousemove", doResize, false); document.documentElement.removeEventListener('mousemove', doResize, false);
document.documentElement.removeEventListener("mouseup", stopResize, false); document.documentElement.removeEventListener('mouseup', stopResize, false);
}; };
const startResize = (ev) => { const startResize = (ev) => {
document.documentElement.addEventListener("mousemove", doResize, false); document.documentElement.addEventListener('mousemove', doResize, false);
document.documentElement.addEventListener("mouseup", stopResize, false); document.documentElement.addEventListener('mouseup', stopResize, false);
}; };
const App = () => { const App = () => {
const closedNotification = { open: false, message: "" }; const closedNotification = { open: false, message: '' };
const [status, setStatus] = useState({ active: false, message: "" }); const [status, setStatus] = useState({ active: false, message: '' });
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [notification, setNotification] = useState(closedNotification); const [notification, setNotification] = useState(closedNotification);
@@ -94,8 +79,8 @@ const App = () => {
getUserUid(); getUserUid();
firebase firebase
.firestore() .firestore()
.collection("server") .collection('server')
.doc("status") .doc('status')
.onSnapshot((statusSnap) => { .onSnapshot((statusSnap) => {
setStatus(statusSnap.data()); setStatus(statusSnap.data());
setLoading(false); setLoading(false);
@@ -103,19 +88,18 @@ const App = () => {
}, []); }, []);
// HANDLE VISIBILITY STYLING // HANDLE VISIBILITY STYLING
const PartyRoutesWrapper = document.getElementById("party-routes-wrapper"); const PartyRoutesWrapper = document.getElementById('party-routes-wrapper');
if (visible) { if (visible) {
document.body.classList.add("visible"); document.body.classList.add('visible');
PartyRoutesWrapper && PartyRoutesWrapper.classList.add("visible"); PartyRoutesWrapper && PartyRoutesWrapper.classList.add('visible');
if ( if (
!hasAttached && !hasAttached &&
(getPlayerSource() === PLAYER_SOURCE.HBOMAX || (getPlayerSource() === PLAYER_SOURCE.HBOMAX || getPlayerSource() === PLAYER_SOURCE.HBONOW)
getPlayerSource() === PLAYER_SOURCE.HBONOW)
) { ) {
document.addEventListener( document.addEventListener(
"mousedown", 'mousedown',
function (ev) { function (ev) {
if (document.body.querySelector("body.visible")) { if (document.body.querySelector('body.visible')) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
ev.stopImmediatePropagation(); ev.stopImmediatePropagation();
@@ -126,8 +110,8 @@ const App = () => {
hasAttached = true; hasAttached = true;
} }
} else { } else {
document.body.classList.remove("visible"); document.body.classList.remove('visible');
PartyRoutesWrapper && PartyRoutesWrapper.classList.remove("visible"); PartyRoutesWrapper && PartyRoutesWrapper.classList.remove('visible');
} }
// HANDLE FULLSCREEN EVENT // HANDLE FULLSCREEN EVENT
@@ -139,7 +123,7 @@ const App = () => {
<ThemeProvider theme={darkTheme}> <ThemeProvider theme={darkTheme}>
<Snackbar <Snackbar
className="party-notification-container" className="party-notification-container"
anchorOrigin={{ vertical: "bottom", horizontal: "right" }} anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
open={notification.open} open={notification.open}
onClose={() => setNotification(closedNotification)} onClose={() => setNotification(closedNotification)}
message={notification.message} message={notification.message}
@@ -152,23 +136,19 @@ const App = () => {
title="Resize Sidebar / Double Click To Reset" title="Resize Sidebar / Double Click To Reset"
aria-label="Resize Sidebar / Double Click To Reset" aria-label="Resize Sidebar / Double Click To Reset"
> >
<div <div onDoubleClick={resetResize} onMouseDown={startResize} id="party-width-dragger">
onDoubleClick={resetResize}
onMouseDown={startResize}
id="party-width-dragger"
>
|| ||
</div> </div>
</Tooltip> </Tooltip>
{loading && <Loading />} {loading && <Loading />}
{status[APP_VERSION_STRING] && {status[APP_VERSION_STRING] && status[APP_VERSION_STRING].active === true ? (
status[APP_VERSION_STRING].active === true ? (
<Routes <Routes
updateLoading={setLoading} updateLoading={setLoading}
notify={(message) => setNotification({ open: true, message })} notify={(message) => setNotification({ open: true, message })}
appVersion={APP_VERSION} appVersion={APP_VERSION}
appVersionString={APP_VERSION_STRING} appVersionString={APP_VERSION_STRING}
status={status[APP_VERSION_STRING]} status={status[APP_VERSION_STRING]}
selectors={status.selectors}
/> />
) : ( ) : (
<Inactive <Inactive
+1 -1
View File
@@ -117,7 +117,7 @@ export default class Chat extends Component {
this.callEventListener = this.callEventListener.bind(this); this.callEventListener = this.callEventListener.bind(this);
this.sendMessageInvoker = this.sendMessageInvoker.bind(this); this.sendMessageInvoker = this.sendMessageInvoker.bind(this);
this.videoEventListener = this.videoEventListener.bind(this); this.videoEventListener = this.videoEventListener.bind(this);
this.mVideoListener = new VideoListener(this.videoEventListener); this.mVideoListener = new VideoListener(this.videoEventListener, props.selectors);
this.updateAllowAutoRejoin = this.updateAllowAutoRejoin.bind(this); this.updateAllowAutoRejoin = this.updateAllowAutoRejoin.bind(this);
this.updateAllowChatNotification = this.updateAllowChatNotification.bind(this); this.updateAllowChatNotification = this.updateAllowChatNotification.bind(this);
this.mCallManager = new CallManager(this.callEventListener, this.props.notify); this.mCallManager = new CallManager(this.callEventListener, this.props.notify);
+198 -286
View File
@@ -9,24 +9,20 @@ ALL CONTENT ON WATCH PARTY'S WEBSITE OR IN WATCH PARTY'S CHROME EXTENSION APP, U
CITED ARE THE SOLE INTELECTUAL PROPERTY OF AYUSHYA AMITABH, AND MAY NOT BE CITED ARE THE SOLE INTELECTUAL PROPERTY OF AYUSHYA AMITABH, AND MAY NOT BE
COPIED, EDITED, OR REPRODUCED WITHOUT PERMISSION. COPIED, EDITED, OR REPRODUCED WITHOUT PERMISSION.
************************************************************************/ ************************************************************************/
import { import { PLAYER_STATUS, getPlayerSource, PLAYER_SOURCE, LocalData } from './Api';
PLAYER_STATUS,
getPlayerSource,
PLAYER_SOURCE,
LocalData,
} from "./Api";
const templateListener = (video) => console.log("MISSING VIDEO LISTENER"); const templateListener = (video) => console.log('MISSING VIDEO LISTENER');
export default class VideoListener { export default class VideoListener {
constructor(listener = templateListener) { constructor(listener = templateListener, selectors) {
this.video = { this.video = {
status: PLAYER_STATUS.NOT_PLAYING, status: PLAYER_STATUS.NOT_PLAYING,
time: 0, time: 0,
showName: "", showName: '',
source: "", source: '',
element: null, element: null,
}; };
this.selectors = selectors;
this.isUpdating = false; this.isUpdating = false;
this.listener = listener; this.listener = listener;
this.updateStatus = this.updateStatus.bind(this); this.updateStatus = this.updateStatus.bind(this);
@@ -46,7 +42,7 @@ export default class VideoListener {
this.video.element !== null && this.video.element !== null &&
this.video.element !== undefined && this.video.element !== undefined &&
this.video.status !== PLAYER_STATUS.NOT_PLAYING && this.video.status !== PLAYER_STATUS.NOT_PLAYING &&
this.video.showName !== "" && this.video.showName !== '' &&
this.video.showName !== null && this.video.showName !== null &&
(this.video.status !== this.server.status || (this.video.status !== this.server.status ||
Math.abs(this.video.element.currentTime - this.server.time) > 1.5) Math.abs(this.video.element.currentTime - this.server.time) > 1.5)
@@ -73,30 +69,23 @@ export default class VideoListener {
// 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:
this.video.element.removeEventListener("playing", this.onplay); this.video.element.removeEventListener('playing', this.onplay);
this.video.element.removeEventListener("pause", this.onpause); this.video.element.removeEventListener('pause', this.onpause);
} }
await this.timeout(250); await this.timeout(250);
// SEEK // SEEK
if ( if (Math.abs(serverPlayer.time - this.video.element.currentTime) > 1.5) {
Math.abs(serverPlayer.time - this.video.element.currentTime) > 1.5
) {
switch (serverPlayer.source) { switch (serverPlayer.source) {
case PLAYER_SOURCE.NETFLIX: case PLAYER_SOURCE.NETFLIX:
window.postMessage( window.postMessage({ type: 'SEEK', time: serverPlayer.time * 1000 }, '*');
{ type: "SEEK", time: serverPlayer.time * 1000 },
"*"
);
break; break;
case PLAYER_SOURCE.AMAZON: case PLAYER_SOURCE.AMAZON:
if (this.video.status === PLAYER_STATUS.PAUSED) if (this.video.status === PLAYER_STATUS.PAUSED)
await this.video.element await this.video.element
.play() .play()
.catch((err) => .catch((err) => console.error('WatchParty erred when syncing time.'));
console.error("WatchParty erred when syncing time.")
);
await this.timeout(250); await this.timeout(250);
this.video.element.currentTime = serverPlayer.time; this.video.element.currentTime = serverPlayer.time;
await this.timeout(500); await this.timeout(500);
@@ -109,10 +98,7 @@ export default class VideoListener {
this.video.element.currentTime = serverPlayer.time; this.video.element.currentTime = serverPlayer.time;
break; break;
case PLAYER_SOURCE.HULU: case PLAYER_SOURCE.HULU:
window.postMessage( window.postMessage({ type: 'SEEK', time: serverPlayer.time }, '*');
{ type: "SEEK", time: serverPlayer.time },
"*"
);
break; break;
case PLAYER_SOURCE.HBOMAX: case PLAYER_SOURCE.HBOMAX:
case PLAYER_SOURCE.HBONOW: case PLAYER_SOURCE.HBONOW:
@@ -121,8 +107,8 @@ export default class VideoListener {
case PLAYER_SOURCE.PEACOCK: case PLAYER_SOURCE.PEACOCK:
window.postMessage( window.postMessage(
JSON.stringify({ 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,
}) })
@@ -134,8 +120,8 @@ export default class VideoListener {
case PLAYER_SOURCE.CRUNCHYROLL: case PLAYER_SOURCE.CRUNCHYROLL:
window.postMessage( window.postMessage(
JSON.stringify({ 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,
}) })
@@ -154,18 +140,15 @@ export default class VideoListener {
PLAYER_SOURCE.HBOMAX === this.video.source || PLAYER_SOURCE.HBOMAX === this.video.source ||
PLAYER_SOURCE.HBONOW === this.video.source PLAYER_SOURCE.HBONOW === this.video.source
) { ) {
window.postMessage( window.postMessage({ type: 'PAUSE', time: serverPlayer.time }, '*');
{ type: "PAUSE", time: serverPlayer.time },
"*"
);
} else if ( } else if (
PLAYER_SOURCE.CRUNCHYROLL === this.video.source || PLAYER_SOURCE.CRUNCHYROLL === this.video.source ||
PLAYER_SOURCE.PEACOCK === this.video.source PLAYER_SOURCE.PEACOCK === this.video.source
) { ) {
window.postMessage( window.postMessage(
JSON.stringify({ 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,
}) })
@@ -181,18 +164,15 @@ export default class VideoListener {
PLAYER_SOURCE.HBOMAX === this.video.source || PLAYER_SOURCE.HBOMAX === this.video.source ||
PLAYER_SOURCE.HBONOW === this.video.source PLAYER_SOURCE.HBONOW === this.video.source
) { ) {
window.postMessage( window.postMessage({ type: 'PLAY', time: serverPlayer.time }, '*');
{ type: "PLAY", time: serverPlayer.time },
"*"
);
} else if ( } else if (
PLAYER_SOURCE.CRUNCHYROLL === this.video.source || PLAYER_SOURCE.CRUNCHYROLL === this.video.source ||
PLAYER_SOURCE.PEACOCK === this.video.source PLAYER_SOURCE.PEACOCK === this.video.source
) { ) {
window.postMessage( window.postMessage(
JSON.stringify({ 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,
}) })
@@ -200,9 +180,7 @@ export default class VideoListener {
} else { } else {
await this.video.element await this.video.element
.play() .play()
.catch((err) => .catch((err) => console.error('WatchParty erred when syncing play.'));
console.error("WatchParty erred when syncing play.")
);
} }
break; break;
default: default:
@@ -212,10 +190,10 @@ export default class VideoListener {
// 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:
this.video.element.addEventListener("playing", this.onplay); this.video.element.addEventListener('playing', this.onplay);
this.video.element.addEventListener("pause", this.onpause); this.video.element.addEventListener('pause', this.onpause);
} }
} }
this.isUpdating = false; this.isUpdating = false;
@@ -231,89 +209,74 @@ export default class VideoListener {
switch (this.video.source) { switch (this.video.source) {
case PLAYER_SOURCE.NETFLIX: case PLAYER_SOURCE.NETFLIX:
const titleContainerParent = document.querySelector( const titleContainerParent = document.querySelector(
".PlayerControls--control-element.text-control.video-title" '.PlayerControls--control-element.text-control.video-title'
); );
if (titleContainerParent) { if (titleContainerParent) {
const titleContainer = titleContainerParent.firstChild; const titleContainer = titleContainerParent.firstChild;
const nshow = titleContainer.querySelector("h4") const nshow = titleContainer.querySelector('h4')
? titleContainer.querySelector("h4").innerHTML ? titleContainer.querySelector('h4').innerHTML
: titleContainer.innerHTML; : titleContainer.innerHTML;
let nepisode = ""; let nepisode = '';
titleContainer.querySelectorAll("span").forEach((e) => { titleContainer.querySelectorAll('span').forEach((e) => {
if (e.innerHTML) nepisode += e.innerHTML + " "; if (e.innerHTML) nepisode += e.innerHTML + ' ';
}); });
return nshow === "" && nepisode === "" return nshow === '' && nepisode === '' ? null : nshow + '\n' + nepisode;
? null
: nshow + "\n" + nepisode;
} }
break; break;
case PLAYER_SOURCE.AMAZON: case PLAYER_SOURCE.AMAZON:
const ashow = const ashow =
document.querySelector( document.querySelector(
"#dv-web-player > div > div:nth-child(1) > div > div > div.webPlayerSDKUiContainer > div > div > div > div > div > div > div > div:nth-child(2) > div:nth-child(2)" '#dv-web-player > div > div:nth-child(1) > div > div > div.webPlayerSDKUiContainer > div > div > div > div > div > div > div > div:nth-child(2) > div:nth-child(2)'
).innerText || ""; ).innerText || '';
return ashow === "" ? null : ashow; return ashow === '' ? null : ashow;
case PLAYER_SOURCE.HULU: case PLAYER_SOURCE.HULU:
const hshow = document.querySelector(".metadata-area__second-line") const hshow = document.querySelector('.metadata-area__second-line').innerHTML;
.innerHTML; const hepisode = document.querySelector('.metadata-area__third-line').innerHTML;
const hepisode = document.querySelector(".metadata-area__third-line") return hshow === '' && hepisode === '' ? null : hshow + '\n' + hepisode;
.innerHTML;
return hshow === "" && hepisode === "" ? null : hshow + "\n" + hepisode;
case PLAYER_SOURCE.DISNEY: case PLAYER_SOURCE.DISNEY:
this.video.element.parentElement.click(); this.video.element.parentElement.click();
await this.timeout(200); await this.timeout(200);
const dshow = document.querySelector(".title-field") const dshow = document.querySelector('.title-field')
? document.querySelector(".title-field").innerHTML ? document.querySelector('.title-field').innerHTML
: ""; : '';
const depisode = document.querySelector(".subtitle-field") const depisode = document.querySelector('.subtitle-field')
? document.querySelector(".subtitle-field").innerHTML ? document.querySelector('.subtitle-field').innerHTML
: ""; : '';
return dshow === "" && depisode === "" ? null : dshow + "\n" + depisode; return dshow === '' && depisode === '' ? null : dshow + '\n' + depisode;
case PLAYER_SOURCE.YOUTUBE: case PLAYER_SOURCE.YOUTUBE:
const yshow = document.querySelector("h1.title").innerText; const yshow = document.querySelector('h1.title').innerText;
const yepisode = document.querySelector( const yepisode = document.querySelector('yt-formatted-string.super-title').innerText;
"yt-formatted-string.super-title" return yshow === '' && yepisode === '' ? null : yshow + '\n' + yepisode;
).innerText;
return yshow === "" && yepisode === "" ? null : yshow + "\n" + yepisode;
case PLAYER_SOURCE.HBOMAX: case PLAYER_SOURCE.HBOMAX:
case PLAYER_SOURCE.HBONOW: case PLAYER_SOURCE.HBONOW:
const bottomHalf = this.video.element.parentNode.parentNode.parentNode const bottomHalf = this.video.element.parentNode.parentNode.parentNode.parentNode.parentNode
.parentNode.parentNode.children[1]; .children[1];
bottomHalf.children[0].id = "hboUpperTitle"; bottomHalf.children[0].id = 'hboUpperTitle';
bottomHalf.children[1].id = "hboLowerTitle"; bottomHalf.children[1].id = 'hboLowerTitle';
const hboshow = document.querySelector("#hboUpperTitle").innerText; const hboshow = document.querySelector('#hboUpperTitle').innerText;
const hboepisode = document.querySelector("#hboLowerTitle").innerText; const hboepisode = document.querySelector('#hboLowerTitle').innerText;
return hboshow === "" && hboepisode === "" return hboshow === '' && hboepisode === '' ? null : hboshow + '\n' + hboepisode;
? null
: hboshow + "\n" + hboepisode;
case PLAYER_SOURCE.PEACOCK: case PLAYER_SOURCE.PEACOCK:
const peacockshow = document.querySelector( const peacockshow = document.querySelector(
".item.playback-metadata__container-episode-metadata-info" '.item.playback-metadata__container-episode-metadata-info'
).innerText; ).innerText;
const peacockepisode = document.querySelector( const peacockepisode = document.querySelector('.item.playback-metadata__container-title')
".item.playback-metadata__container-title" .innerText;
).innerText; return peacockshow === '' && peacockepisode === ''
return peacockshow === "" && peacockepisode === ""
? null ? null
: peacockshow + "\n" + peacockepisode; : peacockshow + '\n' + peacockepisode;
case PLAYER_SOURCE.GOOGLEPLAY: case PLAYER_SOURCE.GOOGLEPLAY:
const playerIframe = document.querySelector("body span div iframe"); const playerIframe = document.querySelector('body span div iframe');
var googleplayshow = ""; var googleplayshow = '';
if (playerIframe) { if (playerIframe) {
const titleElement = playerIframe.contentWindow.document.querySelector( const titleElement = playerIframe.contentWindow.document.querySelector('.playing-title');
".playing-title" googleplayshow = titleElement ? titleElement.innerText : '';
);
googleplayshow = titleElement ? titleElement.innerText : "";
} }
return googleplayshow === "" ? null : googleplayshow; return googleplayshow === '' ? null : googleplayshow;
case PLAYER_SOURCE.CRUNCHYROLL: case PLAYER_SOURCE.CRUNCHYROLL:
const crunchyrollTitle = document.querySelector( const crunchyrollTitle = document.querySelector('#showmedia_about_media');
"#showmedia_about_media" const crunchyrollshow = crunchyrollTitle ? crunchyrollTitle.innerText : '';
); return crunchyrollshow === '' ? null : crunchyrollshow;
const crunchyrollshow = crunchyrollTitle
? crunchyrollTitle.innerText
: "";
return crunchyrollshow === "" ? null : crunchyrollshow;
default: default:
break; break;
} }
@@ -334,8 +297,8 @@ export default class VideoListener {
} }
async crunchyRollListener(ev) { async crunchyRollListener(ev) {
if ( if (
ev.detail.watchPartyDirection === "TO_APP" && ev.detail.watchPartyDirection === 'TO_APP' &&
ev.detail.type === "WATCH_PARTY_PLAYER_UPDATE" ev.detail.type === 'WATCH_PARTY_PLAYER_UPDATE'
) { ) {
this.updateStatus({ this.updateStatus({
status: ev.detail.status, status: ev.detail.status,
@@ -355,15 +318,15 @@ export default class VideoListener {
case PLAYER_SOURCE.CRUNCHYROLL: case PLAYER_SOURCE.CRUNCHYROLL:
window.postMessage( window.postMessage(
JSON.stringify({ 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:
videoElement.addEventListener("playing", this.onplay); videoElement.addEventListener('playing', this.onplay);
videoElement.addEventListener("pause", this.onpause); videoElement.addEventListener('pause', this.onpause);
} }
} }
async start() { async start() {
@@ -374,50 +337,19 @@ export default class VideoListener {
switch (this.video.source) { switch (this.video.source) {
case PLAYER_SOURCE.NETFLIX: case PLAYER_SOURCE.NETFLIX:
const seekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=window.netflix.appContext.state.playerApp.getAPI().videoPlayer,t=e.getAllPlayerSessionIds()[0];return e.getVideoPlayerBySessionId(t)},seekInteraction=function(e){if(e.source==window){if(e.data.type&&"SEEK"==e.data.type){getVideoPlayer().pause();getVideoPlayer().seek(e.data.time);}if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`; const seekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=window.netflix.appContext.state.playerApp.getAPI().videoPlayer,t=e.getAllPlayerSessionIds()[0];return e.getVideoPlayerBySessionId(t)},seekInteraction=function(e){if(e.source==window){if(e.data.type&&"SEEK"==e.data.type){getVideoPlayer().pause();getVideoPlayer().seek(e.data.time);}if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`;
const seekInjectScript = document.createElement("script"); const seekInjectScript = document.createElement('script');
seekInjectScript.text = seekInject; seekInjectScript.text = seekInject;
document.head.appendChild(seekInjectScript); document.head.appendChild(seekInjectScript);
if (document.getElementsByClassName("AkiraPlayer")[0]) { const videoElement = document.querySelector(this.selectors[PLAYER_SOURCE.NETFLIX]);
const videoElement = document if (videoElement && !this.video.element) {
.getElementsByClassName("AkiraPlayer")[0] this.firstTimeSync(videoElement);
.getElementsByTagName("video")[0];
if (videoElement && !this.video.element) {
this.firstTimeSync(videoElement);
} else {
setInterval(
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);
}
},
1000
);
}
} else { } else {
setInterval( setInterval(
this.video.element this.video.element
? null ? null
: () => { : () => {
var nve = document.getElementsByClassName("AkiraPlayer")[0] var nve = document.querySelector(this.selectors[PLAYER_SOURCE.NETFLIX]);
? document if (nve !== null && (this.video.element !== nve || this.video.element === null)) {
.getElementsByClassName("AkiraPlayer")[0]
.getElementsByTagName("video")[0]
: null;
if (
nve !== null &&
(this.video.element !== nve || this.video.element === null)
) {
this.firstTimeSync(nve); this.firstTimeSync(nve);
} }
}, },
@@ -426,13 +358,13 @@ export default class VideoListener {
} }
break; break;
case PLAYER_SOURCE.HULU: case PLAYER_SOURCE.HULU:
const huluSeekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=document.getElementsByClassName('content-video-player')[0].__HuluDashPlayer__;return e;},seekInteraction=function(e){if(e.source==window){if(e.data.type&&"SEEK"==e.data.type){getVideoPlayer().seek(e.data.time,e.data.time);}if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`; const huluSeekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=document.querySelector("${
const huluSeekInjectScript = document.createElement("script"); this.selectors[PLAYER_SOURCE.HULU]
}").__HuluDashPlayer__;return e;},seekInteraction=function(e){if(e.source==window){if(e.data.type&&"SEEK"==e.data.type){getVideoPlayer().seek(e.data.time,e.data.time);}if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`;
const huluSeekInjectScript = document.createElement('script');
huluSeekInjectScript.text = huluSeekInject; huluSeekInjectScript.text = huluSeekInject;
document.head.appendChild(huluSeekInjectScript); document.head.appendChild(huluSeekInjectScript);
const videoElement = document.getElementsByClassName( const videoElement = document.querySelector(this.selectors[PLAYER_SOURCE.HULU]);
"content-video-player"
)[0];
if (videoElement) { if (videoElement) {
this.firstTimeSync(videoElement); this.firstTimeSync(videoElement);
} else { } else {
@@ -440,11 +372,91 @@ export default class VideoListener {
this.video.element this.video.element
? null ? null
: () => { : () => {
var hve = document.getElementsByClassName( var hve = document.querySelector(this.selectors[PLAYER_SOURCE.HULU]);
"content-video-player" if (hve !== null && (this.video.element !== hve || this.video.element === null)) {
)[0]; this.firstTimeSync(hve);
}
},
1000
);
}
break;
case PLAYER_SOURCE.AMAZON:
const videoElement = document.querySelector(this.selectors[PLAYER_SOURCE.AMAZON]);
if (videoElement) {
this.firstTimeSync(videoElement);
} else {
setInterval(
this.video.element
? null
: () => {
var ave = document.querySelector(this.selectors[PLAYER_SOURCE.AMAZON]);
if (ave !== null && (this.video.element !== ave || this.video.element === null)) {
this.firstTimeSync(ave);
}
},
1000
);
}
break;
case PLAYER_SOURCE.DISNEY:
const disneyVideoElement = document.querySelector(this.selectors[PLAYER_SOURCE.DISNEY]);
if (disneyVideoElement) {
this.firstTimeSync(disneyVideoElement);
} else {
setInterval(
this.video.element
? null
: () => {
var dve = document.querySelector(this.selectors[PLAYER_SOURCE.DISNEY]);
if (dve !== null && (this.video.element !== dve || this.video.element === null)) {
this.firstTimeSync(dve);
}
},
1000
);
}
break;
case PLAYER_SOURCE.YOUTUBE:
const youtubeVideoElement = document.querySelector(this.selectors[PLAYER_SOURCE.YOUTUBE]);
if (youtubeVideoElement) this.firstTimeSync(youtubeVideoElement);
else {
setInterval(
this.video.element
? null
: () => {
var yve = document.querySelector(this.selectors[PLAYER_SOURCE.YOUTUBE]);
if (yve !== null && (this.video.element !== yve || this.video.element === null)) {
this.firstTimeSync(yve);
}
},
1000
);
}
break;
case PLAYER_SOURCE.HBOMAX:
const hboSeekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=document.querySelector("${
this.selectors[PLAYER_SOURCE.HBOMAX]
}")._dispNode;return e;},seekInteraction=function(e){if(e.source==window){if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`;
const hboSeekInjectScript = document.createElement('script');
hboSeekInjectScript.text = hboSeekInject;
document.head.appendChild(hboSeekInjectScript);
const hboVideoElement = document.querySelector(this.selectors[PLAYER_SOURCE.HBOMAX]);
if (hboVideoElement) {
const bottomHalf =
hboVideoElement.parentNode.parentNode.parentNode.parentNode.parentNode.children[1];
bottomHalf.children[0].id = 'hboUpperTitle';
bottomHalf.children[1].id = 'hboLowerTitle';
this.firstTimeSync(hboVideoElement);
} else {
setInterval(
this.video.element
? null
: () => {
var hve = document.querySelector(this.selectors[PLAYER_SOURCE.HBOMAX]);
if ( if (
hve !== null && hve !== null &&
hve !== undefined &&
(this.video.element !== hve || this.video.element === null) (this.video.element !== hve || this.video.element === null)
) { ) {
this.firstTimeSync(hve); this.firstTimeSync(hve);
@@ -454,120 +466,26 @@ export default class VideoListener {
); );
} }
break; break;
case PLAYER_SOURCE.AMAZON:
if (document.querySelector("webPlayerSDKContainer")) {
const videoElement = document.querySelector(
".webPlayerSDKContainer video"
);
if (videoElement) {
this.firstTimeSync(videoElement);
} else {
setInterval(
this.video.element
? null
: () => {
var ave = document.querySelector(
".webPlayerSDKContainer video"
);
if (
ave !== null &&
(this.video.element !== ave ||
this.video.element === null)
) {
this.firstTimeSync(ave);
}
},
1000
);
}
} else {
setInterval(
this.video.element
? null
: () => {
var ave = document
.getElementsByClassName("webPlayerSDKContainer")[0]
.getElementsByTagName("video")[0];
if (
ave !== null &&
(this.video.element !== ave || this.video.element === null)
) {
this.firstTimeSync(ave);
}
},
1000
);
}
break;
case PLAYER_SOURCE.DISNEY:
const disneyVideoElement = document.querySelector(
"video.btm-media-client-element"
);
if (disneyVideoElement) {
this.firstTimeSync(disneyVideoElement);
} else {
setInterval(
this.video.element
? null
: () => {
var dve = document.querySelector(
"video.btm-media-client-element"
);
if (
dve !== null &&
(this.video.element !== dve || this.video.element === null)
) {
this.firstTimeSync(dve);
}
},
1000
);
}
break;
case PLAYER_SOURCE.YOUTUBE:
const youtubeVideoElement = document.querySelector(
"video.video-stream.html5-main-video"
);
if (youtubeVideoElement) this.firstTimeSync(youtubeVideoElement);
else {
setInterval(
this.video.element
? null
: () => {
var yve = document.querySelector(
"video.video-stream.html5-main-video"
);
if (
yve !== null &&
(this.video.element !== yve || this.video.element === null)
) {
this.firstTimeSync(yve);
}
},
1000
);
}
break;
case PLAYER_SOURCE.HBOMAX:
case PLAYER_SOURCE.HBONOW: case PLAYER_SOURCE.HBONOW:
const hboSeekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=document.querySelector('video.default')._dispNode;return e;},seekInteraction=function(e){if(e.source==window){if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`; const hboSeekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=document.querySelector("${
const hboSeekInjectScript = document.createElement("script"); this.selectors[PLAYER_SOURCE.HBONOW]
}")._dispNode;return e;},seekInteraction=function(e){if(e.source==window){if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`;
const hboSeekInjectScript = document.createElement('script');
hboSeekInjectScript.text = hboSeekInject; hboSeekInjectScript.text = hboSeekInject;
document.head.appendChild(hboSeekInjectScript); document.head.appendChild(hboSeekInjectScript);
const hboVideoElement = document.querySelector("video.default"); const hboVideoElement = document.querySelector(this.selectors[PLAYER_SOURCE.HBONOW]);
if (hboVideoElement) { if (hboVideoElement) {
const bottomHalf = const bottomHalf =
hboVideoElement.parentNode.parentNode.parentNode.parentNode hboVideoElement.parentNode.parentNode.parentNode.parentNode.parentNode.children[1];
.parentNode.children[1]; bottomHalf.children[0].id = 'hboUpperTitle';
bottomHalf.children[0].id = "hboUpperTitle"; bottomHalf.children[1].id = 'hboLowerTitle';
bottomHalf.children[1].id = "hboLowerTitle";
this.firstTimeSync(hboVideoElement); this.firstTimeSync(hboVideoElement);
} else { } else {
setInterval( setInterval(
this.video.element this.video.element
? null ? null
: () => { : () => {
var hve = document.querySelector("video.default"); var hve = document.querySelector(this.selectors[PLAYER_SOURCE.HBONOW]);
if ( if (
hve !== null && hve !== null &&
hve !== undefined && hve !== undefined &&
@@ -581,13 +499,13 @@ export default class VideoListener {
} }
break; break;
case PLAYER_SOURCE.PEACOCK: case PLAYER_SOURCE.PEACOCK:
const peacockInject = `var watchPartyInteraction=function(e){if(e.source===window){const data=JSON.parse(e.data);const playerReactElement=document.querySelector(".video-player-component.playback-component > div");if(data.watchPartyDirection==='TO_SCRIPT'){if(data.type==='WATCH_PARTY_SEEK'){if(playerReactElement&&playerReactElement.player){playerReactElement.player.seek(data.time)}}else if(data.type==='WATCH_PARTY_STATUS'){if(playerReactElement&&playerReactElement.player){if(data.status==='PAUSED')playerReactElement.player.pause();if(data.status==='PLAYING')playerReactElement.player.play()}}}}};window.addEventListener("message",watchPartyInteraction);`; const peacockInject = `var watchPartyInteraction=function(e){if(e.source===window){const data=JSON.parse(e.data);const playerReactElement=document.querySelector("${
const peacockInjectScript = document.createElement("script"); this.selectors[PLAYER_SOURCE.PEACOCK]
}");if(data.watchPartyDirection==='TO_SCRIPT'){if(data.type==='WATCH_PARTY_SEEK'){if(playerReactElement&&playerReactElement.player){playerReactElement.player.seek(data.time)}}else if(data.type==='WATCH_PARTY_STATUS'){if(playerReactElement&&playerReactElement.player){if(data.status==='PAUSED')playerReactElement.player.pause();if(data.status==='PLAYING')playerReactElement.player.play()}}}}};window.addEventListener("message",watchPartyInteraction);`;
const peacockInjectScript = document.createElement('script');
peacockInjectScript.text = peacockInject; peacockInjectScript.text = peacockInject;
document.head.appendChild(peacockInjectScript); document.head.appendChild(peacockInjectScript);
const peacockVideoElement = document.querySelector( const peacockVideoElement = document.querySelector(this.selectors[PLAYER_SOURCE.PEACOCK]);
".video-player-component.playback-component video"
);
if (peacockVideoElement) { if (peacockVideoElement) {
this.firstTimeSync(peacockVideoElement); this.firstTimeSync(peacockVideoElement);
} else { } else {
@@ -595,9 +513,7 @@ export default class VideoListener {
this.video.element this.video.element
? null ? null
: () => { : () => {
var pve = document.querySelector( var pve = document.querySelector(this.selectors[PLAYER_SOURCE.PEACOCK]);
".video-player-component.playback-component video"
);
if ( if (
pve !== null && pve !== null &&
pve !== undefined && pve !== undefined &&
@@ -611,11 +527,9 @@ export default class VideoListener {
} }
break; break;
case PLAYER_SOURCE.GOOGLEPLAY: case PLAYER_SOURCE.GOOGLEPLAY:
const playerIframe = document.querySelector("body span div iframe"); const playerIframe = document.querySelector(this.selectors[PLAYER_SOURCE.GOOGLEPLAY]);
if (playerIframe) { if (playerIframe) {
const googlePlayVideoElement = playerIframe.contentWindow.document.querySelector( const googlePlayVideoElement = playerIframe.contentWindow.document.querySelector('video');
"video"
);
if (googlePlayVideoElement) { if (googlePlayVideoElement) {
this.firstTimeSync(googlePlayVideoElement); this.firstTimeSync(googlePlayVideoElement);
} }
@@ -624,11 +538,9 @@ export default class VideoListener {
this.video.element this.video.element
? null ? null
: () => { : () => {
const pif = document.querySelector("body span div iframe"); const pif = document.querySelector(this.selectors[PLAYER_SOURCE.GOOGLEPLAY]);
if (pif) { if (pif) {
const gpve = pif.contentWindow.document.querySelector( const gpve = pif.contentWindow.document.querySelector('video');
"video"
);
if (gpve) { if (gpve) {
this.firstTimeSync(gpve); this.firstTimeSync(gpve);
} }
@@ -639,10 +551,10 @@ export default class VideoListener {
} }
case PLAYER_SOURCE.CRUNCHYROLL: case PLAYER_SOURCE.CRUNCHYROLL:
const crunchyRollInject = `var sendToWatchPartyApp = function(pS, pT) { var customWatchPartyEvent = new CustomEvent('watchParty', { detail: { watchPartyDirection: 'TO_APP', type: 'WATCH_PARTY_PLAYER_UPDATE', status: pS, time: pT } }); window.dispatchEvent(customWatchPartyEvent); }, watchPartyGetTimeAndSend = function(pS) { if (window.VILOS_PLAYERJS) { window.VILOS_PLAYERJS.getCurrentTime(function(pT) { sendToWatchPartyApp(pS, pT); }); } }, watchPartySendPlaying = function() { watchPartyGetTimeAndSend('PLAYING'); }, watchPartySendPaused = function() { watchPartyGetTimeAndSend('PAUSED'); }, watchPartyInteraction = function(e) { if (e.source === window) { const data = JSON.parse(e.data); if (data.watchPartyDirection === 'TO_SCRIPT') { if (data.type === 'WATCH_PARTY_ADD_LISTENERS') { if (window.VILOS_PLAYERJS) { window.VILOS_PLAYERJS.on('play', watchPartySendPlaying, 'player.js'); window.VILOS_PLAYERJS.on('pause', watchPartySendPaused, 'player.js'); } } else if (data.type === 'WATCH_PARTY_SEEK') { if (window.VILOS_PLAYERJS) { window.VILOS_PLAYERJS.setCurrentTime(data.time); } } else if (data.type === 'WATCH_PARTY_STATUS') { if (window.VILOS_PLAYERJS) { if (data.status === 'PAUSED') window.VILOS_PLAYERJS.pause(); if (data.status === 'PLAYING') window.VILOS_PLAYERJS.play(); } } } } }; window.addEventListener("message", watchPartyInteraction);`; const crunchyRollInject = `var sendToWatchPartyApp = function(pS, pT) { var customWatchPartyEvent = new CustomEvent('watchParty', { detail: { watchPartyDirection: 'TO_APP', type: 'WATCH_PARTY_PLAYER_UPDATE', status: pS, time: pT } }); window.dispatchEvent(customWatchPartyEvent); }, watchPartyGetTimeAndSend = function(pS) { if (window.VILOS_PLAYERJS) { window.VILOS_PLAYERJS.getCurrentTime(function(pT) { sendToWatchPartyApp(pS, pT); }); } }, watchPartySendPlaying = function() { watchPartyGetTimeAndSend('PLAYING'); }, watchPartySendPaused = function() { watchPartyGetTimeAndSend('PAUSED'); }, watchPartyInteraction = function(e) { if (e.source === window) { const data = JSON.parse(e.data); if (data.watchPartyDirection === 'TO_SCRIPT') { if (data.type === 'WATCH_PARTY_ADD_LISTENERS') { if (window.VILOS_PLAYERJS) { window.VILOS_PLAYERJS.on('play', watchPartySendPlaying, 'player.js'); window.VILOS_PLAYERJS.on('pause', watchPartySendPaused, 'player.js'); } } else if (data.type === 'WATCH_PARTY_SEEK') { if (window.VILOS_PLAYERJS) { window.VILOS_PLAYERJS.setCurrentTime(data.time); } } else if (data.type === 'WATCH_PARTY_STATUS') { if (window.VILOS_PLAYERJS) { if (data.status === 'PAUSED') window.VILOS_PLAYERJS.pause(); if (data.status === 'PLAYING') window.VILOS_PLAYERJS.play(); } } } } }; window.addEventListener("message", watchPartyInteraction);`;
const crunchyRollInjectScript = document.createElement("script"); const crunchyRollInjectScript = document.createElement('script');
crunchyRollInjectScript.text = crunchyRollInject; crunchyRollInjectScript.text = crunchyRollInject;
document.head.appendChild(crunchyRollInjectScript); document.head.appendChild(crunchyRollInjectScript);
const crunchyrollIframe = document.getElementById("vilos-player"); const crunchyrollIframe = document.querySelector(this.selectors[PLAYER_SOURCE.CRUNCHYROLL]);
if (crunchyrollIframe) { if (crunchyrollIframe) {
this.firstTimeSync(crunchyrollIframe); this.firstTimeSync(crunchyrollIframe);
} else { } else {
@@ -650,7 +562,7 @@ export default class VideoListener {
this.video.element this.video.element
? null ? null
: () => { : () => {
const cif = document.getElementById("vilos-player"); const cif = document.querySelector(this.selectors[PLAYER_SOURCE.CRUNCHYROLL]);
if (cif) { if (cif) {
this.firstTimeSync(cif); this.firstTimeSync(cif);
} }
@@ -660,7 +572,7 @@ export default class VideoListener {
} }
break; break;
case PLAYER_SOURCE.LOCAL: case PLAYER_SOURCE.LOCAL:
const localVideoElement = document.getElementsByTagName("video")[0]; const localVideoElement = document.getElementsByTagName('video')[0];
if (localVideoElement) { if (localVideoElement) {
this.firstTimeSync(localVideoElement); this.firstTimeSync(localVideoElement);
} }
@@ -672,12 +584,12 @@ export default class VideoListener {
end() { end() {
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);
break; break;
default: default:
if (this.video.element) { if (this.video.element) {
this.video.element.removeEventListener("playing", this.onplay); this.video.element.removeEventListener('playing', this.onplay);
this.video.element.removeEventListener("pause", this.onpause); this.video.element.removeEventListener('pause', this.onpause);
} }
} }
} }
+27 -35
View File
@@ -1,27 +1,21 @@
const admin = require("firebase-admin"); const admin = require('firebase-admin');
module.exports = async (req, res) => { module.exports = async (req, res) => {
const bodydata = JSON.parse(req.body); const bodydata = JSON.parse(req.body);
console.log("Requested Create - UID - ", bodydata.uid); console.log('Requested Create - UID - ', bodydata.uid);
if (!bodydata.userName) if (!bodydata.userName) res.status(400).send({ message: 'Missing user name' });
res.status(400).send({ message: "Missing user name" }); if (!bodydata.partyName) res.status(400).send({ message: 'Missing party name' });
if (!bodydata.partyName) if (!bodydata.partyPin) res.status(400).send({ message: 'Missing party pin' });
res.status(400).send({ message: "Missing party name" });
if (!bodydata.partyPin)
res.status(400).send({ message: "Missing party pin" });
const roomNameTaken = await admin const roomNameTaken = await admin
.firestore() .firestore()
.collection("rooms") .collection('rooms')
.doc(bodydata.partyName.replace("/", "\\")) .doc(bodydata.partyName.replace('/', '\\'))
.get() .get()
.then((docSnap) => docSnap.exists); .then((docSnap) => docSnap.exists);
if (roomNameTaken) if (roomNameTaken) return res.status(409).send({ message: 'That party name is already taken' });
return res
.status(409)
.send({ message: "That party name is already taken" });
await admin await admin
.firestore() .firestore()
.collection("rooms") .collection('rooms')
.doc(bodydata.partyName) .doc(bodydata.partyName)
.set({ .set({
name: bodydata.partyName, name: bodydata.partyName,
@@ -32,17 +26,17 @@ module.exports = async (req, res) => {
adminOnly: bodydata.adminOnly, adminOnly: bodydata.adminOnly,
}) })
.catch((err) => { .catch((err) => {
res.status(500).send({ message: "Unable to start party." }); res.status(500).send({ message: 'Unable to start party.' });
console.error(err); console.error(err);
}); });
await admin await admin
.firestore() .firestore()
.collection("rooms") .collection('rooms')
.doc(bodydata.partyName) .doc(bodydata.partyName)
.collection("messages") .collection('messages')
.add({ .add({
uid: "<system>", uid: '<system>',
name: "", name: '',
text: `${bodydata.userName} started the party.`, text: `${bodydata.userName} started the party.`,
time: new Date(), time: new Date(),
}) })
@@ -54,9 +48,9 @@ module.exports = async (req, res) => {
}); });
await admin await admin
.firestore() .firestore()
.collection("rooms") .collection('rooms')
.doc(bodydata.partyName) .doc(bodydata.partyName)
.collection("users") .collection('users')
.doc(bodydata.uid) .doc(bodydata.uid)
.set({ .set({
admin: true, admin: true,
@@ -68,26 +62,24 @@ module.exports = async (req, res) => {
err err
); );
}); });
if (bodydata.player && bodydata.player.source === "amazon.") { if (
bodydata.player &&
(bodydata.player.source === 'amazon.' || bodydata.player.source === 'hulu.')
) {
await admin await admin
.firestore() .firestore()
.collection("rooms") .collection('rooms')
.doc(bodydata.partyName) .doc(bodydata.partyName)
.collection("messages") .collection('messages')
.add({ .add({
uid: "<system>", uid: '<system>',
name: "", name: '',
text: `Watch Party may not work with Prime Video temporarily. An update is coming to fix this.`, text: `Watch Party may not work temporarily. An update is coming to fix this.`,
time: new Date(), time: new Date(),
}) })
.catch((err) => { .catch((err) => {
console.error( console.error(`Failed to add amazon error message : \n\t Room: ${bodydata.partyName}`, err);
`Failed to add amazon error message : \n\t Room: ${bodydata.partyName}`,
err
);
}); });
} }
res res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
.status(201)
.send({ roomId: bodydata.partyName, message: "Started a party!" });
}; };