Skip to content

Commit de320d1

Browse files
committed
structure snapcast request functions
1 parent 4f9e793 commit de320d1

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

src/app/services/snapcast.service.ts

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ export class SnapcastService implements OnDestroy {
295295
);
296296
}
297297

298-
// --- Simplified Action Methods ---
298+
// --- "Simplified" Action Methods ---
299+
300+
// CLIENT ACTIONS
299301

300302
public setClientVolumePercent(clientId: string, percent: number): Observable<void> {
301303
if (percent < 0 || percent > 100) return throwError(() => new Error('Volume percentage must be between 0 and 100.'));
@@ -321,27 +323,17 @@ export class SnapcastService implements OnDestroy {
321323
);
322324
}
323325

324-
public setClientMute(clientId: string, mute: boolean): Observable<void> {
325-
return this.state$.pipe(
326-
take(1),
327-
switchMap(currentState => {
328-
const client = currentState?.server.groups.flatMap(g => g.clients).find(c => c.id === clientId);
329-
if (!client) return throwError(() => new Error(`Client ${clientId} not found.`));
330-
331-
const volumePayload: Volume = {
332-
percent: client.config.volume.percent, // Use current volume percent
333-
muted: mute,
334-
};
335-
return this.rpc('Client.SetVolume', { id: clientId, volume: volumePayload });
336-
}),
326+
setClientName(clientId: string, name: string): Observable<void> {
327+
return this.rpc('Client.SetName', { id: clientId, name }).pipe(
337328
map((): void => void 0),
338329
catchError(err => {
339-
console.error(`SnapcastService: Failed to set mute for client ${clientId}`, err);
330+
console.error(`SnapcastService: Failed to set name for client ${clientId}`, err);
340331
return throwError(() => err);
341332
})
342333
);
343334
}
344335

336+
345337
setGroupName(groupId: string, name: string): Observable<void> {
346338
return this.rpc('Group.SetName', { id: groupId, name }).pipe(
347339
map((): void => void 0),
@@ -370,18 +362,10 @@ export class SnapcastService implements OnDestroy {
370362

371363
}
372364

373-
setClientName(clientId: string, name: string): Observable<void> {
374-
return this.rpc('Client.SetName', { id: clientId, name }).pipe(
375-
map((): void => void 0),
376-
catchError(err => {
377-
console.error(`SnapcastService: Failed to set name for client ${clientId}`, err);
378-
return throwError(() => err);
379-
})
380-
);
381-
}
365+
366+
367+
382368

383-
// TODO ... Implement other action methods like.
384-
// They just need to call `this.rpc` with the correct parameters.
385369

386370
// --- Data Access Helpers ---
387371
public getClient(clientId: string): Observable<Client | undefined> {

0 commit comments

Comments
 (0)