@norskvideo/ctl-test-harness 0.1.109 → 0.1.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/run.d.ts +25 -0
- package/demo/run.js +51 -6
- package/package.json +1 -1
package/demo/run.d.ts
CHANGED
|
@@ -61,6 +61,12 @@ export interface DemoDeps {
|
|
|
61
61
|
/** A host port free for TCP and UDP that is not in `taken` (free-port.ts).
|
|
62
62
|
* Optional so an existing custom-deps consumer keeps working; absent = probe. */
|
|
63
63
|
freePort?(taken: ReadonlySet<number>): Promise<number>;
|
|
64
|
+
/** Listen on this process' localhost:`port` and pipe each connection to
|
|
65
|
+
* `host:targetPort` (direct reach, see attachMoqRelayPages). Optional so an
|
|
66
|
+
* existing custom-deps consumer keeps working; absent = node:net. */
|
|
67
|
+
forwardLocalPort?(port: number, host: string, targetPort: number): Promise<{
|
|
68
|
+
close(): void;
|
|
69
|
+
}>;
|
|
64
70
|
/** Does a daemon answer /api/ready on this port? (A stale state file otherwise.) */
|
|
65
71
|
daemonAnswers(port: number): Promise<boolean>;
|
|
66
72
|
cli(storeDir: string, argv: string[]): Promise<CliResult>;
|
|
@@ -233,6 +239,11 @@ export interface MoqRelayHandle {
|
|
|
233
239
|
* by name on norsk-net (NORSK_CTL_MOQ_RELAY_PUBLIC_URL). Absent in publish
|
|
234
240
|
* reach, where ctl's default (advertised host, published port) is right. */
|
|
235
241
|
browserUrl?: string;
|
|
242
|
+
/** Where a browser here loads the product's pages (the join page, a
|
|
243
|
+
* dashboard) so the relay URLs the daemon advertises on its proxy base
|
|
244
|
+
* work: the proxy base, or in direct reach this container's
|
|
245
|
+
* localhost:<proxy port>, forwarded to the proxy. Set once the daemon is up. */
|
|
246
|
+
pageBase?: string;
|
|
236
247
|
}
|
|
237
248
|
export interface SessionOptions {
|
|
238
249
|
mode: DemoMode;
|
|
@@ -342,6 +353,7 @@ export declare class DemoSession {
|
|
|
342
353
|
private readonly moqRelayOptions;
|
|
343
354
|
/** Set once attachDaemon has given the private daemon its relay. */
|
|
344
355
|
moqRelay: MoqRelayHandle | undefined;
|
|
356
|
+
private pageForward;
|
|
345
357
|
daemon: DaemonProcess | null;
|
|
346
358
|
dev: ProcessHandle | null;
|
|
347
359
|
extras: string[];
|
|
@@ -371,6 +383,14 @@ export declare class DemoSession {
|
|
|
371
383
|
/** Private: init a virgin store and start a daemon on the band. Reuse: the
|
|
372
384
|
* developer's daemon must already answer. */
|
|
373
385
|
attachDaemon(): Promise<void>;
|
|
386
|
+
/** The daemon advertises the relay's fingerprint and WebSocket fallback on
|
|
387
|
+
* its proxy base, http://localhost:<proxy port>. In direct reach that port
|
|
388
|
+
* is published on the docker host, not in this container, so this
|
|
389
|
+
* container's own localhost:<proxy port> is forwarded to the proxy: the
|
|
390
|
+
* advertised URLs then work for a browser here, and a page loaded from
|
|
391
|
+
* localhost is a secure context (WebTransport, getUserMedia), which the
|
|
392
|
+
* host gateway's http origin is not. */
|
|
393
|
+
private attachMoqRelayPages;
|
|
374
394
|
/** Name the relay for this run, find it three free ports, and store the
|
|
375
395
|
* auth setting the daemon reads at boot. Returns the daemon's relay env. */
|
|
376
396
|
private prepareMoqRelay;
|
|
@@ -437,3 +457,8 @@ export declare function runExportCheck(spec: DemoSpec, opts: ExportCheckOptions,
|
|
|
437
457
|
export declare function exportStandaloneWorkdir(s: DemoSession, templateName: string, to: string): Promise<void>;
|
|
438
458
|
/** `demo down`: tear down the run `up` recorded, from any shell. */
|
|
439
459
|
export declare function demoDown(product: string, deps?: DemoDeps): Promise<void>;
|
|
460
|
+
/** A plain TCP forward from this process' loopback (both families where they
|
|
461
|
+
* exist) to `host:targetPort`. */
|
|
462
|
+
export declare function forwardLocalPort(port: number, host: string, targetPort: number): Promise<{
|
|
463
|
+
close(): void;
|
|
464
|
+
}>;
|
package/demo/run.js
CHANGED
|
@@ -433,6 +433,7 @@ export class DemoSession {
|
|
|
433
433
|
moqRelayOptions;
|
|
434
434
|
/** Set once attachDaemon has given the private daemon its relay. */
|
|
435
435
|
moqRelay;
|
|
436
|
+
pageForward;
|
|
436
437
|
daemon = null;
|
|
437
438
|
dev = null;
|
|
438
439
|
extras = [];
|
|
@@ -580,19 +581,35 @@ export class DemoSession {
|
|
|
580
581
|
if (netReachMode() === "direct" && this.deps.ensureNetwork() === "failed") {
|
|
581
582
|
throw new Error("could not join the runner to norsk-net for direct reach");
|
|
582
583
|
}
|
|
584
|
+
await this.attachMoqRelayPages();
|
|
585
|
+
}
|
|
586
|
+
/** The daemon advertises the relay's fingerprint and WebSocket fallback on
|
|
587
|
+
* its proxy base, http://localhost:<proxy port>. In direct reach that port
|
|
588
|
+
* is published on the docker host, not in this container, so this
|
|
589
|
+
* container's own localhost:<proxy port> is forwarded to the proxy: the
|
|
590
|
+
* advertised URLs then work for a browser here, and a page loaded from
|
|
591
|
+
* localhost is a secure context (WebTransport, getUserMedia), which the
|
|
592
|
+
* host gateway's http origin is not. */
|
|
593
|
+
async attachMoqRelayPages() {
|
|
594
|
+
const relay = this.moqRelay;
|
|
595
|
+
if (!relay)
|
|
596
|
+
return;
|
|
597
|
+
if (netReachMode() !== "direct" || this.proxyHost === "localhost") {
|
|
598
|
+
relay.pageBase = this.proxyBase;
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
const port = this.ports.proxyPort;
|
|
602
|
+
const forward = this.deps.forwardLocalPort ?? forwardLocalPort;
|
|
603
|
+
this.pageForward = await forward(port, this.proxyHost, port);
|
|
604
|
+
relay.pageBase = `${this.proxyScheme}://localhost:${port}`;
|
|
605
|
+
this.deps.log(`localhost:${port} forwarded to the proxy at ${this.proxyHost}:${port} for the relay's pages`);
|
|
583
606
|
}
|
|
584
607
|
/** Name the relay for this run, find it three free ports, and store the
|
|
585
608
|
* auth setting the daemon reads at boot. Returns the daemon's relay env. */
|
|
586
609
|
async prepareMoqRelay(opts) {
|
|
587
610
|
const auth = opts.auth ?? "off";
|
|
588
|
-
// The relay's fingerprint and WebSocket fallback are advertised on the
|
|
589
|
-
// proxy's base URL, i.e. the daemon's public host. In direct reach the
|
|
590
|
-
// browser is in this runner container and reaches the proxy at proxyHost
|
|
591
|
-
// (the host gateway), not the daemon's default of localhost.
|
|
592
|
-
const advertiseProxy = netReachMode() === "direct" && this.publicHost === undefined && this.proxyHost !== "localhost";
|
|
593
611
|
const settings = [
|
|
594
612
|
...(auth !== "off" ? [{ flag: "--moq-relay-auth", key: "moqRelayAuth", value: auth }] : []),
|
|
595
|
-
...(advertiseProxy ? [{ flag: "--public-host", key: "publicHost", value: this.proxyHost }] : []),
|
|
596
613
|
];
|
|
597
614
|
if (settings.length > 0) {
|
|
598
615
|
const argv = ["config", "set", ...settings.flatMap((x) => [x.flag, x.value])];
|
|
@@ -653,6 +670,8 @@ export class DemoSession {
|
|
|
653
670
|
}
|
|
654
671
|
/** The daemon never removes its relay, on shutdown or otherwise. */
|
|
655
672
|
removeMoqRelay() {
|
|
673
|
+
this.pageForward?.close();
|
|
674
|
+
this.pageForward = undefined;
|
|
656
675
|
const relay = this.moqRelay;
|
|
657
676
|
if (!relay)
|
|
658
677
|
return;
|
|
@@ -1009,3 +1028,29 @@ export async function demoDown(product, deps = defaultDemoDeps(process.cwd())) {
|
|
|
1009
1028
|
deps.state.remove(product);
|
|
1010
1029
|
deps.log(`${product} demo torn down${state.daemon === "reuse" ? " (your daemon and its registration are untouched)" : ""}`);
|
|
1011
1030
|
}
|
|
1031
|
+
/** A plain TCP forward from this process' loopback (both families where they
|
|
1032
|
+
* exist) to `host:targetPort`. */
|
|
1033
|
+
export async function forwardLocalPort(port, host, targetPort) {
|
|
1034
|
+
const { createServer, connect } = await import("node:net");
|
|
1035
|
+
const listen = (address) => new Promise((resolve, reject) => {
|
|
1036
|
+
const server = createServer((client) => {
|
|
1037
|
+
const upstream = connect(targetPort, host);
|
|
1038
|
+
client.pipe(upstream).pipe(client);
|
|
1039
|
+
const end = () => {
|
|
1040
|
+
client.destroy();
|
|
1041
|
+
upstream.destroy();
|
|
1042
|
+
};
|
|
1043
|
+
client.on("error", end);
|
|
1044
|
+
upstream.on("error", end);
|
|
1045
|
+
});
|
|
1046
|
+
server.once("error", (e) => address === "::1" && (e.code === "EADDRNOTAVAIL" || e.code === "EAFNOSUPPORT") ? resolve(undefined) : reject(e));
|
|
1047
|
+
server.listen(port, address, () => resolve(server));
|
|
1048
|
+
});
|
|
1049
|
+
const servers = [await listen("127.0.0.1"), await listen("::1")].filter((x) => x !== undefined);
|
|
1050
|
+
return {
|
|
1051
|
+
close: () => {
|
|
1052
|
+
for (const s of servers)
|
|
1053
|
+
s.close();
|
|
1054
|
+
},
|
|
1055
|
+
};
|
|
1056
|
+
}
|