Merge pull request #332 from sapireli/electron

feat: support for setting channel HTTP referrer headers for HTML 5 Player & JS Player
This commit is contained in:
4gray authored and GitHub committed 2023-12-06 20:20:57 +01:00
commit acb89804c6
2 files changed
+18 -5

No files matched your search

+3 -5
View File
@@ -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) => {
@@ -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();
}
}