@camstack/server 1.2.145 → 1.2.147

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.
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ADAPTIVE_PROBE_BYTES = void 0;
4
+ exports.registerAdaptiveProbeRoute = registerAdaptiveProbeRoute;
5
+ exports.ADAPTIVE_PROBE_BYTES = 128 * 1024;
6
+ const BODY = Buffer.alloc(exports.ADAPTIVE_PROBE_BYTES, 0x61);
7
+ function registerAdaptiveProbeRoute(fastify) {
8
+ fastify.get('/adaptive-probe', async (_req, reply) => {
9
+ reply.header('cache-control', 'no-store');
10
+ reply.header('content-type', 'application/octet-stream');
11
+ return reply.send(BODY);
12
+ });
13
+ }
@@ -4338,6 +4338,22 @@ function createCapRouter_localNetwork(getProvider, createRemoteProxy) {
4338
4338
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
4339
4339
  return p.setNotificationEndpoint(methodInput);
4340
4340
  }),
4341
+ getViewerEndpoints: trpc_middleware_js_1.protectedProcedure
4342
+ .input(zod_1.z.object({ nodeId: zod_1.z.string().optional() }).optional())
4343
+ .output(types_57.localNetworkCapability.methods.getViewerEndpoints.output)
4344
+ .query(async ({ input, ctx }) => {
4345
+ const p = resolveProvider('local-network', input?.nodeId, () => getProvider(ctx), createRemoteProxy);
4346
+ return p.getViewerEndpoints();
4347
+ }),
4348
+ setViewerEndpoints: trpc_middleware_js_1.protectedProcedure
4349
+ .input(types_57.localNetworkCapability.methods.setViewerEndpoints.input.loose())
4350
+ .output(types_57.localNetworkCapability.methods.setViewerEndpoints.output)
4351
+ .mutation(async ({ input, ctx }) => {
4352
+ const { nodeId, ...methodInput } = input;
4353
+ const p = resolveProvider('local-network', nodeId, () => getProvider(ctx), createRemoteProxy);
4354
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
4355
+ return p.setViewerEndpoints(methodInput);
4356
+ }),
4341
4357
  getAllowedAddresses: trpc_middleware_js_1.protectedProcedure
4342
4358
  .input(zod_1.z.object({ nodeId: zod_1.z.string().optional() }).optional())
4343
4359
  .output(types_57.localNetworkCapability.methods.getAllowedAddresses.output)
@@ -88,50 +88,15 @@ function enrichInputWithRelayClass(input, clientClass) {
88
88
  return { ...input, relayOnly };
89
89
  }
90
90
  /**
91
- * Initial adaptive rung for a genuinely-REMOTE viewer.
92
- *
93
- * A `remote` (public / CGNAT-4G / internet) client cannot reliably receive the
94
- * high tier's large keyframe over a lossy relay path — LAN can, which is why
95
- * adaptive works on LAN but a remote adaptive viewer sees a permanent black
96
- * frame (ICE/DTLS up, no decodable frame). So a remote adaptive session STARTS
97
- * on the smallest tier; the broker's `AdaptiveController` upgrades from there
98
- * once the link proves healthy. `lan` and `vpn` (Tailscale, direct overlay)
99
- * keep the full-quality default and are never biased.
100
- */
101
- const REMOTE_INITIAL_ADAPTIVE_TIER = 'low';
102
- /**
103
- * Bias the INITIAL adaptive-tier selection for a genuinely-remote viewer by
104
- * injecting a `prefersTier` hint the broker's `selectBestBroker` already
105
- * honours. The hub is the only layer that knows the client's network class
106
- * (the forked broker cannot see the HTTP request), so — exactly like
107
- * `relayOnly` and the User-Agent — the class is read here and threaded down
108
- * through the EXISTING `hints` cap field (no cap/schema change: `prefersTier`
109
- * is already part of `webrtcClientHintsSchema`).
110
- *
111
- * Applied ONLY when:
112
- * - the client class is `remote` (lan/vpn keep the full-quality default), and
113
- * - the target is adaptive (`handleOffer` defaults an absent target to
114
- * adaptive; a pinned profile/cam-stream is the operator's explicit choice
115
- * and passes through untouched), and
116
- * - the caller did not already set `prefersTier` (no client does today, but
117
- * keep the trusted-injection rule symmetric with relayOnly/userAgent).
118
- *
119
- * Immutable — builds a NEW input (and a new `hints`), never mutates the
120
- * caller's. On a downgrade re-offer the broker's controller-chosen tier intent
121
- * overrides this hint, so a healthy remote session can still climb above `low`.
91
+ * Bias used to live here (`prefersTier: 'low'` for `remote`). That pinned
92
+ * every phone-sized session — including LAN IPv6 GUA misclassified as remote
93
+ * — onto the sub stream. Initial tier is now `pickAdaptiveTier` (default
94
+ * high, downlink limiter, viewport ceiling for tiny tiles). This function
95
+ * stays as the documented seam so a future probe can still thread class
96
+ * without a cap change; today it is a no-op.
122
97
  */
123
- function enrichHintsWithClientClass(input, clientClass) {
124
- if (clientClass !== 'remote')
125
- return input;
126
- const isAdaptive = input.target === undefined || input.target.kind === 'adaptive';
127
- if (!isAdaptive)
128
- return input;
129
- if (input.hints?.prefersTier !== undefined)
130
- return input;
131
- return {
132
- ...input,
133
- hints: { ...input.hints, prefersTier: REMOTE_INITIAL_ADAPTIVE_TIER },
134
- };
98
+ function enrichHintsWithClientClass(input, _clientClass) {
99
+ return input;
135
100
  }
136
101
  /**
137
102
  * Per-request wrapper around the resolved `webrtc-session` broker singleton.
@@ -12,18 +12,26 @@ exports.isSessionGradeJwtPayload = isSessionGradeJwtPayload;
12
12
  * after a tRPC login; read by the addon-route catch-all for `authenticated`
13
13
  * routes hit by a plain browser navigation. */
14
14
  exports.SESSION_COOKIE = 'camstack_session';
15
- function buildSessionCookie(token, ttlSec) {
15
+ function buildSessionCookie(token, ttlSec, opts = {}) {
16
16
  return {
17
17
  name: exports.SESSION_COOKIE,
18
18
  value: token,
19
- options: { httpOnly: true, sameSite: 'lax', secure: true, path: '/', maxAge: ttlSec },
19
+ options: {
20
+ httpOnly: true,
21
+ sameSite: 'lax',
22
+ // Secure cookies are invisible on the LAN HTTP sibling (plain http://).
23
+ // Default stays true so HTTPS callers do not regress.
24
+ secure: opts.secure ?? true,
25
+ path: '/',
26
+ maxAge: ttlSec,
27
+ },
20
28
  };
21
29
  }
22
- function clearSessionCookie() {
30
+ function clearSessionCookie(opts = {}) {
23
31
  return {
24
32
  name: exports.SESSION_COOKIE,
25
33
  value: '',
26
- options: { httpOnly: true, sameSite: 'lax', secure: true, path: '/', maxAge: 0 },
34
+ options: { httpOnly: true, sameSite: 'lax', secure: opts.secure ?? true, path: '/', maxAge: 0 },
27
35
  };
28
36
  }
29
37
  /**
package/dist/main.js CHANGED
@@ -59,6 +59,7 @@ const ws_2 = require("ws");
59
59
  const addon_upload_1 = require("./api/addon-upload");
60
60
  const auth_whoami_1 = require("./api/auth-whoami");
61
61
  const health_routes_1 = require("./api/health/health.routes");
62
+ const adaptive_probe_routes_1 = require("./api/health/adaptive-probe.routes");
62
63
  const model_distributor_js_1 = require("./api/model-distributor.js");
63
64
  const oauth2_routes_js_1 = require("./api/oauth2/oauth2-routes.js");
64
65
  const server_upload_1 = require("./api/server-upload");
@@ -459,6 +460,7 @@ async function bootstrap() {
459
460
  verifyToken: (token) => app.get(auth_service_1.AuthService).verifyToken(token),
460
461
  });
461
462
  console.log(`[bootstrap] Health routes registered (hub v${hubVersion})`);
463
+ (0, adaptive_probe_routes_1.registerAdaptiveProbeRoute)(fastify);
462
464
  }
463
465
  catch (err) {
464
466
  console.warn('[bootstrap] Failed to register health routes:', err);
@@ -790,13 +792,13 @@ async function bootstrap() {
790
792
  catch {
791
793
  return reply.status(401).send({ error: 'invalid token' });
792
794
  }
793
- const c = (0, session_cookie_js_1.buildSessionCookie)(token, ttlSec);
795
+ const c = (0, session_cookie_js_1.buildSessionCookie)(token, ttlSec, { secure: request.protocol === 'https' });
794
796
  reply.setCookie(c.name, c.value, c.options);
795
797
  return reply.send({ ok: true });
796
798
  });
797
799
  // DELETE /api/auth/session — clear the cookie on logout.
798
- fastify.delete('/api/auth/session', async (_request, reply) => {
799
- const c = (0, session_cookie_js_1.clearSessionCookie)();
800
+ fastify.delete('/api/auth/session', async (request, reply) => {
801
+ const c = (0, session_cookie_js_1.clearSessionCookie)({ secure: request.protocol === 'https' });
800
802
  reply.setCookie(c.name, c.value, c.options);
801
803
  return reply.send({ ok: true });
802
804
  });
@@ -826,7 +828,7 @@ async function bootstrap() {
826
828
  catch {
827
829
  return reply.status(401).send({ error: 'invalid token' });
828
830
  }
829
- const c = (0, session_cookie_js_1.buildSessionCookie)(token, ttlSec);
831
+ const c = (0, session_cookie_js_1.buildSessionCookie)(token, ttlSec, { secure: request.protocol === 'https' });
830
832
  reply.setCookie(c.name, c.value, c.options);
831
833
  return reply.redirect(next);
832
834
  });
@@ -1182,6 +1184,7 @@ async function bootstrap() {
1182
1184
  url.startsWith('/api/') ||
1183
1185
  url.startsWith('/agent') ||
1184
1186
  url.startsWith('/health') ||
1187
+ url.startsWith('/adaptive-probe') ||
1185
1188
  url.startsWith('/viewer')) {
1186
1189
  return reply.callNotFound();
1187
1190
  }
@@ -1301,7 +1304,18 @@ async function bootstrap() {
1301
1304
  }
1302
1305
  };
1303
1306
  try {
1304
- await app.listen(port, host);
1307
+ const listenHost = (0, system_1.allFamiliesListenHost)(host).host;
1308
+ try {
1309
+ await app.listen(port, listenHost);
1310
+ }
1311
+ catch (listenErr) {
1312
+ if (listenHost === '::' && host !== '::') {
1313
+ await app.listen(port, '0.0.0.0');
1314
+ }
1315
+ else {
1316
+ throw listenErr;
1317
+ }
1318
+ }
1305
1319
  }
1306
1320
  catch (listenErr) {
1307
1321
  if (listenErr !== null &&
@@ -1319,8 +1333,13 @@ async function bootstrap() {
1319
1333
  // LAN HTTP sibling — same Fastify request graph, dedicated port. Handler
1320
1334
  // is registered as soon as we have the instance; bind happens after HTTPS
1321
1335
  // is up so a failed HTTPS listen does not leave HTTP serving alone.
1322
- (0, system_1.registerLanHttpHandler)((req, res) => {
1323
- fastify.server.emit('request', req, res);
1336
+ (0, system_1.registerLanHttpHandler)({
1337
+ onRequest: (req, res) => {
1338
+ fastify.server.emit('request', req, res);
1339
+ },
1340
+ onUpgrade: (req, socket, head) => {
1341
+ fastify.server.emit('upgrade', req, socket, head);
1342
+ },
1324
1343
  });
1325
1344
  try {
1326
1345
  const lanHttp = await (0, system_1.bindPendingLanHttp)();
@@ -414,7 +414,13 @@ async function bootManual(opts) {
414
414
  });
415
415
  },
416
416
  async listen(port, host) {
417
- await fastify.listen({ port, host });
417
+ await fastify.listen({
418
+ port,
419
+ host,
420
+ // Dual-stack when binding `::`. Positional listen() drops this and
421
+ // on macOS/BSD `IPV6_V6ONLY` defaults to 1 — IPv4 clients die.
422
+ ipv6Only: host === '::' ? false : undefined,
423
+ });
418
424
  },
419
425
  close,
420
426
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/server",
3
- "version": "1.2.145",
3
+ "version": "1.2.147",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -33,18 +33,18 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "@camstack/addon-admin-ui": "1.2.88",
37
- "@camstack/addon-agent-ui": "1.2.27",
38
- "@camstack/addon-auth": "1.2.29",
39
- "@camstack/addon-decoder-nodeav": "1.2.25",
40
- "@camstack/addon-notifiers": "1.2.30",
41
- "@camstack/addon-pipeline": "1.2.107",
42
- "@camstack/addon-pipeline-orchestrator": "1.2.90",
43
- "@camstack/addon-post-analysis": "1.2.109",
44
- "@camstack/sdk": "1.2.29",
45
- "@camstack/system": "1.2.116",
46
- "@camstack/types": "1.2.97",
47
- "@camstack/ui-library": "1.2.67",
36
+ "@camstack/addon-admin-ui": "1.2.90",
37
+ "@camstack/addon-agent-ui": "1.2.28",
38
+ "@camstack/addon-auth": "1.2.30",
39
+ "@camstack/addon-decoder-nodeav": "1.2.26",
40
+ "@camstack/addon-notifiers": "1.2.31",
41
+ "@camstack/addon-pipeline": "1.2.115",
42
+ "@camstack/addon-pipeline-orchestrator": "1.2.99",
43
+ "@camstack/addon-post-analysis": "1.2.110",
44
+ "@camstack/sdk": "1.2.30",
45
+ "@camstack/system": "1.2.118",
46
+ "@camstack/types": "1.2.99",
47
+ "@camstack/ui-library": "1.2.68",
48
48
  "@fastify/compress": "^9.0.0",
49
49
  "@fastify/cookie": "^11.0.2",
50
50
  "@fastify/cors": "^11.2.0",