Skip to content

Commit

Permalink
chore: fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 26, 2024
1 parent 0d4e078 commit e26acf4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/vite/src/node/server/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import colors from 'picocolors'
import type { WebSocket as WebSocketRaw } from 'ws'
import { WebSocketServer as WebSocketServerRaw_ } from 'ws'
import type { WebSocket as WebSocketTypes } from 'dep-types/ws'
import type { ErrorPayload, HotPayload } from 'types/hmrPayload'
import type { CustomPayload, ErrorPayload, HotPayload } from 'types/hmrPayload'
import type { InferCustomEventPayload } from 'types/customEvent'
import type { ResolvedConfig } from '..'
import type { HotChannelClient, ResolvedConfig } from '..'
import { isObject } from '../utils'
import { type NormalizedHotChannel, normalizeHotChannel } from './hmr'
import type { HttpServer } from '.'
Expand Down Expand Up @@ -66,7 +66,16 @@ export interface WebSocketServer extends NormalizedHotChannel {
clients: Set<WebSocketClient>
}

export interface WebSocketClient extends NormalizedHotChannel {
export interface WebSocketClient extends HotChannelClient {
/**
* Send event to the client
*/
send(payload: HotPayload): void
// support this signature for backward compatibility
/**
* Send custom event
*/
send(event: string, payload?: CustomPayload['data']): void
/**
* The raw WebSocket instance
* @advanced
Expand Down Expand Up @@ -269,7 +278,7 @@ export function createWebSocketServer(
socket.send(JSON.stringify(payload))
},
socket,
} as WebSocketClient)
})
}
return clientsMap.get(socket)!
}
Expand Down

0 comments on commit e26acf4

Please sign in to comment.