Files
nanobot/webui/src/tests/stream-client.ts
T
chengyongru a4d2430140 refactor: remove redundant comments and docstrings (#6527)
* refactor: remove redundant comments and docstrings

* fix(signal): annotate async context manager as a generator
2026-10-30 13:07:03 +08:00

25 lines
649 B
TypeScript

import { NanobotClient } from "@/lib/nanobot-client";
import type { InboundEvent } from "@/lib/types";
export function createStreamClient() {
const socket = {
readyState: 1,
onopen: null as (() => void) | null,
onmessage: null as ((event: MessageEvent) => void) | null,
send() {},
close() {},
};
const client = new NanobotClient({
url: "ws://test", reconnect: false,
socketFactory: () => socket as unknown as WebSocket,
});
client.connect();
socket.onopen?.();
return {
client,
receive(event: InboundEvent) {
socket.onmessage?.({ data: JSON.stringify(event) } as MessageEvent);
},
};
}