feat(playback): resolve shared controls from settings

This commit is contained in:
4gray committed 2026-07-17 08:09:44 +02:00
1 parent 98c1a55ff7
commit 40d5238071
2 files changed
+57 -3

No files matched your search

@@ -1,5 +1,5 @@
import { ClipboardModule } from '@angular/cdk/clipboard';
import { Component, input, output } from '@angular/core';
import { Component, input, output, signal } from '@angular/core';
import {
ComponentFixture,
DeferBlockBehavior,
@@ -16,8 +16,9 @@ import {
type ResolvedPortalPlayback,
VideoPlayer,
} from '@iptvnator/shared/interfaces';
import { RuntimeCapabilitiesService } from '@iptvnator/services';
import { RuntimeCapabilitiesService, SettingsStore } from '@iptvnator/services';
import type { WebPlayerViewComponent as WebPlayerViewComponentInstance } from './web-player-view.component';
import { WEB_PLAYER_SHARED_CONTROLS } from '../player-controls';
import {
type PlaybackDiagnostic,
PlaybackDiagnosticCode,
@@ -89,6 +90,8 @@ class StubEmbeddedMpvPlayerComponent {
readonly nextEpisodeRequested = output<void>();
}
const webPlayerSharedControls = signal(false);
describe('WebPlayerViewComponent shared web controls metadata', () => {
let WebPlayerViewComponent: typeof import('./web-player-view.component').WebPlayerViewComponent;
let fixture: ComponentFixture<WebPlayerViewComponentInstance>;
@@ -100,6 +103,8 @@ describe('WebPlayerViewComponent shared web controls metadata', () => {
});
beforeEach(async () => {
webPlayerSharedControls.set(false);
await TestBed.configureTestingModule({
deferBlockBehavior: DeferBlockBehavior.Playthrough,
imports: [WebPlayerViewComponent, TranslateModule.forRoot()],
@@ -114,6 +119,10 @@ describe('WebPlayerViewComponent shared web controls metadata', () => {
provide: RuntimeCapabilitiesService,
useValue: { supportsManagedExternalPlayers: false },
},
{
provide: SettingsStore,
useValue: { webPlayerSharedControls },
},
],
})
.overrideComponent(WebPlayerViewComponent, {
@@ -146,6 +155,34 @@ describe('WebPlayerViewComponent shared web controls metadata', () => {
fixture.destroy();
});
it('snapshots the shared controls setting for each player host', () => {
webPlayerSharedControls.set(true);
fixture.detectChanges();
expect(
fixture.debugElement.injector.get(WEB_PLAYER_SHARED_CONTROLS)
).toBe(true);
webPlayerSharedControls.set(false);
expect(
fixture.debugElement.injector.get(WEB_PLAYER_SHARED_CONTROLS)
).toBe(true);
fixture.destroy();
fixture = TestBed.createComponent(WebPlayerViewComponent);
component = fixture.componentInstance;
fixture.componentRef.setInput(
'streamUrl',
'https://example.com/next.ts'
);
fixture.detectChanges();
expect(
fixture.debugElement.injector.get(WEB_PLAYER_SHARED_CONTROLS)
).toBe(false);
});
it.each([
['an explicit VOD value', { isLive: false }, false],
[
@@ -25,10 +25,14 @@ import {
VideoPlayer,
} from '@iptvnator/shared/interfaces';
import type { ExternalPlayerName } from '@iptvnator/shared/interfaces';
import { RuntimeCapabilitiesService } from '@iptvnator/services';
import { RuntimeCapabilitiesService, SettingsStore } from '@iptvnator/services';
import { ArtPlayerComponent } from '../art-player/art-player.component';
import { EmbeddedMpvPlayerComponent } from '../embedded-mpv-player/embedded-mpv-player.component';
import { HtmlVideoPlayerComponent } from '../html-video-player/html-video-player.component';
import {
WEB_PLAYER_SHARED_CONTROLS,
WEB_PLAYER_SHARED_CONTROLS_ENABLED,
} from '../player-controls';
import {
type PlaybackDiagnostic,
PlaybackDiagnosticCode,
@@ -44,6 +48,13 @@ type PlaybackDiagnosticDetail = {
readonly value: string;
};
function resolveWebPlayerSharedControls(): boolean {
const storedValue = inject(SettingsStore).webPlayerSharedControls?.();
return typeof storedValue === 'boolean'
? storedValue
: WEB_PLAYER_SHARED_CONTROLS_ENABLED;
}
@Component({
selector: 'app-web-player-view',
templateUrl: './web-player-view.component.html',
@@ -62,6 +73,12 @@ type PlaybackDiagnosticDetail = {
TranslatePipe,
VjsPlayerComponent,
],
providers: [
{
provide: WEB_PLAYER_SHARED_CONTROLS,
useFactory: resolveWebPlayerSharedControls,
},
],
encapsulation: ViewEncapsulation.None,
})
export class WebPlayerViewComponent {