1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00

Fixed additional webOS 6.0/5.0 playback issues

This commit is contained in:
Michael Hollister 2025-02-19 12:46:09 -06:00
parent 5c071fb202
commit 593bb69d49
4 changed files with 21 additions and 29 deletions

View file

@ -45,7 +45,6 @@ export class Main {
keepAlive = activity;
});
// TODO: Fix issue of emitting events to non-existent subscribers after multiple page changes
const voidCb = (message: any) => { message.respond({ returnValue: true, value: {} }); };
const objectCb = (message: any, value: any) => { message.respond({ returnValue: true, value: value }); };
@ -95,7 +94,7 @@ export class Main {
},
(message: any) => {
Main.logger.info('Canceled play service subscriber');
Main.emitter.off('play', playClosureCb);
Main.emitter.removeAllListeners('play');
message.respond({ returnValue: true, value: message.payload });
});
@ -114,7 +113,7 @@ export class Main {
},
(message: any) => {
Main.logger.info('Canceled stop service subscriber');
Main.emitter.off('stop', stopClosureCb);
Main.emitter.removeAllListeners('stop');
message.respond({ returnValue: true, value: message.payload });
});
@ -208,7 +207,7 @@ function registerService(service: Service, method: string, callback: (message: a
},
(message: any) => {
Main.logger.info(`Canceled ${method} service subscriber`);
Main.emitter.off(method, callbackRef);
Main.emitter.removeAllListeners(method);
message.respond({ returnValue: true, value: message.payload });
});
}

View file

@ -27,6 +27,7 @@ try {
const playService = registerService('play', (message: any) => {
if (message.value !== undefined && message.value.playData !== undefined) {
console.log(`Main: Playing ${JSON.stringify(message)}`);
sessionStorage.setItem('playData', JSON.stringify(message.value.playData));
getDeviceInfoService.cancel();
toastService.cancel();
onConnectService.cancel();
@ -37,18 +38,18 @@ try {
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
// history.pushState({}, '', '../main_window/index.html');
window.open('../player/index.html');
window.open('../player/index.html', '_self');
}
});
const launchHandler = (args: any) => {
// args don't seem to be passed in via event despite what documentation says...
const launchHandler = () => {
const params = window.webOSDev.launchParams();
console.log(`Main: (Re)launching FCast Receiver with args: ${JSON.stringify(params)}`);
const lastTimestamp = localStorage.getItem('lastTimestamp');
const lastTimestamp = Number(localStorage.getItem('lastTimestamp'));
if (params.playData !== undefined && params.timestamp != lastTimestamp) {
localStorage.setItem('lastTimestamp', params.timestamp);
sessionStorage.setItem('playData', JSON.stringify(params.playData));
toastService?.cancel();
getDeviceInfoService?.cancel();
onConnectService?.cancel();
@ -59,12 +60,12 @@ try {
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
// history.pushState({}, '', '../main_window/index.html');
window.open('../player/index.html');
window.open('../player/index.html', '_self');
}
};
document.addEventListener('webOSLaunch', (ags) => { launchHandler(ags)});
document.addEventListener('webOSRelaunch', (ags) => { launchHandler(ags)});
document.addEventListener('webOSLaunch', launchHandler);
document.addEventListener('webOSRelaunch', launchHandler);
// Cannot go back to a state where user was previously casting a video, so exit.
// window.onpopstate = () => {

View file

@ -8,10 +8,8 @@ require('lib/webOSTVjs-1.2.10/webOSTV-dev.js');
try {
const serviceId = 'com.futo.fcast.receiver.service';
let playerWindowOpen = false;
window.webOSAPI = {
pendingPlay: null
pendingPlay: JSON.parse(sessionStorage.getItem('playData'))
};
preloadData.sendPlaybackErrorCb = (error: PlaybackErrorMessage) => {
@ -58,10 +56,6 @@ try {
}
if (message.value.playData !== null) {
if (!playerWindowOpen) {
playerWindowOpen = true;
}
if (preloadData.onPlayCb === undefined) {
window.webOSAPI.pendingPlay = message.value.playData;
}
@ -80,7 +74,6 @@ try {
const pauseService = registerService('pause', () => { preloadData.onPauseCb(); });
const resumeService = registerService('resume', () => { preloadData.onResumeCb(); });
const stopService = registerService('stop', () => {
playerWindowOpen = false;
playService.cancel();
pauseService.cancel();
resumeService.cancel();
@ -92,23 +85,22 @@ try {
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
// history.back();
window.open('../main_window/index.html');
window.open('../main_window/index.html', '_self');
});
const seekService = registerService('seek', (message: any) => { preloadData.onSeekCb(null, message.value); });
const setVolumeService = registerService('setvolume', (message: any) => { preloadData.onSetVolumeCb(null, message.value); });
const setSpeedService = registerService('setspeed', (message: any) => { preloadData.onSetSpeedCb(null, message.value); });
const launchHandler = (args: any) => {
const launchHandler = () => {
// args don't seem to be passed in via event despite what documentation says...
const params = window.webOSDev.launchParams();
console.log(`Player: (Re)launching FCast Receiver with args: ${JSON.stringify(params)}`);
const lastTimestamp = localStorage.getItem('lastTimestamp');
const lastTimestamp = Number(localStorage.getItem('lastTimestamp'));
if (params.playData !== undefined && params.timestamp != lastTimestamp) {
localStorage.setItem('lastTimestamp', params.timestamp);
playerWindowOpen = false;
sessionStorage.setItem('playData', JSON.stringify(params.playData));
playService?.cancel();
pauseService?.cancel();
resumeService?.cancel();
@ -120,12 +112,12 @@ try {
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
// history.pushState({}, '', '../main_window/index.html');
window.open('../player/index.html');
window.open('../player/index.html', '_self');
}
};
document.addEventListener('webOSLaunch', (ags) => { launchHandler(ags)});
document.addEventListener('webOSRelaunch', (ags) => { launchHandler(ags)});
document.addEventListener('webOSLaunch', launchHandler);
document.addEventListener('webOSRelaunch', launchHandler);
}
catch (err) {

View file

@ -91,7 +91,7 @@ export function targetKeyDownEventListener(event: any): boolean {
switch (event.keyCode) {
case RemoteKeyCode.Stop:
// history.back();
window.open('../main_window/index.html');
window.open('../main_window/index.html', '_self');
handledCase = true;
break;
@ -126,7 +126,7 @@ export function targetKeyDownEventListener(event: any): boolean {
// so manually handling page navigation...
case RemoteKeyCode.Back:
// history.back();
window.open('../main_window/index.html');
window.open('../main_window/index.html', '_self');
event.preventDefault();
handledCase = true;
break;