feat: improve sync

This commit is contained in:
2026-09-08 11:20:17 +02:00
parent 047a3a8b29
commit b11882c993
19 changed files with 160 additions and 55 deletions
+6 -3
View File
@@ -41,7 +41,8 @@ const create = ( name: string, uid: string ) => {
'index': 0,
'lastUpdate': new Date().getTime(),
'playing': false,
'start': new Date().getTime()
'start': new Date().getTime(),
'offset': 0
}
};
@@ -112,9 +113,10 @@ const close = ( name: string, uid: string ) => {
* @param playing - Set to true if the player is playing currently
* @param index - The current playback index
* @param start - The timestamp where playback of the current song started
* @param offset - The playback offset from the start in seconds
* @returns true if update succeeded
*/
const updateState = ( room: string, uid: string, playing: boolean, index: number, start: number ) => {
const updateState = ( room: string, uid: string, playing: boolean, index: number, start: number, offset: number ) => {
if ( !rooms[room] || rooms[room].owner !== uid ) {
return false;
}
@@ -123,7 +125,8 @@ const updateState = ( room: string, uid: string, playing: boolean, index: number
'playing': playing,
'index': index,
'lastUpdate': new Date().getTime(),
'start': start
'start': start,
'offset': offset
};
return sendUpdate( room, 'state' );
+1
View File
@@ -20,6 +20,7 @@ export interface Room {
'start': number;
'playing': boolean;
'lastUpdate': number;
'offset': number;
};
'owner': string;
'clients': Client[];
+2 -1
View File
@@ -79,7 +79,8 @@ const routes = ( app: express.Application, foss: boolean, config: Config ) => {
sdk.getUID( request )!,
request.body.playing ?? false,
request.body.index ?? -1,
request.body.start ?? new Date().getTime()
request.body.start ?? new Date().getTime(),
request.body.offset ?? 0
) )
response.sendStatus( 200 );
else