screenreader-speech-capture 0.0.1-preview.4 → 0.0.1-preview.5

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +24 -7
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import http from "node:http";
3
+ import os from "node:os";
3
4
  import net from "node:net";
4
5
  import { TextDecoder as TextDecoder$1, parseArgs } from "node:util";
5
6
  import fs from "node:fs/promises";
6
7
  import path from "node:path";
7
8
  import fs$1 from "node:fs";
8
- import os from "node:os";
9
9
  // package.json
10
- var version = "0.0.1-preview.3";
10
+ var version = "0.0.1-preview.5";
11
11
  // ../shared/src/api-version.ts
12
12
  /** Path prefix of every API route. */
13
13
  const API_PREFIX = "/api/v1";
@@ -63,6 +63,26 @@ async function listen(server, host, port) {
63
63
  });
64
64
  return server.address().port;
65
65
  }
66
+ // src/adapters/in/net/reachable-urls.ts
67
+ /** True for a host that means "every interface" (`0.0.0.0`, `::`). */
68
+ const isWildcard = (host) => [
69
+ "0.0.0.0",
70
+ "::",
71
+ ""
72
+ ].includes(host);
73
+ /** `host:port` for a URL, with an IPv6 host in brackets. */
74
+ function hostPort(host, port) {
75
+ return host.includes(":") ? `[${host}]:${port}` : `${host}:${port}`;
76
+ }
77
+ /**
78
+ * URLs other machines can use to reach a listener on `host:port`. For a wildcard host (`0.0.0.0`,
79
+ * `::`) these are the machine's external IPv4 addresses, then `localhost`; otherwise just `host`.
80
+ */
81
+ function reachableUrls(scheme, host, port, interfaces = os.networkInterfaces()) {
82
+ if (!isWildcard(host)) return [`${scheme}://${hostPort(host, port)}`];
83
+ const addresses = Object.values(interfaces).flatMap((infos) => infos ?? []).filter((info) => info.family === "IPv4" && !info.internal).map((info) => info.address);
84
+ return [...new Set(addresses), "localhost"].map((a) => `${scheme}://${hostPort(a, port)}`);
85
+ }
66
86
  // src/adapters/in/http/response.ts
67
87
  function sendJson(res, status, body) {
68
88
  const data = JSON.stringify(body);
@@ -355,10 +375,6 @@ function statusRoutes(router, { status, config }) {
355
375
  const CLOSE_GRACE_MS = 1e3;
356
376
  /** Bytes an SSE stream may hold for a client that stopped reading before it is closed. */
357
377
  const SSE_MAX_BUFFERED_BYTES = 1048576;
358
- /** `host:port` for a URL, with an IPv6 host in brackets. */
359
- function hostPort(host, port) {
360
- return host.includes(":") ? `[${host}]:${port}` : `${host}:${port}`;
361
- }
362
378
  /**
363
379
  * Driving adapter for the REST + SSE API (docs/http-api.md), on plain `node:http`.
364
380
  */
@@ -445,7 +461,8 @@ var HttpServer = class {
445
461
  ...settings,
446
462
  port
447
463
  };
448
- this.deps.logger.info(`listening on http://${hostPort(settings.host, port)}`);
464
+ const urls = reachableUrls("http", settings.host, port).join(", ");
465
+ this.deps.logger.info(isWildcard(settings.host) ? `listening on ${hostPort(settings.host, port)}, reachable at ${urls}` : `listening on ${urls}`);
449
466
  return port;
450
467
  }
451
468
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screenreader-speech-capture",
3
- "version": "0.0.1-preview.4",
3
+ "version": "0.0.1-preview.5",
4
4
  "description": "Capture what a screen reader says (JAWS / NVDA via a SAPI 5 socket voice) and expose it over HTTP for automated tests.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",