MCPcopy
hub / github.com/vitejs/vite / getSocketClient

Function getSocketClient

packages/vite/src/node/server/ws.ts:346–366  ·  view source on GitHub ↗
(socket: WebSocketRaw)

Source from the content-addressed store, hash-verified

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.

Callers 1

emitCustomEventFunction · 0.85

Calls 4

hasMethod · 0.80
sendMethod · 0.65
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected