mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +00:00
Fixing app relaunching when suspended
This commit is contained in:
parent
77728af69e
commit
5328087d64
5 changed files with 130 additions and 81 deletions
|
@ -1,7 +1,6 @@
|
|||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export {};
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
@ -13,6 +12,7 @@ declare global {
|
|||
}
|
||||
|
||||
let deviceInfo: any;
|
||||
let preloadData: Record<string, any> = {};
|
||||
|
||||
// @ts-ignore
|
||||
if (TARGET === 'electron') {
|
||||
|
@ -35,18 +35,6 @@ if (TARGET === 'electron') {
|
|||
const serviceId = 'com.futo.fcast.receiver.service';
|
||||
let onDeviceInfoCb = () => { console.log('Main: Callback not set while fetching device info'); };
|
||||
|
||||
const keepAliveService = window.webOS.service.request(`luna://${serviceId}/`, {
|
||||
method:"keepAlive",
|
||||
parameters: {},
|
||||
onSuccess: (message: any) => {
|
||||
console.log(`Main: keepAlive ${JSON.stringify(message)}`);
|
||||
},
|
||||
onFailure: (message: any) => {
|
||||
console.error(`Main: keepAlive ${JSON.stringify(message)}`);
|
||||
},
|
||||
// onComplete: (message) => {},
|
||||
});
|
||||
|
||||
const getDeviceInfoService = window.webOS.service.request(`luna://${serviceId}/`, {
|
||||
method:"getDeviceInfo",
|
||||
parameters: {},
|
||||
|
@ -62,56 +50,19 @@ if (TARGET === 'electron') {
|
|||
// onComplete: (message) => {},
|
||||
});
|
||||
|
||||
const playService = window.webOS.service.request(`luna://${serviceId}/`, {
|
||||
method:"play",
|
||||
parameters: {},
|
||||
onSuccess: (message: any) => {
|
||||
if (message.value.subscribed === true) {
|
||||
console.log('Main: Registered play handler with service');
|
||||
}
|
||||
else {
|
||||
if (message.value !== undefined && message.value.playData !== undefined) {
|
||||
console.log(`Main: Playing ${JSON.stringify(message)}`);
|
||||
getDeviceInfoService.cancel();
|
||||
playService.cancel();
|
||||
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
},
|
||||
onFailure: (message: any) => {
|
||||
console.error(`Main: play ${JSON.stringify(message)}`);
|
||||
},
|
||||
subscribe: true,
|
||||
resubscribe: true
|
||||
});
|
||||
|
||||
window.targetAPI = {
|
||||
onDeviceInfo: (callback: () => void) => onDeviceInfoCb = callback,
|
||||
getDeviceInfo: () => deviceInfo,
|
||||
};
|
||||
|
||||
document.addEventListener('webOSRelaunch', (args: any) => {
|
||||
console.log(`Relaunching FCast Receiver with args: ${JSON.stringify(args)}`);
|
||||
|
||||
if (args.playData !== undefined) {
|
||||
if (getDeviceInfoService !== undefined) {
|
||||
getDeviceInfoService.cancel();
|
||||
}
|
||||
if (playService !== undefined) {
|
||||
playService.cancel();
|
||||
}
|
||||
|
||||
// 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');
|
||||
}
|
||||
});
|
||||
preloadData = {
|
||||
getDeviceInfoService: getDeviceInfoService,
|
||||
};
|
||||
} else {
|
||||
// @ts-ignore
|
||||
console.log(`Attempting to run FCast player on unsupported target: ${TARGET}`);
|
||||
}
|
||||
|
||||
export {
|
||||
preloadData
|
||||
};
|
||||
|
|
|
@ -13,6 +13,8 @@ declare global {
|
|||
}
|
||||
}
|
||||
|
||||
let preloadData: Record<string, any> = {};
|
||||
|
||||
// @ts-ignore
|
||||
if (TARGET === 'electron') {
|
||||
// @ts-ignore
|
||||
|
@ -40,18 +42,6 @@ if (TARGET === 'electron') {
|
|||
let onSeekCb, onSetVolumeCb, onSetSpeedCb;
|
||||
let playerWindowOpen = false;
|
||||
|
||||
const keepAliveService = window.webOS.service.request(`luna://${serviceId}/`, {
|
||||
method:"keepAlive",
|
||||
parameters: {},
|
||||
onSuccess: (message: any) => {
|
||||
console.log(`Player: keepAlive ${JSON.stringify(message)}`);
|
||||
},
|
||||
onFailure: (message: any) => {
|
||||
console.error(`Player: keepAlive ${JSON.stringify(message)}`);
|
||||
},
|
||||
// onComplete: (message) => {},
|
||||
});
|
||||
|
||||
const playService = window.webOS.service.request(`luna://${serviceId}/`, {
|
||||
method:"play",
|
||||
parameters: {},
|
||||
|
@ -248,7 +238,21 @@ if (TARGET === 'electron') {
|
|||
pendingPlay: null
|
||||
};
|
||||
|
||||
preloadData = {
|
||||
playerWindowOpen: playerWindowOpen,
|
||||
playService: playService,
|
||||
pauseService: pauseService,
|
||||
resumeService: resumeService,
|
||||
stopService: stopService,
|
||||
seekService: seekService,
|
||||
setVolumeService: setVolumeService,
|
||||
setSpeedService: setSpeedService,
|
||||
};
|
||||
} else {
|
||||
// @ts-ignore
|
||||
console.log(`Attempting to run FCast player on unsupported target: ${TARGET}`);
|
||||
}
|
||||
|
||||
export {
|
||||
preloadData
|
||||
};
|
||||
|
|
|
@ -37,16 +37,10 @@ export class Main {
|
|||
const serviceId = 'com.futo.fcast.receiver.service';
|
||||
const service = new Service(serviceId);
|
||||
|
||||
// Not compatible with WebOS 22 and earlier simulator?
|
||||
// Service will timeout and casting will disconnect if not forced to be kept alive
|
||||
// let keepAlive;
|
||||
// service.activityManager.create("keepAlive", function(activity) {
|
||||
// keepAlive = activity;
|
||||
// });
|
||||
|
||||
service.register("keepAlive", (_message: any) => {
|
||||
Main.logger.info("In keepAlive callback");
|
||||
// Do not respond to keep service alive
|
||||
let keepAlive;
|
||||
service.activityManager.create("keepAlive", function(activity) {
|
||||
keepAlive = activity;
|
||||
});
|
||||
|
||||
service.register("getDeviceInfo", (message: any) => {
|
||||
|
@ -198,7 +192,7 @@ export class Main {
|
|||
const appId = 'com.futo.fcast.receiver';
|
||||
service.call("luna://com.webos.applicationManager/launch", {
|
||||
'id': appId,
|
||||
'params': { playData: message }
|
||||
'params': { timestamp: Date.now(), playData: message }
|
||||
}, (response: any) => {
|
||||
Main.logger.info(`Launch response: ${JSON.stringify(response)}`);
|
||||
Main.logger.info(`Relaunching FCast Receiver with args: ${JSON.stringify(message)}`);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'common/main/Preload';
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { preloadData } from 'common/main/Preload';
|
||||
|
||||
enum RemoteKeyCode {
|
||||
Stop = 413,
|
||||
|
@ -9,6 +10,60 @@ enum RemoteKeyCode {
|
|||
Back = 461,
|
||||
}
|
||||
|
||||
const serviceId = 'com.futo.fcast.receiver.service';
|
||||
|
||||
const playService = window.webOS.service.request(`luna://${serviceId}/`, {
|
||||
method:"play",
|
||||
parameters: {},
|
||||
onSuccess: (message: any) => {
|
||||
if (message.value.subscribed === true) {
|
||||
console.log('Main: Registered play handler with service');
|
||||
}
|
||||
else {
|
||||
if (message.value !== undefined && message.value.playData !== undefined) {
|
||||
console.log(`Main: Playing ${JSON.stringify(message)}`);
|
||||
preloadData.getDeviceInfoService.cancel();
|
||||
playService.cancel();
|
||||
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
},
|
||||
onFailure: (message: any) => {
|
||||
console.error(`Main: play ${JSON.stringify(message)}`);
|
||||
},
|
||||
subscribe: true,
|
||||
resubscribe: true
|
||||
});
|
||||
|
||||
const launchHandler = (args: any) => {
|
||||
// args don't seem to be passed in via event despite what documentation says...
|
||||
const params = window.webOSDev.launchParams();
|
||||
console.log(`Main: (Re)launching FCast Receiver with args: ${JSON.stringify(params)}`);
|
||||
|
||||
const lastTimestamp = localStorage.getItem('lastTimestamp');
|
||||
if (params.playData !== undefined && params.timestamp != lastTimestamp) {
|
||||
localStorage.setItem('lastTimestamp', params.timestamp);
|
||||
if (preloadData.getDeviceInfoService !== undefined) {
|
||||
preloadData.getDeviceInfoService.cancel();
|
||||
}
|
||||
if (playService !== undefined) {
|
||||
playService.cancel();
|
||||
}
|
||||
|
||||
// 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');
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('webOSLaunch', (ags) => { console.log('lunch'); launchHandler(ags)});
|
||||
document.addEventListener('webOSRelaunch', (ags) => { console.log('relun'); launchHandler(ags)});
|
||||
|
||||
// Cannot go back to a state where user was previously casting a video, so exit.
|
||||
// window.onpopstate = () => {
|
||||
// window.webOS.platformBack();
|
||||
|
|
|
@ -1 +1,46 @@
|
|||
import 'common/player/Preload';
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { preloadData } from 'common/player/Preload';
|
||||
|
||||
const launchHandler = (args: any) => {
|
||||
// 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');
|
||||
if (params.playData !== undefined && params.timestamp != lastTimestamp) {
|
||||
localStorage.setItem('lastTimestamp', params.timestamp);
|
||||
|
||||
if (preloadData.playerWindowOpen !== undefined) {
|
||||
preloadData.playerWindowOpen = false;
|
||||
}
|
||||
if (preloadData.playService !== undefined) {
|
||||
preloadData.playService.cancel();
|
||||
}
|
||||
if (preloadData.pauseService !== undefined) {
|
||||
preloadData.pauseService.cancel();
|
||||
}
|
||||
if (preloadData.resumeService !== undefined) {
|
||||
preloadData.resumeService.cancel();
|
||||
}
|
||||
if (preloadData.stopService !== undefined) {
|
||||
preloadData.stopService.cancel();
|
||||
}
|
||||
if (preloadData.seekService !== undefined) {
|
||||
preloadData.seekService.cancel();
|
||||
}
|
||||
if (preloadData.setVolumeService !== undefined) {
|
||||
preloadData.setVolumeService.cancel();
|
||||
}
|
||||
if (preloadData.setSpeedService !== undefined) {
|
||||
preloadData.setSpeedService.cancel();
|
||||
}
|
||||
|
||||
// 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');
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('webOSLaunch', (ags) => { console.log('lunch'); launchHandler(ags)});
|
||||
document.addEventListener('webOSRelaunch', (ags) => { console.log('relun'); launchHandler(ags)});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue