mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-09 09:26:14 -08:00
refactor: extend channel model and store for epg
This commit is contained in:
2 files changed
+66
-3
No files matched your search
@@ -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>): Channel {
|
||||
name: params.name,
|
||||
group: params.group,
|
||||
url: params.url,
|
||||
tvg: params.tvg,
|
||||
} as Channel;
|
||||
}
|
||||
@@ -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<Channel> {
|
||||
active: Channel;
|
||||
@@ -54,12 +56,62 @@ export class ChannelStore extends EntityStore<ChannelState> {
|
||||
* @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,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user