From 5e90083f35e36623c9e03860e16b651f15ea7717 Mon Sep 17 00:00:00 2001 From: sapireli <114778791+sapireli@users.noreply.github.com> Date: Sat, 2 Dec 2023 04:57:21 -0500 Subject: [PATCH] feat: support for setting channel HTTP referrer headers for both HTML5 and JS players This commit introduces support for setting the HTTP referrer headers per channel. The referer is the http-referrer set for each channel in the m3u8 playlist. This feature works for both the HTML5 and JS players. Updates were made to the player-dialog component to handle the referrer headers for the JS player. Corresponding changes to the html-video-player component for the HTML5 player. --- electron/api.ts | 8 +++----- .../html-video-player.component.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) 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(); } }