v1.6.0/fix peacock sync
This commit is contained in:
+22
-21
@@ -86,6 +86,7 @@ export default class VideoListener {
|
|||||||
await this.video.element
|
await this.video.element
|
||||||
.play()
|
.play()
|
||||||
.catch((err) => console.error('WatchParty erred when syncing time.'));
|
.catch((err) => console.error('WatchParty erred when syncing time.'));
|
||||||
|
await this.timeout(250);
|
||||||
this.video.element.currentTime = serverPlayer.time;
|
this.video.element.currentTime = serverPlayer.time;
|
||||||
await this.timeout(500);
|
await this.timeout(500);
|
||||||
break;
|
break;
|
||||||
@@ -104,14 +105,14 @@ export default class VideoListener {
|
|||||||
this.video.element.currentTime = serverPlayer.time;
|
this.video.element.currentTime = serverPlayer.time;
|
||||||
break;
|
break;
|
||||||
case PLAYER_SOURCE.PEACOCK:
|
case PLAYER_SOURCE.PEACOCK:
|
||||||
const sliderHead = document.body.querySelector(
|
window.postMessage(
|
||||||
'.playback-scrubber-bar .rc-slider-handle'
|
JSON.stringify({
|
||||||
|
watchPartyDirection: 'TO_SCRIPT',
|
||||||
|
type: 'WATCH_PARTY_SEEK',
|
||||||
|
status: serverPlayer.status,
|
||||||
|
time: serverPlayer.time,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
sliderHead.style.left =
|
|
||||||
((serverPlayer.time * 1000) / sliderHead.getAttribute('aria-valueMax')) * 100 + '%';
|
|
||||||
simulate(sliderHead, 'mousedown');
|
|
||||||
simulate(sliderHead, 'mouseup');
|
|
||||||
await this.timeout(500);
|
|
||||||
break;
|
break;
|
||||||
case PLAYER_SOURCE.GOOGLEPLAY:
|
case PLAYER_SOURCE.GOOGLEPLAY:
|
||||||
this.video.element.currentTime = serverPlayer.time;
|
this.video.element.currentTime = serverPlayer.time;
|
||||||
@@ -140,7 +141,10 @@ export default class VideoListener {
|
|||||||
PLAYER_SOURCE.HBONOW === this.video.source
|
PLAYER_SOURCE.HBONOW === this.video.source
|
||||||
) {
|
) {
|
||||||
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 ||
|
||||||
|
PLAYER_SOURCE.PEACOCK === this.video.source
|
||||||
|
) {
|
||||||
window.postMessage(
|
window.postMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
watchPartyDirection: 'TO_SCRIPT',
|
watchPartyDirection: 'TO_SCRIPT',
|
||||||
@@ -161,7 +165,10 @@ export default class VideoListener {
|
|||||||
PLAYER_SOURCE.HBONOW === this.video.source
|
PLAYER_SOURCE.HBONOW === this.video.source
|
||||||
) {
|
) {
|
||||||
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 ||
|
||||||
|
PLAYER_SOURCE.PEACOCK === this.video.source
|
||||||
|
) {
|
||||||
window.postMessage(
|
window.postMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
watchPartyDirection: 'TO_SCRIPT',
|
watchPartyDirection: 'TO_SCRIPT',
|
||||||
@@ -304,12 +311,6 @@ export default class VideoListener {
|
|||||||
this.updateStatus({
|
this.updateStatus({
|
||||||
element: videoElement,
|
element: videoElement,
|
||||||
});
|
});
|
||||||
// if (videoElement.currentTime > 0 && !videoElement.paused) {
|
|
||||||
// this.updateStatus({
|
|
||||||
// time: videoElement.currentTime,
|
|
||||||
// status: PLAYER_STATUS.PLAYING,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
this.updateStatus({
|
this.updateStatus({
|
||||||
showName: await this.getShowName(),
|
showName: await this.getShowName(),
|
||||||
});
|
});
|
||||||
@@ -510,9 +511,11 @@ export default class VideoListener {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PLAYER_SOURCE.PEACOCK:
|
case PLAYER_SOURCE.PEACOCK:
|
||||||
const peacockVideoElement = document.querySelector(
|
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);`;
|
||||||
'#mount > div > div > div > div > div > div.video-player-component.playback-component > div > video'
|
const peacockInjectScript = document.createElement('script');
|
||||||
);
|
peacockInjectScript.text = peacockInject;
|
||||||
|
document.head.appendChild(peacockInjectScript);
|
||||||
|
const peacockVideoElement = document.querySelector(".video-player-component.playback-component video")
|
||||||
if (peacockVideoElement) {
|
if (peacockVideoElement) {
|
||||||
this.firstTimeSync(peacockVideoElement);
|
this.firstTimeSync(peacockVideoElement);
|
||||||
} else {
|
} else {
|
||||||
@@ -520,9 +523,7 @@ export default class VideoListener {
|
|||||||
this.video.element
|
this.video.element
|
||||||
? null
|
? null
|
||||||
: () => {
|
: () => {
|
||||||
var pve = document.querySelector(
|
var pve = document.querySelector(".video-player-component.playback-component video");
|
||||||
'#mount > div > div > div > div > div > div.video-player-component.playback-component > div > video'
|
|
||||||
);
|
|
||||||
if (
|
if (
|
||||||
pve !== null &&
|
pve !== null &&
|
||||||
pve !== undefined &&
|
pve !== undefined &&
|
||||||
|
|||||||
Reference in New Issue
Block a user