Live video on the AT Protocol
1import { TestPdsServer, type PdsServerOptions } from "./pds.js";
2import { TestPlcServer, type PlcServerOptions } from "./plc.js";
3import { mockNetworkUtilities } from "./utils.js";
4
5export type NetworkConfig = {
6 pds: Partial<PdsServerOptions>;
7 plc: Partial<PlcServerOptions>;
8};
9
10export class TestNetwork {
11 constructor(
12 public readonly plc: TestPlcServer,
13 public readonly pds: TestPdsServer,
14 ) {}
15
16 static async create(cfg: Partial<NetworkConfig>): Promise<TestNetwork> {
17 const plc = await TestPlcServer.create(cfg.plc ?? {});
18 const pds = await TestPdsServer.create({ didPlcUrl: plc.url, ...cfg.pds });
19
20 mockNetworkUtilities(pds);
21
22 return new TestNetwork(plc, pds);
23 }
24
25 async processAll() {
26 await this.pds.processAll();
27 }
28
29 async close() {
30 await Promise.all([this.plc.close(), this.pds.close()]);
31 }
32}