1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Use dynamic import for pdf.js

This commit is contained in:
Bill Thornton 2022-09-16 03:06:13 -04:00
parent 8a2eb0d0d8
commit 5c97fe861a

View file

@ -7,7 +7,6 @@ import { appRouter } from '../../components/appRouter';
import './style.scss'; import './style.scss';
import '../../elements/emby-button/paper-icon-button-light'; import '../../elements/emby-button/paper-icon-button-light';
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';
import { GlobalWorkerOptions, getDocument } from 'pdfjs-dist';
export class PdfPlayer { export class PdfPlayer {
constructor() { constructor() {
@ -200,14 +199,14 @@ export class PdfPlayer {
const serverId = item.ServerId; const serverId = item.ServerId;
const apiClient = ServerConnections.getApiClient(serverId); const apiClient = ServerConnections.getApiClient(serverId);
return new Promise((resolve) => { return import('pdfjs-dist').then(({ GlobalWorkerOptions, getDocument }) => {
const downloadHref = apiClient.getItemDownloadUrl(item.Id); const downloadHref = apiClient.getItemDownloadUrl(item.Id);
this.bindEvents(); this.bindEvents();
GlobalWorkerOptions.workerSrc = appRouter.baseUrl() + '/libraries/pdf.worker.js'; GlobalWorkerOptions.workerSrc = appRouter.baseUrl() + '/libraries/pdf.worker.js';
const downloadTask = getDocument(downloadHref); const downloadTask = getDocument(downloadHref);
downloadTask.promise.then(book => { return downloadTask.promise.then(book => {
if (this.cancellationToken) return; if (this.cancellationToken) return;
this.book = book; this.book = book;
this.loaded = true; this.loaded = true;
@ -219,8 +218,6 @@ export class PdfPlayer {
} else { } else {
this.loadPage(1); this.loadPage(1);
} }
return resolve();
}); });
}); });
} }