Skip to content

Commit

Permalink
feat(ws): expose on / off for server.ws (#5273)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Oct 13, 2021
1 parent b7e8a5c commit 6f696be
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/vite/src/node/server/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Socket } from 'net'
export const HMR_HEADER = 'vite-hmr'

export interface WebSocketServer {
on: WebSocket.Server['on']
off: WebSocket.Server['off']
send(payload: HMRPayload): void
close(): Promise<void>
}
Expand Down Expand Up @@ -92,6 +94,8 @@ export function createWebSocketServer(
let bufferedError: ErrorPayload | null = null

return {
on: wss.on.bind(wss),
off: wss.off.bind(wss),
send(payload: HMRPayload) {
if (payload.type === 'error' && !wss.clients.size) {
bufferedError = payload
Expand Down

0 comments on commit 6f696be

Please sign in to comment.