use custom create-websocket

This commit is contained in:
Anbraten 2024-02-20 10:14:43 +01:00
parent b805631ea2
commit 7de741c838

View File

@ -21,6 +21,13 @@ document.body.addEventListener('htmx:responseError', (event) => {
showErrorToast(`Error ${event.detail.xhr.status} when calling ${event.detail.requestConfig.path}`);
});
// eslint-disable-next-line no-import-assign
htmx.createWebSocket = (url) => {
// TODO: reuse websocket from shared webworker
const sock = new WebSocket(url, []);
sock.binaryType = htmx.config.wsBinaryType;
return sock;
};
document.body.addEventListener('htmx:wsOpen', (evt) => {
const socket = evt.detail.socketWrapper;
socket.send(JSON.stringify({action: 'subscribe', data: {url: window.location.href}}));