diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index ded059f..a4aa6b9 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -19,6 +19,10 @@ const routes: Routes = [ loadChildren: () => import('./pages/server-status/server-status.module').then( m => m.ServerStatusPageModule) }, // { + // path: 'client-details', + // loadChildren: () => import('./pages/client-details/client-details.module').then( m => m.ClientDetailsPageModule) + // }, + // { // path: 'settings', // loadChildren: () => import('./pages/settings/settings.module').then( m => m.SettingsPageModule) // }, diff --git a/src/app/pages/clients/client-details/client-details-routing.module.ts b/src/app/pages/clients/client-details/client-details-routing.module.ts new file mode 100644 index 0000000..0e16e72 --- /dev/null +++ b/src/app/pages/clients/client-details/client-details-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { ClientDetailsPage } from './client-details.page'; + +const routes: Routes = [ + { + path: '', + component: ClientDetailsPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class ClientDetailsPageRoutingModule {} diff --git a/src/app/pages/clients/client-details/client-details.module.ts b/src/app/pages/clients/client-details/client-details.module.ts new file mode 100644 index 0000000..ed9636d --- /dev/null +++ b/src/app/pages/clients/client-details/client-details.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { ClientDetailsPageRoutingModule } from './client-details-routing.module'; + +import { ClientDetailsPage } from './client-details.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + ClientDetailsPageRoutingModule + ], + declarations: [ClientDetailsPage] +}) +export class ClientDetailsPageModule {} diff --git a/src/app/pages/clients/client-details/client-details.page.html b/src/app/pages/clients/client-details/client-details.page.html new file mode 100644 index 0000000..491c73a --- /dev/null +++ b/src/app/pages/clients/client-details/client-details.page.html @@ -0,0 +1,54 @@ + + + client-details + + + + + + + client-details + + + + + + +

Client ID: {{ id }}

+
+
+ + + + + + + + + +

{{ client.id }}

+

Group: {{ group.name || group.id }}

+

Volume: {{ client.config.volume.percent || 'N/A' }}%

+

Last Seen: {{ client.lastSeen.sec * 1000 | date }}

+

Connected: {{ client.connected }}

+
+
+
+
+
+
+ + + + + +

{{ client.id }}

+

{{ client.connected}}

+
+
+ +
{{ client| json }}
+
+
+
+
\ No newline at end of file diff --git a/src/app/pages/clients/client-details/client-details.page.scss b/src/app/pages/clients/client-details/client-details.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/clients/client-details/client-details.page.spec.ts b/src/app/pages/clients/client-details/client-details.page.spec.ts new file mode 100644 index 0000000..f6393c0 --- /dev/null +++ b/src/app/pages/clients/client-details/client-details.page.spec.ts @@ -0,0 +1,17 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ClientDetailsPage } from './client-details.page'; + +describe('ClientDetailsPage', () => { + let component: ClientDetailsPage; + let fixture: ComponentFixture; + + beforeEach(() => { + fixture = TestBed.createComponent(ClientDetailsPage); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/clients/client-details/client-details.page.ts b/src/app/pages/clients/client-details/client-details.page.ts new file mode 100644 index 0000000..083195b --- /dev/null +++ b/src/app/pages/clients/client-details/client-details.page.ts @@ -0,0 +1,70 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { Observable } from 'rxjs'; +import { Client, SnapCastServerStatusResponse } from 'src/app/model/snapcast.model'; +import { SnapcastService } from 'src/app/services/snapcast.service'; + +@Component({ + selector: 'app-client-details', + templateUrl: './client-details.page.html', + styleUrls: ['./client-details.page.scss'], + standalone: false +}) +export class ClientDetailsPage implements OnInit { + + + id?: string; + + serverState?: Observable; + client?: Client; + + + constructor( + private avtivateRoute: ActivatedRoute, + private snapcastService: SnapcastService + ) { } + + async ngOnInit() { + this.serverState = this.snapcastService.state$; + this.id = this.avtivateRoute.snapshot.paramMap.get('id') || undefined; + if (!this.id) { + console.error('ClientDetailsPage: No ID found in route parameters'); + return; + } + console.log('ClientDetailsPage: ID from route parameters:', this.id); + this.subscribeToClient(); + } + + subscribeToClient() { + if (!this.id) { + console.error('ClientDetailsPage: No ID available to subscribe to client'); + return; + } + this.serverState.subscribe((state) => { + this.client = state.server.groups.flatMap(group => group.clients).find(client => client.id === this.id); + if (!this.client) { + console.error(`ClientDetailsPage: Client with ID ${this.id} not found in server state`); + } else { + console.log('ClientDetailsPage: Found client:', this.client); + } + }); + } + + setClientName() { + if (!this.client || !this.client.id) { + console.error('ClientDetailsPage: No client or client ID available to set name'); + return; + } + this.snapcastService.setClientName(this.client.id, this.client.config.name).subscribe({ + next: () => { + console.log(`ClientDetailsPage: Successfully set name for client ${this.client.id} to ${name}`); + }, + error: (err) => { + console.error(`ClientDetailsPage: Failed to set name for client ${this.client.id}`, err); + } + }); + } + + + +} diff --git a/src/app/pages/devices/device-details/device-details.page.html b/src/app/pages/devices/device-details/device-details.page.html index 1f9063b..a07398b 100644 --- a/src/app/pages/devices/device-details/device-details.page.html +++ b/src/app/pages/devices/device-details/device-details.page.html @@ -41,7 +41,7 @@ - {{ client.id }} + {{ client.config.name || client.id }} diff --git a/src/app/pages/devices/devices.page.html b/src/app/pages/devices/devices.page.html index 47d2f94..5b4f2fe 100644 --- a/src/app/pages/devices/devices.page.html +++ b/src/app/pages/devices/devices.page.html @@ -25,22 +25,22 @@

{{ group.name || group.id }}

Clients - + - + -

{{ client.id }}

+

{{ client.config.name || client.id }} +

Group: {{ group.name || group.id }}

Volume: {{ client.config.volume.percent || 'N/A' }}%

Last Seen: {{ client.lastSeen.sec *1000 | date }}

Connected: {{ client.connected }}

-
-
- +
+ diff --git a/src/app/services/snapcast.service.ts b/src/app/services/snapcast.service.ts index cf600fa..39be99a 100644 --- a/src/app/services/snapcast.service.ts +++ b/src/app/services/snapcast.service.ts @@ -368,6 +368,16 @@ export class SnapcastService implements OnDestroy { } + setClientName(clientId: string, name: string): Observable { + return this.rpc('Client.SetName', { id: clientId, name }).pipe( + map((): void => void 0), + catchError(err => { + console.error(`SnapcastService: Failed to set name for client ${clientId}`, err); + return throwError(() => err); + }) + ); + } + // TODO ... Implement other action methods like. // They just need to call `this.rpc` with the correct parameters. @@ -376,7 +386,7 @@ export class SnapcastService implements OnDestroy { return this.state$.pipe(map(state => state?.server?.groups.flatMap(g => g.clients).find(c => c.id === clientId))); } - // TODO: ... other get... methods ... + // TODO: ... other get methods ... diff --git a/src/app/tabs/tabs-routing.module.ts b/src/app/tabs/tabs-routing.module.ts index 2c5f419..61d4d84 100644 --- a/src/app/tabs/tabs-routing.module.ts +++ b/src/app/tabs/tabs-routing.module.ts @@ -48,6 +48,18 @@ const routes: Routes = [ } ] }, + { + path: 'clients', + children: [ + // { path: '', + // loadChildren: () => import('../pages/clients/clients.module').then(m => m.ClientsPageModule) + // }, + { + path: ':id', + loadChildren: () => import('../pages/clients/client-details/client-details.module').then(m => m.ClientDetailsPageModule) + } + ] + }, { path: 'menu', loadChildren: () => import('../pages/menu/menu.module').then(m => m.MenuPageModule)