diff --git a/electron/api.ts b/electron/api.ts index 1fac5f391..bd38f54dd 100644 --- a/electron/api.ts +++ b/electron/api.ts @@ -150,8 +150,11 @@ export class Api { .on( CHANNEL_SET_USER_AGENT, (_event, args: { userAgent: string; referer?: string }) => { - if (args.userAgent && args.referer) { - this.setUserAgent(args.userAgent, args.referer); + if (args.userAgent && args.referer !== undefined) { + this.setUserAgent( + args.userAgent, + args.referer || 'localhost' + ); } else { this.setUserAgent(this.defaultUserAgent, 'localhost'); } @@ -281,6 +284,7 @@ export class Api { * @param referer referer to use */ setUserAgent(userAgent: string, referer?: string): void { + console.log('here we go', userAgent); if (userAgent === undefined || userAgent === null || userAgent === '') { userAgent = this.defaultUserAgent; } diff --git a/src/app/player/components/video-player/video-player.component.ts b/src/app/player/components/video-player/video-player.component.ts index 22799380e..5f4f71f1f 100644 --- a/src/app/player/components/video-player/video-player.component.ts +++ b/src/app/player/components/video-player/video-player.component.ts @@ -12,15 +12,10 @@ import { MatSnackBar } from '@angular/material/snack-bar'; import { ActivatedRoute } from '@angular/router'; import { Store } from '@ngrx/store'; import { StorageMap } from '@ngx-pwa/local-storage'; -import { - Observable, - combineLatestWith, - filter, - skipWhile, - switchMap, -} from 'rxjs'; +import { Observable, combineLatestWith, filter, map, switchMap } from 'rxjs'; import { Channel } from '../../../../../shared/channel.interface'; import { + CHANNEL_SET_USER_AGENT, ERROR, PLAYLIST_PARSE_BY_URL, PLAYLIST_PARSE_RESPONSE, @@ -35,7 +30,6 @@ import { selectActive, selectChannels, selectCurrentEpgProgram, - selectPlaylistTitle, } from '../../../state/selectors'; import { MultiEpgContainerComponent } from '../multi-epg/multi-epg-container.component'; @@ -68,11 +62,6 @@ export class VideoPlayerComponent implements OnInit, OnDestroy { showCaptions: false, }; - /** Title of the current playlist */ - playlistTitle$ = this.store - .select(selectPlaylistTitle) - .pipe(skipWhile((playlistFilename) => playlistFilename === '')); - /** IPC Renderer commands list with callbacks */ commandsList = [ { @@ -141,7 +130,20 @@ export class VideoPlayerComponent implements OnInit, OnDestroy { playlistId: params.id, }) ); - return this.playlistsService.getPlaylistChannels(params.id); + return this.playlistsService.getPlaylist(params.id).pipe( + map((playlist) => { + if (playlist.userAgent) { + this.dataService.sendIpcEvent( + CHANNEL_SET_USER_AGENT, + { + referer: 'localhost', + userAgent: playlist.userAgent, + } + ); + } + return playlist.playlist.items; + }) + ); } else if (queryParams.url) { return this.store.select(selectChannels); } diff --git a/src/app/services/playlists.service.ts b/src/app/services/playlists.service.ts index e4d30fc48..b4041eb17 100644 --- a/src/app/services/playlists.service.ts +++ b/src/app/services/playlists.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { parse } from 'iptv-playlist-parser'; import { NgxIndexedDBService } from 'ngx-indexed-db'; -import { combineLatest, map, Observable, switchMap } from 'rxjs'; +import { combineLatest, map, switchMap } from 'rxjs'; import { Channel } from '../../../shared/channel.interface'; import { GLOBAL_FAVORITES_PLAYLIST_ID } from '../../../shared/constants'; import { @@ -40,19 +40,12 @@ export class PlaylistsService { return this.dbService.add(DbStores.Playlists, playlist); } - getPlaylistChannels(id: string) { - let playlist$: Observable>; + getPlaylist(id: string) { if (id === GLOBAL_FAVORITES_PLAYLIST_ID) { - playlist$ = this.getPlaylistWithGlobalFavorites(); + return this.getPlaylistWithGlobalFavorites(); } else { - playlist$ = this.dbService.getByID( - DbStores.Playlists, - id - ); + return this.dbService.getByID(DbStores.Playlists, id); } - return playlist$.pipe( - map((data: Playlist) => data.playlist.items as Channel[]) - ); } deletePlaylist(playlistId: string) { @@ -84,6 +77,7 @@ export class PlaylistsService { ...playlist, title: updatedPlaylist.title, autoRefresh: updatedPlaylist.autoRefresh, + userAgent: updatedPlaylist.userAgent, }) ) );