|
| 1 | +import type { Peer } from 'crossws' |
1 | 2 | import type { DevframeAuthHandler } from '../node/auth/handler' |
2 | 3 | import type { StartedServer } from '../node/server' |
3 | 4 | import type { ConnectionMeta } from '../types/context' |
4 | 5 | import type { DevframeDefinition, DevframeSetupInfo, DevframeWsOptions, McpRouteOptions } from '../types/devframe' |
| 6 | +import type { DevframeNodeRpcSession, DevframeNodeRpcSessionMeta } from '../types/rpc' |
5 | 7 | import process from 'node:process' |
6 | 8 | import { open } from 'devframe/utils/open' |
7 | 9 | import { mountStaticHandler } from 'devframe/utils/serve-static' |
@@ -87,6 +89,17 @@ export interface CreateDevServerOptions { |
87 | 89 | * {@link McpRouteOptions}. |
88 | 90 | */ |
89 | 91 | mcp?: boolean | McpRouteOptions |
| 92 | + /** |
| 93 | + * Called once per new WS connection, right after its session is created. |
| 94 | + * Forwarded verbatim to the underlying `startHttpAndWs`. |
| 95 | + */ |
| 96 | + onPeerConnect?: (peer: Peer, session: DevframeNodeRpcSession) => void |
| 97 | + /** |
| 98 | + * Called once per closed WS connection, right after its session's |
| 99 | + * disconnect bookkeeping runs. Forwarded verbatim to the underlying |
| 100 | + * `startHttpAndWs`. |
| 101 | + */ |
| 102 | + onPeerDisconnect?: (peer: Peer, meta: DevframeNodeRpcSessionMeta) => void |
90 | 103 | /** |
91 | 104 | * Called once the WS server is bound. Devframe stays headless |
92 | 105 | * otherwise — wire this if you want a startup banner. |
@@ -255,6 +268,8 @@ export async function createDevServer( |
255 | 268 | path: bindPath, |
256 | 269 | wsPort, |
257 | 270 | auth: resolvedAuth, |
| 271 | + onPeerConnect: options.onPeerConnect, |
| 272 | + onPeerDisconnect: options.onPeerDisconnect, |
258 | 273 | onReady: async (info) => { |
259 | 274 | // Print the auth banner before the caller's own onReady / browser open |
260 | 275 | // so the code is on screen by the time a browser lands on the page. |
|
0 commit comments