2020-12-03 00:34:50 +01:00
|
|
|
import { createApp } from 'vue';
|
|
|
|
import { createStore } from 'vuex';
|
2021-10-22 00:30:36 +02:00
|
|
|
import mdiVue from 'mdi-vue/v3';
|
|
|
|
import * as mdijs from '@mdi/js';
|
2020-12-03 00:34:50 +01:00
|
|
|
|
2020-12-03 01:35:22 +01:00
|
|
|
if (process.env.CHANNEL !== 'stable'){
|
|
|
|
console.info("Loading: UI");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-03 00:34:50 +01:00
|
|
|
class UI {
|
|
|
|
constructor(
|
|
|
|
interfaceId,
|
|
|
|
storeConfig,
|
|
|
|
uiConfig, // {component, parentElement?}
|
|
|
|
commsConfig,
|
2021-11-13 00:51:59 +01:00
|
|
|
ultrawidify, // or, at least, videoData instance + event bus
|
2020-12-03 00:34:50 +01:00
|
|
|
) {
|
|
|
|
this.interfaceId = interfaceId;
|
|
|
|
this.commsConfig = commsConfig;
|
2021-02-17 00:20:30 +01:00
|
|
|
this.storeConfig = storeConfig;
|
2020-12-03 01:35:22 +01:00
|
|
|
this.uiConfig = uiConfig;
|
2021-11-13 00:51:59 +01:00
|
|
|
this.ultrawidify = ultrawidify;
|
2020-12-03 01:35:22 +01:00
|
|
|
|
|
|
|
this.init();
|
2020-12-03 00:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
// initialize vuejs, but only once (check handled in initVue())
|
|
|
|
// we need to initialize this _after_ initializing comms.
|
2020-12-04 02:02:25 +01:00
|
|
|
|
2020-12-03 00:34:50 +01:00
|
|
|
this.initVue();
|
|
|
|
}
|
|
|
|
|
|
|
|
async initVue() {
|
2020-12-04 02:02:25 +01:00
|
|
|
if (this.storeConfig) {
|
|
|
|
this.vuexStore = createStore(this.storeConfig);
|
|
|
|
}
|
|
|
|
|
2020-12-03 01:35:22 +01:00
|
|
|
this.initUi();
|
2020-12-03 00:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async initUi() {
|
2021-10-26 20:11:03 +02:00
|
|
|
if (this.app) {
|
|
|
|
this.app.unmount();
|
|
|
|
}
|
|
|
|
|
2020-12-03 00:34:50 +01:00
|
|
|
const random = Math.round(Math.random() * 69420);
|
2020-12-05 03:30:43 +01:00
|
|
|
const uwid = `uw-${this.interfaceId}-root-${random}`
|
2020-12-03 00:34:50 +01:00
|
|
|
|
|
|
|
const rootDiv = document.createElement('div');
|
|
|
|
|
2020-12-15 00:26:19 +01:00
|
|
|
if (this.uiConfig.additionalStyle) {
|
|
|
|
rootDiv.setAttribute('style', this.uiConfig.additionalStyle);
|
|
|
|
}
|
2020-12-05 03:30:43 +01:00
|
|
|
rootDiv.setAttribute('id', uwid);
|
2020-12-12 00:38:51 +01:00
|
|
|
rootDiv.classList.add('uw-ultrawidify-container-root');
|
2020-12-04 02:02:25 +01:00
|
|
|
|
|
|
|
if (this.uiConfig?.parentElement) {
|
2020-12-03 00:34:50 +01:00
|
|
|
this.uiConfig.parentElement.appendChild(rootDiv);
|
|
|
|
} else {
|
|
|
|
document.body.appendChild(rootDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.element = rootDiv;
|
|
|
|
|
2021-10-26 23:13:11 +02:00
|
|
|
const app = createApp(this.uiConfig.component)
|
|
|
|
.use(mdiVue, {icons: mdijs})
|
|
|
|
.use({ // hand eventBus to the component
|
|
|
|
install: (app, options) => {
|
|
|
|
app.mixin({
|
|
|
|
data() {
|
|
|
|
return {
|
2021-11-13 00:51:59 +01:00
|
|
|
ultrawidify: options.ultrawidify
|
2021-10-26 23:13:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-11-13 00:51:59 +01:00
|
|
|
}, {ultrawidify: this.ultrawidify});
|
2021-10-26 23:13:11 +02:00
|
|
|
|
2020-12-04 02:02:25 +01:00
|
|
|
if (this.vuexStore) {
|
|
|
|
app.use(this.vuexStore);
|
|
|
|
}
|
2021-10-26 23:13:11 +02:00
|
|
|
|
|
|
|
this.app = app;
|
2020-12-04 02:02:25 +01:00
|
|
|
app.mount(`#${uwid}`);
|
2020-12-03 00:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces ui config and re-inits the UI
|
2021-10-22 00:30:36 +02:00
|
|
|
* @param {*} newUiConfig
|
2020-12-03 00:34:50 +01:00
|
|
|
*/
|
|
|
|
replace(newUiConfig) {
|
|
|
|
this.element?.remove();
|
2021-10-26 20:11:03 +02:00
|
|
|
this.app.unmount();
|
|
|
|
this.app = undefined;
|
2020-12-03 00:34:50 +01:00
|
|
|
this.uiConfig = newUiConfig;
|
|
|
|
this.initUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
2020-12-04 02:02:25 +01:00
|
|
|
// this.comms?.destroy();
|
2020-12-03 00:34:50 +01:00
|
|
|
this.element?.remove();
|
2021-10-26 20:11:03 +02:00
|
|
|
this.app.unmount();
|
|
|
|
this.app = undefined;
|
2020-12-03 00:34:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 01:35:22 +01:00
|
|
|
if (process.env.CHANNEL !== 'stable'){
|
|
|
|
console.info("UI.js loaded");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-03 01:16:57 +01:00
|
|
|
export default UI;
|