Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/packages/server/test/helpers.ts
2019-02-05 11:15:44 -06:00

29 lines
682 B
TypeScript

import { Emitter } from "@coder/events";
import { Client } from "../src/browser/client";
import { Server } from "../src/node/server";
export const createClient = (): Client => {
const s2c = new Emitter<Uint8Array | Buffer>();
const c2s = new Emitter<Uint8Array | Buffer>();
new Server({
close: () => undefined,
onClose: () => undefined,
onMessage: (cb) => {
c2s.event((d) => cb(d));
},
send: (data) => setTimeout(() => s2c.emit(data), 0),
});
const client = new Client({
close: () => undefined,
onClose: () => undefined,
onMessage: (cb) => {
s2c.event((d) => cb(d));
},
send: (data) => setTimeout(() => c2s.emit(data), 0),
});
return client;
};