diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-09-19 23:40:03 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-09-19 23:40:03 +0100 |
commit | 92e8596b78982885803994b50c6b35f73f7a403e (patch) | |
tree | 13428243987317da540495215ed4d9e3938fb5cb /compat/lustre_websocket/src/ffi.mjs | |
parent | 985a9b0aa469cbe94fb95c433c97e2b321014341 (diff) | |
download | lustre-92e8596b78982885803994b50c6b35f73f7a403e.tar.gz lustre-92e8596b78982885803994b50c6b35f73f7a403e.zip |
:recycle: So long monorepo.
Diffstat (limited to 'compat/lustre_websocket/src/ffi.mjs')
-rw-r--r-- | compat/lustre_websocket/src/ffi.mjs | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/compat/lustre_websocket/src/ffi.mjs b/compat/lustre_websocket/src/ffi.mjs deleted file mode 100644 index 56f11fd..0000000 --- a/compat/lustre_websocket/src/ffi.mjs +++ /dev/null @@ -1,39 +0,0 @@ -let ws_handler_registry = {} - -export const init_websocket = path => { - let ws - if (typeof WebSocket === "function") { - // we're in the browser - let url = new URL(document.URL) - let protocol = url.protocol === "http:" ? "ws" : "wss" - let ws_url = protocol + "://" + url.host + url.pathname + path - ws = new WebSocket(ws_url) - } else { - // we're NOT in the browser, prolly running tests - ws = {} - } - ws_handler_registry[ws.url] = { ws: ws } - - ws.onopen = evt => { - ws_handler_registry[ws.url]?.on_open?.() - } - ws.onclose = evt => { - ws_handler_registry[ws.url]?.on_close?.(evt.code) - delete ws_handler_registry[ws.url] - } - ws.onmessage = event => ws_handler_registry[ws.url]?.on_message?.(event.data) - ws.onerror = error => console.log("ws", ws.url, "error", error, "no handler, since I have no clue what errors we might be talking about") - return ws -} - -export const register_websocket_handler = (ws, on_open, on_message, on_close) => { - const reg_entry = ws_handler_registry[ws.url] - reg_entry.on_open = on_open - reg_entry.on_message = on_message - reg_entry.on_close = on_close - console.log("ws reg", ws_handler_registry) -} - -export const send_over_websocket = (ws, msg) => { - ws.send(msg) -} |