fp/services/bright/assets/vendor/player.js.map

1 line
56 KiB
Plaintext
Raw Normal View History

2025-01-11 03:10:04 +00:00
{"version":3,"sources":["../../../node_modules/tseep/lib/types.js","../../../node_modules/tseep/src/task-collection/utils.ts","../../../node_modules/tseep/src/task-collection/bake-collection.ts","../../../node_modules/tseep/src/task-collection/task-collection.ts","../../../node_modules/tseep/src/task-collection/index.ts","../../../node_modules/tseep/src/utils.ts","../../../node_modules/tseep/src/ee.ts","../../../node_modules/tseep/src/index.ts","../src/hls-player.ts","../../shared/src/assert.ts","../src/event-manager.ts","../src/helpers.ts","../src/types.ts","../src/state.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n//# sourceMappingURL=types.js.map",null,null,null,null,null,null,null,"import Hls from \"hls.js\";\nimport { assert } from \"shared/assert\";\nimport { EventEmitter } from \"tseep\";\nimport { EventManager } from \"./event-manager\";\nimport { getLangCode } from \"./helpers\";\nimport { getState, State } from \"./state\";\nimport { Events } from \"./types\";\nimport type {\n AudioTrack,\n HlsPlayerEventMap,\n Quality,\n SubtitleTrack,\n} from \"./types\";\nimport type { Level } from \"hls.js\";\n\nexport class HlsPlayer {\n private media_: HTMLMediaElement;\n\n private eventManager_ = new EventManager();\n\n private hls_: Hls | null = null;\n\n private state_: State | null = null;\n\n private emitter_ = new EventEmitter<HlsPlayerEventMap>();\n\n constructor(public container: HTMLDivElement) {\n this.media_ = this.createMedia_();\n }\n\n private createMedia_() {\n const media = document.createElement(\"video\");\n this.container.appendChild(media);\n\n media.style.position = \"absolute\";\n media.style.inset = \"0\";\n media.style.width = \"100%\";\n media.style.height = \"100%\";\n\n return media;\n }\n\n load(url: string) {\n this.unload();\n\n this.bindMediaListeners_();\n const hls = this.createHls_();\n\n this.state_ = new State({\n onEvent: (event: Events) => this.emit_(event),\n getTiming: () => ({\n primary: hls.interstitialsManager?.primary ?? hls.media,\n asset: hls.interstitialsManager?.playerQueue.find(\n (player) =>\n player.assetItem === hls.interstitialsManager?.playingAsset,\n ),\n }),\n });\n\n hls.attachMedia(this.media_);\n hls.loadSource(url);\n\n this.hls_ = hls;\n }\n\n unload() {\n this.eventManager_.removeAll();\n this.state_ = null;\n\n if (this.hls_) {\n this.hls_.destroy();\n this.hls_ = null;\n }\n\n this.emit_(Events.RESET);\n }\n\n destroy() {\n this.emitter_.removeAllListeners();\n this.unload();\n }\n\n on = this.emitter_.on.bind(this.emitter_);\n off = this.emitter_.off.bind(this.emitter_);\n once = this.emitter_.once.bind(this.emitter_);\n\n playOrPause() {\n if (!this.state_) {\n return;\n }\n const shouldPause =\n this.state_.playhead === \"play\" || this.state_.playhead === \"playing\";\n if (shouldPause) {\n this.media_.pause();\n } else {\n this.media_.play();\n }\n }\n\n seekTo(time: number) {\n assert(this.hls_);\n\n if (this.state_?.interstitial) {\n return false;\n }\n\n if (this.hls_.interstitialsManager) {\n this.hls_.interstitialsManager.primary.seekTo(time);\n } else {\n this.media_.currentTime = time;\n }\n\n return true;\n }\n\n setQuality(height: number | null) {\n assert(this.hls_);\n\n if (height === null) {\n this.hls_.nextLevel = -1;\n } else {\n const loadLevel = this.hls_.levels[this.hls_.loadLevel];\n assert(loadLevel, \"No level found for loadLevel index\");\n\n const idx = this.hls_.levels.findIndex((level) => {\n return (\n level.height === height &&\n level.audioCodec?.substring(0, 4) ===\n loadLevel.audioCodec?.substring(0, 4)\n );\n });\n\n if (idx < 0) {\n throw new Error(\"Could not find matching level\");\n }\n\n this.hls_.nextLevel = idx;\n }\n\n t