11import type { BirpcGroup , BirpcOptions , ChannelOptions } from 'birpc'
22import type { IncomingMessage } from 'node:http'
3+ import type { ServerOptions as HttpsServerOptions } from 'node:https'
34import type { WebSocket } from 'ws'
45import type { RpcServerPreset } from '..'
6+ import { createServer as createHttpsServer } from 'node:https'
57import { parse , stringify } from 'structured-clone-es'
68import { WebSocketServer } from 'ws'
79import { defineRpcServerPreset } from '..'
@@ -17,6 +19,7 @@ export interface DevToolsNodeRpcSessionMeta {
1719export interface WebSocketRpcServerOptions {
1820 port : number
1921 host ?: string
22+ https ?: HttpsServerOptions | undefined
2023 onConnected ?: ( ws : WebSocket , req : IncomingMessage , meta : DevToolsNodeRpcSessionMeta ) => void
2124 onDisconnected ?: ( ws : WebSocket , meta : DevToolsNodeRpcSessionMeta ) => void
2225}
@@ -37,15 +40,20 @@ export const createWsRpcPreset: RpcServerPreset<
3740> = defineRpcServerPreset ( ( options : WebSocketRpcServerOptions ) => {
3841 const {
3942 port,
43+ https,
4044 host = 'localhost' ,
4145 onConnected = NOOP ,
4246 onDisconnected = NOOP ,
4347 } = options
4448
45- const wss = new WebSocketServer ( {
46- port,
47- host,
48- } )
49+ const httpsServer = https ? createHttpsServer ( https ) : undefined
50+
51+ const wss = https
52+ ? new WebSocketServer ( { server : httpsServer } )
53+ : new WebSocketServer ( {
54+ port,
55+ host,
56+ } )
4957
5058 return < ClientFunctions extends object , ServerFunctions extends object > (
5159 rpcGroup : BirpcGroup < ClientFunctions , ServerFunctions , false > ,
@@ -93,5 +101,7 @@ export const createWsRpcPreset: RpcServerPreset<
93101 } )
94102 onConnected ( ws , req , meta )
95103 } )
104+
105+ httpsServer ?. listen ( port , host )
96106 }
97107} )
0 commit comments