MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / startWebsocket

Function startWebsocket

lib/src/websockets.ts:5–20  ·  view source on GitHub ↗
(store: Store)

Source from the content-addressed store, hash-verified

3
4/** Opens a Websocket Connection at `/ws` for the current Drive */
5export function startWebsocket(store: Store): WebSocket {
6 const wsURL = new URL(store.getServerUrl());
7 // Default to a secure WSS connection, but allow WS for unsecured server connections
8 if (wsURL.protocol == 'http:') {
9 wsURL.protocol = 'ws';
10 } else {
11 wsURL.protocol = 'wss';
12 }
13 wsURL.pathname = '/ws';
14 const client = new WebSocket(wsURL.toString());
15 client.onopen = _e => handleOpen(store);
16 client.onmessage = (ev: MessageEvent) => handleMessage(ev, store);
17 client.onerror = handleError;
18 // client.onclose = handleClose;
19 return client;
20}
21
22function handleOpen(store: Store) {
23 // TODO: Add a way to subscribe to multiple resources in one request

Callers 1

setWebSocketMethod · 0.90

Calls 3

handleOpenFunction · 0.85
handleMessageFunction · 0.85
getServerUrlMethod · 0.80

Tested by

no test coverage detected