From 60b34cd740bf195f0c100b0c341f883658254a85 Mon Sep 17 00:00:00 2001 From: b040213 Date: Thu, 31 Oct 2024 14:08:09 +0100 Subject: [PATCH] start timers --- .../src/app/blabla/blabla-epg.service.ts | 27 ++++++++++++++++--- .../app/blabla/player/player.component.html | 4 +-- .../src/app/blabla/player/player.component.ts | 6 +++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/blablaspotify_frontend/src/app/blabla/blabla-epg.service.ts b/blablaspotify_frontend/src/app/blabla/blabla-epg.service.ts index 101fb5d..dbf9fd3 100644 --- a/blablaspotify_frontend/src/app/blabla/blabla-epg.service.ts +++ b/blablaspotify_frontend/src/app/blabla/blabla-epg.service.ts @@ -1,18 +1,21 @@ +import {HttpClient} from '@angular/common/http'; import { inject, Injectable } from '@angular/core'; import { Subscription, timer } from 'rxjs'; import { isAfter, subSeconds } from 'date-fns' import { ControlsService } from '../controls/controls.service'; -import { Program } from '../types'; +import {Program, ProgramList} from '../types'; @Injectable({ providedIn: 'root' }) export class BlaBlaEpgService { private _controlsService = inject(ControlsService) + private _httpClient = inject(HttpClient) private _subscriptions: Subscription[] = [] - scheduleBlaBla(lineup: Program[]) { + scheduleBlaBla(programList: ProgramList) { + console.log('scheduleBlaBla: ', programList); this.cancelExistingSchedule() - this._subscriptions = lineup.flatMap(program => this.createScheduleEntry(program)) + this._subscriptions = programList.programs.flatMap(program => this.createScheduleEntry(program)) .filter(scheduleEntry => isAfter(scheduleEntry.on, new Date())) .map(scheduleEntry => timer(scheduleEntry.on) .subscribe(() => this._controlsService.setPlayBackSource(scheduleEntry.type === 'start' ? 'blabla': 'music')) @@ -30,4 +33,20 @@ export class BlaBlaEpgService { this._subscriptions.forEach(subscription => subscription.unsubscribe()) this._subscriptions = [] } -} \ No newline at end of file + + stationChanged(stationId: string) { + console.log('Station changed to: ', stationId); + this.getProgramList(stationId); + } + + getProgramList(stationId: string) { + this._httpClient.get('/api/blabla/programGuides/' + stationId).subscribe({ + next: (response: any) => { + this.scheduleBlaBla(response as ProgramList); + }, + error: (error: any) => { + console.error('Failed to get program list: ', error) + } + }); + } +} diff --git a/blablaspotify_frontend/src/app/blabla/player/player.component.html b/blablaspotify_frontend/src/app/blabla/player/player.component.html index 930f6e9..e82e31e 100644 --- a/blablaspotify_frontend/src/app/blabla/player/player.component.html +++ b/blablaspotify_frontend/src/app/blabla/player/player.component.html @@ -7,7 +7,7 @@ Sender - + @for(station of stationList(); track station.epgId) { {{ station.name }} } @@ -15,4 +15,4 @@ - \ No newline at end of file + diff --git a/blablaspotify_frontend/src/app/blabla/player/player.component.ts b/blablaspotify_frontend/src/app/blabla/player/player.component.ts index 65c477c..99f9840 100644 --- a/blablaspotify_frontend/src/app/blabla/player/player.component.ts +++ b/blablaspotify_frontend/src/app/blabla/player/player.component.ts @@ -1,6 +1,7 @@ import { Component, computed, signal, viewChild, ElementRef, inject, model, effect, untracked, input } from '@angular/core'; import { MatIconButton } from '@angular/material/button'; import { MatCard, MatCardContent, MatCardHeader, MatCardTitle } from '@angular/material/card'; +import {BlaBlaEpgService} from '../blabla-epg.service'; import { RadioStationFacade } from '../data-access/radio-station.facade'; import { MatFormField, MatLabel } from '@angular/material/form-field'; import { MatOption, MatSelect } from '@angular/material/select'; @@ -28,6 +29,7 @@ export class PlayerComponent { readonly isActive = input.required() private _radioStationFacade = inject(RadioStationFacade) + private _epgService = inject(BlaBlaEpgService) protected readonly playerElement = viewChild>('player') @@ -64,4 +66,8 @@ export class PlayerComponent { const station = this._radioStationFacade.stations().find(station => station.epgId === epgId) return station === undefined ? '' : station.streamUrl } + + onStationValueChange() { + this._epgService.stationChanged(this.selectedStation()); + } }