(socket: WebSocketRaw)
| 344 | // Provide a wrapper to the ws client so we can send messages in JSON format |
| 345 | // To be consistent with server.ws.send |
| 346 | function getSocketClient(socket: WebSocketRaw) { |
| 347 | if (!clientsMap.has(socket)) { |
| 348 | clientsMap.set(socket, { |
| 349 | send: (...args: any[]) => { |
| 350 | let payload: HotPayload |
| 351 | if (typeof args[0] === 'string') { |
| 352 | payload = { |
| 353 | type: 'custom', |
| 354 | event: args[0], |
| 355 | data: args[1], |
| 356 | } |
| 357 | } else { |
| 358 | payload = args[0] |
| 359 | } |
| 360 | socket.send(JSON.stringify(payload)) |
| 361 | }, |
| 362 | socket, |
| 363 | }) |
| 364 | } |
| 365 | return clientsMap.get(socket)! |
| 366 | } |
| 367 | |
| 368 | // On page reloads, if a file fails to compile and returns 500, the server |
| 369 | // sends the error payload before the client connection is established. |
no test coverage detected