From 3152842a30c22344858f0ac3f1fa089f33dfe082 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Tue, 28 Nov 2023 01:39:11 +0900 Subject: [PATCH] fix: this binding Co-authored-by: Su-Yong --- src/plugins/captions-selector/index.ts | 6 +++--- src/utils/index.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/plugins/captions-selector/index.ts b/src/plugins/captions-selector/index.ts index 66ceb832..10fc77ea 100644 --- a/src/plugins/captions-selector/index.ts +++ b/src/plugins/captions-selector/index.ts @@ -102,7 +102,7 @@ export default createPlugin< api: null, config: null, setConfig: () => {}, - async videoChangeListener() { + async captionsButtonClickListener() { if (this.captionTrackList?.length) { const currentCaptionTrack = this.api!.getOption('captions', 'track'); let currentIndex = currentCaptionTrack @@ -130,8 +130,8 @@ export default createPlugin< setTimeout(() => this.api?.playVideo()); } }, - captionsButtonClickListener() { - if (this.config!.disableCaptions) { + videoChangeListener() { + if (this.config?.disableCaptions) { setTimeout(() => this.api!.unloadModule('captions'), 100); this.captionsSettingsButton.style.display = 'none'; return; diff --git a/src/utils/index.ts b/src/utils/index.ts index 44107b1b..c73ba316 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -41,6 +41,15 @@ export const startPlugin = (id: string, def: Plugin if (!lifecycle) return false; try { + const defContext = def[options.ctx]; + if (defContext && typeof defContext !== 'function') { + Object.entries(defContext) + .forEach(([key, value]) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access + if (typeof value === 'function') defContext[key as keyof typeof defContext] = value.bind(defContext); + }); + } + const start = performance.now(); lifecycle.bind(def[options.ctx])(options.context as Config & typeof options.context);