mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-14 13:16:16 -08:00
Takes Angular Material off the renderer's startup path: renderer.initialBytes 1,596,201 -> 1,344,067 bytes (-252,134, 15.8%) at the branch point; merged with master, where #1928 lands the form-field defaults per component, the branch measures 1,345,807 (-188,797, 12.3% against master's baseline). The bundler keeps each module in one chunk, so one eager import of any export carries the module's whole code; each item removes the last eager importer of one Material module. - EPG progress and update panels: eager host + `@defer (when visible)` view with an `@error` notice; the startup spinner is static markup copied from mat-spinner. - LazyMatDialog: the confirm dialog service, player service, parental lock prompt and shell actions resolve MatDialog on first use. - The theme emits tokens for the 21 imported components only, through a `$material-components` list and meta.apply; tools/nx/check-material-theme-scope.mjs (CI) keeps it in step with the imports in both directions. - No provideAnimations(): Material 22 animates with CSS and reads prefers-reduced-motion itself; apps/electron-backend-e2e/src/material-motion.e2e.ts proves dialogs, selects, menus, snack-bars and tooltips animate in and out and stop under reduced motion. Its renderer had deferred every DOM removal to the end of the tick, so the catalog list now tracks the grid offset from scroll events and the player settings panel decides "focus was inside" in a microtask, both with specs that detach the view first. - The snack-bar stays, and with it button, the icon-button chunk and the CDK overlay (about 190 KB): root services inject it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
134 lines
4.3 KiB
TypeScript
134 lines
4.3 KiB
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { DataService } from '@iptvnator/services';
|
|
import {
|
|
ExternalPlayerSession,
|
|
OPEN_MPV_PLAYER,
|
|
OPEN_VLC_PLAYER,
|
|
PlayerContentInfo,
|
|
ResolvedPortalPlayback,
|
|
VideoPlayer,
|
|
} from '@iptvnator/shared/interfaces';
|
|
import type { ExternalPlayerName } from '@iptvnator/shared/interfaces';
|
|
import { LazyMatDialog } from '@iptvnator/ui/components/lazy-dialog';
|
|
import { SettingsStore } from './settings-store.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class PlayerService {
|
|
private lazyDialog = inject(LazyMatDialog);
|
|
private dataService = inject(DataService);
|
|
private settingsStore = inject(SettingsStore);
|
|
|
|
isEmbeddedPlayer(
|
|
player = this.settingsStore.player() ?? VideoPlayer.VideoJs
|
|
): boolean {
|
|
return (
|
|
player === VideoPlayer.VideoJs ||
|
|
player === VideoPlayer.Html5Player ||
|
|
player === VideoPlayer.ArtPlayer ||
|
|
player === VideoPlayer.EmbeddedMpv
|
|
);
|
|
}
|
|
|
|
openPlayer(
|
|
streamUrl: string,
|
|
title: string,
|
|
thumbnail?: string,
|
|
hideExternalInfoDialog = true,
|
|
isLiveContent = false,
|
|
userAgent?: string,
|
|
referer?: string,
|
|
origin?: string,
|
|
contentInfo?: PlayerContentInfo,
|
|
startTime?: number,
|
|
headers?: Record<string, string>
|
|
): Promise<ExternalPlayerSession | void> {
|
|
return this.openResolvedPlayback(
|
|
{
|
|
streamUrl,
|
|
title,
|
|
thumbnail,
|
|
isLive: isLiveContent,
|
|
startTime,
|
|
contentInfo,
|
|
headers,
|
|
userAgent,
|
|
referer,
|
|
origin,
|
|
},
|
|
hideExternalInfoDialog
|
|
);
|
|
}
|
|
|
|
async openResolvedPlayback(
|
|
playback: ResolvedPortalPlayback,
|
|
hideExternalInfoDialog = true
|
|
): Promise<ExternalPlayerSession | void> {
|
|
const player = this.settingsStore.player() ?? VideoPlayer.VideoJs;
|
|
|
|
if (player === VideoPlayer.MPV) {
|
|
if (!hideExternalInfoDialog) {
|
|
this.showExternalPlayerInfoDialog();
|
|
}
|
|
return await this.openExternalPlayback(playback, 'mpv');
|
|
} else if (player === VideoPlayer.VLC) {
|
|
if (!hideExternalInfoDialog) {
|
|
this.showExternalPlayerInfoDialog();
|
|
}
|
|
return await this.openExternalPlayback(playback, 'vlc');
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* Loaded on demand: the dialog's Material checkbox brings @angular/forms,
|
|
* and this service is created with the app, so a static import would put
|
|
* both, and Material's dialog, on the initial path. Playback does not
|
|
* wait for the dialog.
|
|
*/
|
|
private showExternalPlayerInfoDialog(): void {
|
|
Promise.all([
|
|
this.lazyDialog.resolve(),
|
|
this.loadExternalPlayerInfoDialog(),
|
|
])
|
|
.then(([dialog, { ExternalPlayerInfoDialogComponent }]) =>
|
|
dialog.open(ExternalPlayerInfoDialogComponent)
|
|
)
|
|
.catch((error: unknown) => {
|
|
// Informational only: playback is already starting.
|
|
console.error(
|
|
'Could not load the external player info dialog:',
|
|
error
|
|
);
|
|
});
|
|
}
|
|
|
|
/** The dynamic import; a field so specs can substitute it. */
|
|
loadExternalPlayerInfoDialog = () =>
|
|
import('./external-player-info-dialog.lazy');
|
|
|
|
async openExternalPlayback(
|
|
playback: ResolvedPortalPlayback,
|
|
player: ExternalPlayerName
|
|
): Promise<ExternalPlayerSession | void> {
|
|
const ipcEvent = player === 'mpv' ? OPEN_MPV_PLAYER : OPEN_VLC_PLAYER;
|
|
|
|
return await this.dataService.sendIpcEvent<ExternalPlayerSession>(
|
|
ipcEvent,
|
|
{
|
|
url: playback.streamUrl,
|
|
title: playback.title,
|
|
thumbnail: playback.thumbnail,
|
|
'user-agent': playback.userAgent,
|
|
referer: playback.referer,
|
|
origin: playback.origin,
|
|
headers: playback.headers,
|
|
contentInfo: playback.contentInfo,
|
|
startTime: playback.startTime,
|
|
}
|
|
);
|
|
}
|
|
}
|