Introduce shared websocket close code and reason constants
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
7e2bbaa403
commit
3cbec3a139
2 files changed
+17
-2
No files matched your search
@@ -14,6 +14,8 @@ import {
|
||||
type WsClientMessage,
|
||||
type WsResponseMessage,
|
||||
WS_EVENT_CHANNELS,
|
||||
WS_CLOSE_CODES,
|
||||
WS_CLOSE_REASONS,
|
||||
agentConfigSchema,
|
||||
agentSessionIdSchema,
|
||||
newTodoInputSchema,
|
||||
@@ -611,12 +613,15 @@ export async function startRuntimeApiServer(
|
||||
|
||||
wss.on("connection", (socket, request) => {
|
||||
if (!isAuthorizedConnection(request.url)) {
|
||||
socket.close(4001, "unauthorized");
|
||||
socket.close(WS_CLOSE_CODES.unauthorized, WS_CLOSE_REASONS.unauthorized);
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeClient && activeClient !== socket) {
|
||||
activeClient.close(4000, "replaced-by-new-client");
|
||||
activeClient.close(
|
||||
WS_CLOSE_CODES.replacedByNewClient,
|
||||
WS_CLOSE_REASONS.replacedByNewClient,
|
||||
);
|
||||
}
|
||||
|
||||
activeClient = socket;
|
||||
|
||||
@@ -6,6 +6,16 @@ export const WS_EVENT_CHANNELS = {
|
||||
agentExit: "agent:exit",
|
||||
} as const;
|
||||
|
||||
export const WS_CLOSE_CODES = {
|
||||
replacedByNewClient: 4000,
|
||||
unauthorized: 4001,
|
||||
} as const;
|
||||
|
||||
export const WS_CLOSE_REASONS = {
|
||||
replacedByNewClient: "replaced-by-new-client",
|
||||
unauthorized: "unauthorized",
|
||||
} as const;
|
||||
|
||||
const wsRequestSchema = z.object({
|
||||
type: z.literal("request"),
|
||||
id: z.string().min(1),
|
||||
|
||||
Reference in new issue
Block a user