Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-12 02:57:35 +03:00
1 parent 2d1d03db1e
commit ef3139ca64
60 files changed
+1774 -4412

No files matched your search

+1
View File
@@ -22,6 +22,7 @@ export type ViewName =
| 'search'
| 'library'
| 'stats'
| 'rooms'
| 'watch'
| 'server'
| 'rpc';
@@ -0,0 +1,11 @@
import { describe, expect, it } from 'vitest';
import { auditMethodName } from './auditMethods';
describe('audit RPC method mapping', () => {
it('keeps listening-room methods append-only and aligned with RpcTypes.hpp', () => {
expect(auditMethodName(53)).toBe('ListListeningRooms');
expect(auditMethodName(62)).toBe('GetListeningRoomQueue');
expect(auditMethodName(63)).toBe('SkipListeningRoom');
expect(auditMethodName(66)).toBe('ClearListeningRoomQueue');
});
});
@@ -58,6 +58,20 @@ const RPC_METHOD_BY_INDEX: readonly string[] = [
'AddCustomEmoji', // 50
'RemoveCustomEmoji',
'GetLyrics',
'ListListeningRooms',
'CreateListeningRoom',
'DeleteListeningRoom',
'JoinListeningRoom',
'LeaveListeningRoom',
'PlayInListeningRoom',
'PauseListeningRoom',
'ResumeListeningRoom',
'StopListeningRoom',
'GetListeningRoomQueue',
'SkipListeningRoom',
'RemoveFromListeningRoomQueue',
'MoveInListeningRoomQueue',
'ClearListeningRoomQueue',
];
export function auditMethodName(method: number): string {
+1
View File
@@ -13,6 +13,7 @@ const VIEWS: readonly ViewName[] = [
'search',
'library',
'stats',
'rooms',
'watch',
'server',
'rpc',
+14
View File
@@ -139,4 +139,18 @@ describe('RpcClient wire contract', () => {
});
expect(seen).toEqual([['queue.updated', { size: 3 }]]);
});
it('unsubscribes a notification listener', async () => {
installFakes();
const rpc = new RpcClient();
await rpc.connect();
const ws = FakeWebSocket.instances[0];
const seen: unknown[] = [];
const unsubscribe = rpc.on('listening_rooms.updated', (data) =>
seen.push(data)
);
unsubscribe();
ws.receive({ event: 'listening_rooms.updated', data: '{}' });
expect(seen).toEqual([]);
});
});
+23 -1
View File
@@ -64,7 +64,22 @@ export type RpcMethodName =
| 'SetUserPrefs'
| 'GetCustomEmojis'
| 'AddCustomEmoji'
| 'RemoveCustomEmoji';
| 'RemoveCustomEmoji'
| 'ListListeningRooms'
| 'CreateListeningRoom'
| 'DeleteListeningRoom'
| 'JoinListeningRoom'
| 'LeaveListeningRoom'
| 'PlayInListeningRoom'
| 'PauseListeningRoom'
| 'ResumeListeningRoom'
| 'StopListeningRoom'
| 'GetListeningRoomQueue'
| 'SkipListeningRoom'
| 'RemoveFromListeningRoomQueue'
| 'MoveInListeningRoomQueue'
| 'ClearListeningRoomQueue';
type Pending = {
resolve: (value: unknown) => void;
@@ -226,6 +241,13 @@ export class RpcClient {
on(event: string, cb: (...args: unknown[]) => void) {
if (!this.listeners.has(event)) this.listeners.set(event, []);
this.listeners.get(event)!.push(cb);
return () => {
const listeners = this.listeners.get(event);
if (!listeners) return;
const index = listeners.indexOf(cb);
if (index >= 0) listeners.splice(index, 1);
if (listeners.length === 0) this.listeners.delete(event);
};
}
authenticate(token: string) {
+15
View File
@@ -19,6 +19,21 @@ export interface QueueEntry {
addedBy?: string;
}
export interface ListeningRoom {
name: string;
ownerId: number;
members: number[];
isPlaying: boolean;
isPaused: boolean;
queueSize: number;
isOwner: boolean;
}
export interface ListeningRoomList {
rooms: ListeningRoom[];
currentRoom?: string;
}
export interface Status {
isPlaying?: boolean;
isPaused?: boolean;