mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 10:03:33 +00:00
[enhancement]: support viewing current/setting current time in remote
This commit is contained in:
parent
b347b794b9
commit
5b2977e5e8
9 changed files with 61 additions and 13 deletions
|
|
@ -34,13 +34,14 @@ interface MimeType {
|
|||
js: string;
|
||||
}
|
||||
|
||||
interface StatefulWebSocket extends WebSocket {
|
||||
declare class StatefulWebSocket extends WebSocket {
|
||||
alive: boolean;
|
||||
|
||||
auth: boolean;
|
||||
}
|
||||
|
||||
let server: Server | undefined;
|
||||
let wsServer: WsServer<StatefulWebSocket> | undefined;
|
||||
let wsServer: WsServer<typeof StatefulWebSocket> | undefined;
|
||||
|
||||
const settings: RemoteConfig = {
|
||||
enabled: false,
|
||||
|
|
@ -327,9 +328,9 @@ const enableServer = (config: RemoteConfig): Promise<void> => {
|
|||
});
|
||||
|
||||
server.listen(config.port, resolve);
|
||||
wsServer = new WebSocketServer({ server });
|
||||
wsServer = new WebSocketServer<typeof StatefulWebSocket>({ server });
|
||||
|
||||
wsServer.on('connection', (ws) => {
|
||||
wsServer!.on('connection', (ws: StatefulWebSocket) => {
|
||||
let authFail: number | undefined;
|
||||
ws.alive = true;
|
||||
|
||||
|
|
@ -471,6 +472,15 @@ const enableServer = (config: RemoteConfig): Promise<void> => {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 'position': {
|
||||
const { position } = json;
|
||||
if (mprisPlayer) {
|
||||
mprisPlayer.getPosition = () => position * 1e6;
|
||||
}
|
||||
getMainWindow()?.webContents.send('request-position', {
|
||||
position,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
|
@ -496,7 +506,7 @@ const enableServer = (config: RemoteConfig): Promise<void> => {
|
|||
});
|
||||
}, PING_TIMEOUT_MS);
|
||||
|
||||
wsServer.on('close', () => {
|
||||
wsServer!.on('close', () => {
|
||||
clearInterval(heartBeat);
|
||||
});
|
||||
|
||||
|
|
@ -649,3 +659,8 @@ if (mprisPlayer) {
|
|||
broadcast({ data: volume, event: 'volume' });
|
||||
});
|
||||
}
|
||||
|
||||
ipcMain.on('update-position', (_event, position: number) => {
|
||||
currentState.position = position;
|
||||
broadcast({ data: position, event: 'position' });
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue