diff --git a/electron/api.ts b/electron/api.ts index 0843c3009..1534b934e 100644 --- a/electron/api.ts +++ b/electron/api.ts @@ -169,14 +169,12 @@ export class Api { .on( CHANNEL_SET_USER_AGENT, (_event, args: { userAgent: string; referer?: string }) => { - if (args.userAgent && args.referer !== undefined) { + if (args.userAgent || args.referer !== undefined) { this.setUserAgent( - args.userAgent, + args.userAgent || 'localhost', args.referer || 'localhost' ); - } else { - this.setUserAgent(this.defaultUserAgent, 'localhost'); - } + } } ) .on(IS_PLAYLISTS_MIGRATION_POSSIBLE, (event) => { diff --git a/src/app/player/components/html-video-player/html-video-player.component.ts b/src/app/player/components/html-video-player/html-video-player.component.ts index e4ac2b9c6..643bbecdb 100644 --- a/src/app/player/components/html-video-player/html-video-player.component.ts +++ b/src/app/player/components/html-video-player/html-video-player.component.ts @@ -10,6 +10,8 @@ import { import Hls from 'hls.js'; import { Channel } from '../../../../../shared/channel.interface'; import { getExtensionFromUrl } from '../../../../../shared/playlist.utils'; +import { DataService } from '../../../services/data.service'; +import { CHANNEL_SET_USER_AGENT } from '../../../../../shared/ipc-commands'; /** * This component contains the implementation of HTML5 based video player @@ -23,6 +25,11 @@ import { getExtensionFromUrl } from '../../../../../shared/playlist.utils'; export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy { /** Channel to play */ @Input() channel: Channel; + dataService: DataService; // Declare the dataService property + + constructor(dataService: DataService) { + this.dataService = dataService; // Inject the DataService + } /** Video player DOM element */ @ViewChild('videoPlayer', { static: true }) @@ -63,6 +70,10 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy { this.hls = new Hls(); this.hls.attachMedia(this.videoPlayer.nativeElement); this.hls.loadSource(url); + this.dataService.sendIpcEvent(CHANNEL_SET_USER_AGENT, { + userAgent: channel.http['user-agent'], + referer: channel.http.referrer, + }); this.handlePlayOperation(); } else { console.error('something wrong with hls.js init...'); @@ -71,6 +82,10 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy { url, 'video/mp4' ); + this.dataService.sendIpcEvent(CHANNEL_SET_USER_AGENT, { + userAgent: channel.http['user-agent'], + referer: channel.http.referrer, + }); this.videoPlayer.nativeElement.play(); } }