diff --git a/package-lock.json b/package-lock.json index 964d7ed7c0..5e7d33af06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "dompurify": "3.0.1", "epubjs": "0.4.2", "escape-html": "1.0.3", + "event-target-polyfill": "0.0.3", "fast-text-encoding": "1.0.6", "flv.js": "1.6.2", "headroom.js": "0.12.0", diff --git a/package.json b/package.json index 4a6817c17c..a795264e58 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "dompurify": "3.0.1", "epubjs": "0.4.2", "escape-html": "1.0.3", + "event-target-polyfill": "0.0.3", "fast-text-encoding": "1.0.6", "flv.js": "1.6.2", "headroom.js": "0.12.0", diff --git a/src/plugins/htmlVideoPlayer/plugin.js b/src/plugins/htmlVideoPlayer/plugin.js index a2e5535df6..a9457783f4 100644 --- a/src/plugins/htmlVideoPlayer/plugin.js +++ b/src/plugins/htmlVideoPlayer/plugin.js @@ -1270,10 +1270,11 @@ function tryRemoveElement(elem) { fonts: avaliableFonts, fallbackFont: 'liberation sans', availableFonts: {'liberation sans': `${appRouter.baseUrl()}/libraries/default.woff2`}, + // Disabled eslint compat, but is safe as corejs3 polyfills URL // eslint-disable-next-line compat/compat - workerUrl: `${appRouter.baseUrl()}/${new URL('jassub/dist/jassub-worker.js', import.meta.url)}`, + workerUrl: `${appRouter.baseUrl()}${new URL('jassub/dist/jassub-worker.js', import.meta.url).pathname}`, // eslint-disable-next-line compat/compat - legacyWorkerUrl: `${appRouter.baseUrl()}/${new URL('jassub/dist/jassub-worker-legacy.js', import.meta.url)}`, + legacyWorkerUrl: `${appRouter.baseUrl()}${new URL('jassub/dist/jassub-worker-legacy.js', import.meta.url).pathname}`, timeOffset: (this._currentPlayOptions.transcodingOffsetTicks || 0) / 10000000, // new jassub options; override all, even defaults blendMode: 'js', @@ -1290,37 +1291,39 @@ function tryRemoveElement(elem) { prescaleHeightLimit: 1080, maxRenderHeight: 2160 }; - import('jassub').then(({ default: JASSUB }) => { - Promise.all([ - apiClient.getNamedConfiguration('encoding'), - // Worker in Tizen 5 doesn't resolve relative path with async request - resolveUrl(options.workerUrl), - resolveUrl(options.legacyWorkerUrl) - ]).then(([config, workerUrl, legacyWorkerUrl]) => { - options.workerUrl = workerUrl; - options.legacyWorkerUrl = legacyWorkerUrl; + import('event-target-polyfill').then(() => { + import('jassub').then(({ default: JASSUB }) => { + Promise.all([ + apiClient.getNamedConfiguration('encoding'), + // Worker in Tizen 5 doesn't resolve relative path with async request + resolveUrl(options.workerUrl), + resolveUrl(options.legacyWorkerUrl) + ]).then(([config, workerUrl, legacyWorkerUrl]) => { + options.workerUrl = workerUrl; + options.legacyWorkerUrl = legacyWorkerUrl; - const cleanup = () => { - this.#currentJASSUB.destroy(); - this.#currentJASSUB = null; - onErrorInternal(this, 'mediadecodeerror'); - }; + const cleanup = () => { + this.#currentJASSUB.destroy(); + this.#currentJASSUB = null; + onErrorInternal(this, 'mediadecodeerror'); + }; - if (config.EnableFallbackFont) { - apiClient.getJSON(fallbackFontList).then((fontFiles = []) => { - fontFiles.forEach(font => { - const fontUrl = apiClient.getUrl(`/FallbackFont/Fonts/${font.Name}`, { - api_key: apiClient.accessToken() + if (config.EnableFallbackFont) { + apiClient.getJSON(fallbackFontList).then((fontFiles = []) => { + fontFiles.forEach(font => { + const fontUrl = apiClient.getUrl(`/FallbackFont/Fonts/${font.Name}`, { + api_key: apiClient.accessToken() + }); + avaliableFonts.push(fontUrl); }); - avaliableFonts.push(fontUrl); + this.#currentJASSUB = new JASSUB(options); + this.#currentJASSUB.addEventListener('error', cleanup, { once: true }); }); + } else { this.#currentJASSUB = new JASSUB(options); this.#currentJASSUB.addEventListener('error', cleanup, { once: true }); - }); - } else { - this.#currentJASSUB = new JASSUB(options); - this.#currentJASSUB.addEventListener('error', cleanup, { once: true }); - } + } + }); }); }); } diff --git a/webpack.common.js b/webpack.common.js index a66ddfe033..87f899040c 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -8,10 +8,13 @@ const { DefinePlugin } = require('webpack'); const Assets = [ 'native-promise-only/npo.js', 'libarchive.js/dist/worker-bundle.js', + 'pdfjs-dist/build/pdf.worker.js' +]; + +const JassubWasm = [ 'jassub/dist/jassub-worker.wasm', 'jassub/dist/jassub-worker-legacy.mem', - 'jassub/dist/default.woff2', - 'pdfjs-dist/build/pdf.worker.js' + 'jassub/dist/default.woff2' ]; const LibarchiveWasm = [ @@ -80,6 +83,14 @@ const config = { to: path.resolve(__dirname, './dist/libraries/wasm-gen') }; }) + }), + new CopyPlugin({ + patterns: JassubWasm.map(asset => { + return { + from: path.resolve(__dirname, `./node_modules/${asset}`), + to: path.resolve(__dirname, './dist') + }; + }) }) ], output: { @@ -144,6 +155,7 @@ const config = { { test: /\.(js|jsx)$/, include: [ + path.resolve(__dirname, 'node_modules/event-target-polyfill'), path.resolve(__dirname, 'node_modules/rvfc-polyfill'), path.resolve(__dirname, 'node_modules/@jellyfin/sdk'), path.resolve(__dirname, 'node_modules/@remix-run/router'),