ui: fix websocket cookie (#670)

pull/673/head
panda 12 months ago committed by GitHub
parent 6cce9784d4
commit fe53323d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -46,12 +46,7 @@ const onmessage = (msg) => {
return true; return true;
}; };
const url = new URL(`${UiContext.ws_prefix}home/messages-conn`, window.location.href); const initWorkerMode = (endpoint) => {
// TODO handle a better way for cookie
if (url.host !== window.location.host) url.searchParams.append('sid', document.cookie.split('sid=')[1].split(';')[0]);
const endpoint = url.toString().replace('http', 'ws');
const initWorkerMode = () => {
console.log('Messages: using SharedWorker'); console.log('Messages: using SharedWorker');
const worker = new SharedWorker('/messages-shared-worker.js', { name: 'HydroMessagesWorker' }); const worker = new SharedWorker('/messages-shared-worker.js', { name: 'HydroMessagesWorker' });
worker.port.start(); worker.port.start();
@ -81,9 +76,13 @@ const messagePage = new AutoloadPage('messagePage', (pagename) => {
action: () => window.open('/home/messages', '_blank'), action: () => window.open('/home/messages', '_blank'),
}).show(); }).show();
} }
const url = new URL(`${UiContext.ws_prefix}home/messages-conn`, window.location.href);
// TODO handle a better way for cookie
if (url.host !== window.location.host) url.searchParams.append('sid', document.cookie.split('sid=')[1].split(';')[0]);
const endpoint = url.toString().replace('http', 'ws');
if (window.SharedWorker) { if (window.SharedWorker) {
try { try {
initWorkerMode(); initWorkerMode(endpoint);
return; return;
} catch (e) { } catch (e) {
console.error('SharedWorker init fail: ', e.message); console.error('SharedWorker init fail: ', e.message);

Loading…
Cancel
Save