(store: Store)
| 3 | |
| 4 | /** Opens a Websocket Connection at `/ws` for the current Drive */ |
| 5 | export 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 | |
| 22 | function handleOpen(store: Store) { |
| 23 | // TODO: Add a way to subscribe to multiple resources in one request |
no test coverage detected