mirror of
https://github.com/zoriya/v10.git
synced 2026-08-05 05:37:21 +00:00
fix: ssr issue with hls.js (#758)
This commit is contained in:
@@ -14,30 +14,30 @@ const defaultConfig = {
|
||||
};
|
||||
|
||||
export class HlsMediaDelegateBase implements MediaDelegate {
|
||||
#engine = new Hls(defaultConfig);
|
||||
#engine = Hls.isSupported() ? new Hls(defaultConfig) : null;
|
||||
|
||||
get engine(): Hls {
|
||||
get engine(): Hls | null {
|
||||
return this.#engine;
|
||||
}
|
||||
|
||||
attach(target: EventTarget): void {
|
||||
this.#engine.attachMedia(target as HTMLMediaElement);
|
||||
this.#engine?.attachMedia(target as HTMLMediaElement);
|
||||
}
|
||||
|
||||
detach(): void {
|
||||
this.#engine.detachMedia();
|
||||
this.#engine?.detachMedia();
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.#engine.destroy();
|
||||
this.#engine?.destroy();
|
||||
}
|
||||
|
||||
set src(src: string) {
|
||||
this.#engine.loadSource(src);
|
||||
this.#engine?.loadSource(src);
|
||||
}
|
||||
|
||||
get src(): string {
|
||||
return this.#engine.url ?? '';
|
||||
return this.#engine?.url ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { CuesParsedData, NonNativeTextTracksData } from 'hls.js';
|
||||
import Hls from 'hls.js';
|
||||
|
||||
interface HlsEngineHost {
|
||||
readonly engine: Hls;
|
||||
readonly engine: Hls | null;
|
||||
attach?(target: EventTarget): void;
|
||||
detach?(): void;
|
||||
}
|
||||
@@ -43,6 +43,8 @@ export function HlsMediaTextTracksMixin<Base extends Constructor<HlsEngineHost>>
|
||||
|
||||
const { signal } = this.#disconnect;
|
||||
const { engine } = this;
|
||||
if (!engine) return;
|
||||
|
||||
const media = this.#target!;
|
||||
|
||||
const onTracksFound = (_event: string, data: NonNativeTextTracksData) => {
|
||||
|
||||
Reference in New Issue
Block a user