You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
// index.js
|
|
// Copyright (C) 2021 Digital Telepresence, LLC
|
|
// License: Apache-2.0
|
|
|
|
'use strict';
|
|
|
|
const DTP_COMPONENT_NAME = 'Site';
|
|
|
|
const dtp = window. dtp = window.dtp || { };
|
|
|
|
import DtpSiteApp from './site-app.js';
|
|
import DtpWebLog from 'dtp/dtp-log.js';
|
|
import UIkit from 'uikit';
|
|
|
|
window.addEventListener('load', async ( ) => {
|
|
// application console log
|
|
dtp.log = new DtpWebLog(DTP_COMPONENT_NAME);
|
|
|
|
// service worker
|
|
if ('serviceWorker' in navigator) {
|
|
try {
|
|
dtp.registration = await navigator.serviceWorker.register('/dist/js/service_worker.min.js');
|
|
dtp.log.info('load', 'service worker startup complete', { scope: dtp.registration.scope });
|
|
} catch (error) {
|
|
console.log('service worker startup failed', { error });
|
|
UIkit.modal.alert(`Service worker startup failed: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
dtp.app = new DtpSiteApp(dtp.user);
|
|
if (dtp.user && dtp.user._id) {
|
|
await dtp.app.connect();
|
|
}
|
|
|
|
dtp.log.debug('load', 'dispatching load event');
|
|
window.dispatchEvent(new Event('dtp-load'));
|
|
});
|
|
|
|
document.addEventListener('socketConnected', async ( ) => {
|
|
if (dtp.channel) {
|
|
dtp.app.socket.joinChannel(dtp.channel._id);
|
|
if (dtp.user && (dtp.user._id === dtp.channel.owner._id)) {
|
|
dtp.app.socket.joinChannel(`broadcast:${dtp.channel._id}`);
|
|
}
|
|
}
|
|
});
|