Load hotkey-js only once and fix destroy.

This commit is contained in:
FireMasterK 2022-01-23 19:08:33 +00:00
parent de8fb4fab5
commit 1d6a6daa06
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD

View File

@ -9,6 +9,7 @@ import("shaka-player/dist/controls.css");
const shaka = import("shaka-player/dist/shaka-player.ui.js");
import muxjs from "mux.js";
window.muxjs = muxjs;
const hotkeys = import("hotkeys-js");
export default {
props: {
@ -62,14 +63,13 @@ export default {
},
mounted() {
if (!this.shaka) this.shakaPromise = shaka.then(shaka => shaka.default).then(shaka => (this.shaka = shaka));
if (!this.$hotkeys)
this.hotkeysPromise = hotkeys.then(mod => mod.default).then(hotkeys => (this.$hotkeys = hotkeys));
},
activated() {
import("hotkeys-js")
.then(mod => mod.default)
.then(hotkeys => {
this.hotkeys = hotkeys;
this.hotkeysPromise.then(() => {
var self = this;
hotkeys(
this.$hotkeys(
"f,m,j,k,l,c,space,up,down,left,right,0,1,2,3,4,5,6,7,8,9,shift+,,shift+.",
function (e, handler) {
const videoEl = self.$refs.videoEl;
@ -168,10 +168,10 @@ export default {
});
},
deactivated() {
this.destroy();
this.destroy(true);
},
unmounted() {
this.destroy();
this.destroy(true);
},
methods: {
async loadVideo() {
@ -514,7 +514,7 @@ export default {
this.$refs.videoEl.currentTime = time;
}
},
destroy() {
destroy(hotkeys) {
if (this.$ui) {
this.$ui.destroy();
this.$ui = undefined;
@ -524,7 +524,7 @@ export default {
this.$player.destroy();
this.$player = undefined;
}
if (this.hotkeys) this.hotkeys.unbind();
if (this.$hotkeys && hotkeys) this.$hotkeys.unbind();
if (this.$refs.container) this.$refs.container.querySelectorAll("div").forEach(node => node.remove());
},
},