diff --git a/src/app/state/channel.model.ts b/src/app/state/channel.model.ts index fd9b106d9..4754191cc 100755 --- a/src/app/state/channel.model.ts +++ b/src/app/state/channel.model.ts @@ -9,6 +9,16 @@ export interface Channel { group: { title: string; }; + tvg: { + id: string; + name: string; + language: string; + country: string; + url: string; + logo: string; + rec: string; + }; + epgParams?: string; } /** @@ -21,5 +31,6 @@ export function createChannel(params: Partial): Channel { name: params.name, group: params.group, url: params.url, + tvg: params.tvg, } as Channel; } diff --git a/src/app/state/channel.store.ts b/src/app/state/channel.store.ts index 4e939ad2c..e25ba6aa7 100644 --- a/src/app/state/channel.store.ts +++ b/src/app/state/channel.store.ts @@ -3,6 +3,8 @@ import { EntityState, EntityStore, StoreConfig } from '@datorama/akita'; import { EPG_GET_PROGRAM } from '../shared/ipc-commands'; import { ElectronService } from '../services/electron.service'; import { Channel } from './channel.model'; +import * as moment from 'moment'; +import { EpgProgram } from 'app/player/models/epg-program.model'; export interface ChannelState extends EntityState { active: Channel; @@ -54,12 +56,62 @@ export class ChannelStore extends EntityStore { * @param channel selected channel */ setActiveChannel(channel: Channel): void { + this.update((store) => { + if (store.epgAvailable) { + this.electronService.ipcRenderer.send(EPG_GET_PROGRAM, { + channelName: channel.name, + }); + } + return { + ...store, + active: { ...channel, epgParams: '' }, + }; + }); + } + + /** + * Sets the given timestamp for the epg program + * @param program epg program to set as active + */ + setActiveEpgProgram(program: EpgProgram): void { + const from = moment( + program['_attributes'].start, + 'YYYYMMDDHHmm ZZ' + ).unix(); + const now = moment(Date.now()).unix(); + const epgParams = `?utc=${from}&lutc=${now}`; this.update((store) => ({ ...store, - active: channel, + active: { ...store.active, epgParams }, })); - this.electronService.ipcRenderer.send(EPG_GET_PROGRAM, { - channelName: channel.name, + } + + /** + * Sets the active channel from epg program back to the live translation + */ + resetActiveEpgProgram(): void { + this.update((store) => ({ + ...store, + active: { ...store.active, epgParams: '' }, + })); + } + + /** + * Updates the epg availability flag + * @param value + */ + setEpgAvailableFlag(value: boolean): void { + this.update((store) => { + if (store.active && store.active.name) { + this.electronService.ipcRenderer.send(EPG_GET_PROGRAM, { + channelName: store.active.name, + }); + } + + return { + ...store, + epgAvailable: value, + }; }); } }