@dev-anywhere/relay 0.4.72 → 0.4.73

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.
@@ -513,6 +513,11 @@ var RelayClientInfoSchema = z8.object({
513
513
  connectedAt: z8.number().int().nonnegative(),
514
514
  current: z8.boolean().optional(),
515
515
  userAgent: z8.string().optional(),
516
+ platform: z8.string().optional(),
517
+ maxTouchPoints: z8.number().int().nonnegative().optional(),
518
+ browserName: z8.string().min(1),
519
+ osName: z8.string().min(1),
520
+ deviceKind: z8.enum(["desktop", "tablet", "phone", "unknown"]),
516
521
  remoteAddress: z8.string().optional()
517
522
  });
518
523
  var AgentCliAvailabilitySchema = z8.object({
@@ -675,7 +680,13 @@ var relayControlDefinitions = [
675
680
  control("latency_web_proxy_pong", { ...RequiredRequestIdShape, proxyNow: z8.number().optional() }, "proxy_to_client"),
676
681
  // 客户端注册协议
677
682
  control("client_register", {
678
- clientId: IdSchema
683
+ clientId: IdSchema,
684
+ userAgent: z8.string().optional(),
685
+ platform: z8.string().optional(),
686
+ maxTouchPoints: z8.number().int().nonnegative().optional(),
687
+ browserName: z8.string().min(1),
688
+ osName: z8.string().min(1),
689
+ deviceKind: z8.enum(["desktop", "tablet", "phone", "unknown"])
679
690
  }),
680
691
  control("client_register_response", {
681
692
  status: z8.enum(["restored", "proxy_offline", "new"]),
@@ -964,7 +975,8 @@ function isClientToProxyRelayControlType(type) {
964
975
 
965
976
  // ../../packages/shared/dist/constants/relay-close-codes.js
966
977
  var RelayCloseCode = {
967
- CLIENT_KICKED: 4401
978
+ CLIENT_KICKED: 4401,
979
+ CLIENT_PROTOCOL_REJECTED: 4402
968
980
  };
969
981
 
970
982
  // ../../packages/shared/dist/binary-frame.js
@@ -1173,6 +1185,11 @@ var RelayRegistry = class {
1173
1185
  connectedAt: metadata.connectedAt ?? Date.now(),
1174
1186
  ...metadata.clientId !== void 0 ? { clientId: metadata.clientId } : {},
1175
1187
  ...metadata.userAgent !== void 0 ? { userAgent: metadata.userAgent } : {},
1188
+ ...metadata.platform !== void 0 ? { platform: metadata.platform } : {},
1189
+ ...metadata.maxTouchPoints !== void 0 ? { maxTouchPoints: metadata.maxTouchPoints } : {},
1190
+ ...metadata.browserName !== void 0 ? { browserName: metadata.browserName } : {},
1191
+ ...metadata.osName !== void 0 ? { osName: metadata.osName } : {},
1192
+ ...metadata.deviceKind !== void 0 ? { deviceKind: metadata.deviceKind } : {},
1176
1193
  ...metadata.remoteAddress !== void 0 ? { remoteAddress: metadata.remoteAddress } : {}
1177
1194
  });
1178
1195
  }
@@ -1184,6 +1201,21 @@ var RelayRegistry = class {
1184
1201
  }
1185
1202
  this.addClientWs(ws, { clientId });
1186
1203
  }
1204
+ updateConnectedClientMetadata(ws, metadata) {
1205
+ const current = this.connectedClients.get(ws);
1206
+ if (!current) {
1207
+ this.addClientWs(ws, metadata);
1208
+ return;
1209
+ }
1210
+ if (metadata.clientId !== void 0) current.clientId = metadata.clientId;
1211
+ if (metadata.userAgent !== void 0) current.userAgent = metadata.userAgent;
1212
+ if (metadata.platform !== void 0) current.platform = metadata.platform;
1213
+ if (metadata.maxTouchPoints !== void 0) current.maxTouchPoints = metadata.maxTouchPoints;
1214
+ if (metadata.browserName !== void 0) current.browserName = metadata.browserName;
1215
+ if (metadata.osName !== void 0) current.osName = metadata.osName;
1216
+ if (metadata.deviceKind !== void 0) current.deviceKind = metadata.deviceKind;
1217
+ if (metadata.remoteAddress !== void 0) current.remoteAddress = metadata.remoteAddress;
1218
+ }
1187
1219
  removeClientWs(ws) {
1188
1220
  this.connectedClients.delete(ws);
1189
1221
  }
@@ -1235,6 +1267,7 @@ var RelayRegistry = class {
1235
1267
  const details = [];
1236
1268
  for (const [ws, metadata] of this.connectedClients) {
1237
1269
  if (ws.readyState !== WebSocket.OPEN || !metadata.clientId) continue;
1270
+ if (!metadata.browserName || !metadata.osName || !metadata.deviceKind) continue;
1238
1271
  const binding = this.clientBindings.get(metadata.clientId);
1239
1272
  details.push({
1240
1273
  clientId: metadata.clientId,
@@ -1242,6 +1275,11 @@ var RelayRegistry = class {
1242
1275
  connectedAt: metadata.connectedAt,
1243
1276
  ...metadata.clientId === currentClientId ? { current: true } : {},
1244
1277
  ...metadata.userAgent !== void 0 ? { userAgent: metadata.userAgent } : {},
1278
+ ...metadata.platform !== void 0 ? { platform: metadata.platform } : {},
1279
+ ...metadata.maxTouchPoints !== void 0 ? { maxTouchPoints: metadata.maxTouchPoints } : {},
1280
+ browserName: metadata.browserName,
1281
+ osName: metadata.osName,
1282
+ deviceKind: metadata.deviceKind,
1245
1283
  ...metadata.remoteAddress !== void 0 ? { remoteAddress: metadata.remoteAddress } : {}
1246
1284
  });
1247
1285
  }
@@ -1754,7 +1792,6 @@ function handleProxyConnection(ws, registry, logger, chaos) {
1754
1792
 
1755
1793
  // src/handlers/client.ts
1756
1794
  import { WebSocket as WebSocket7 } from "ws";
1757
- import { nanoid as nanoid3 } from "nanoid";
1758
1795
 
1759
1796
  // src/voice/bailian-asr.ts
1760
1797
  import { EventEmitter } from "events";
@@ -2404,9 +2441,26 @@ function handleVoiceConfigControl(msg, ws, store, logger, providers) {
2404
2441
 
2405
2442
  // src/handlers/client.ts
2406
2443
  var MAX_JSON_MESSAGE_SIZE2 = 1 * 1024 * 1024;
2407
- function handleClientRegister(clientId, clientWs, registry, logger) {
2444
+ function isMalformedClientRegister(raw) {
2445
+ try {
2446
+ const parsed = JSON.parse(raw);
2447
+ return parsed !== null && typeof parsed === "object" && parsed.type === "client_register";
2448
+ } catch {
2449
+ return false;
2450
+ }
2451
+ }
2452
+ function handleClientRegister(registration, clientWs, registry, logger) {
2453
+ const { clientId } = registration;
2408
2454
  clientWs.clientId = clientId;
2409
- registry.updateConnectedClientId(clientWs, clientId);
2455
+ registry.updateConnectedClientMetadata(clientWs, {
2456
+ clientId,
2457
+ ...registration.userAgent !== void 0 ? { userAgent: registration.userAgent } : {},
2458
+ ...registration.platform !== void 0 ? { platform: registration.platform } : {},
2459
+ ...registration.maxTouchPoints !== void 0 ? { maxTouchPoints: registration.maxTouchPoints } : {},
2460
+ browserName: registration.browserName,
2461
+ osName: registration.osName,
2462
+ deviceKind: registration.deviceKind
2463
+ });
2410
2464
  const binding = registry.getClientBinding(clientId);
2411
2465
  if (!binding) {
2412
2466
  clientWs.send(
@@ -2516,6 +2570,19 @@ function rejectNotBound(ws) {
2516
2570
  })
2517
2571
  );
2518
2572
  }
2573
+ function rejectNotRegistered2(ws, requestId) {
2574
+ ws.send(
2575
+ JSON.stringify({
2576
+ type: "relay_error",
2577
+ requestId,
2578
+ code: RelayErrorCode.NOT_REGISTERED,
2579
+ message: "Client must register before selecting a proxy"
2580
+ })
2581
+ );
2582
+ }
2583
+ function closeRejectedClientProtocol(ws) {
2584
+ ws.close(RelayCloseCode.CLIENT_PROTOCOL_REJECTED, "client protocol rejected");
2585
+ }
2519
2586
  function rejectProxySelect(ws, requestId, proxyId) {
2520
2587
  ws.send(
2521
2588
  JSON.stringify({
@@ -2570,7 +2637,7 @@ function handleClientConnection(ws, registry, logger, chaos, voiceConfigStore, v
2570
2637
  "Client message received"
2571
2638
  );
2572
2639
  if (msg.type === "client_register") {
2573
- handleClientRegister(msg.clientId, clientWs, registry, logger);
2640
+ handleClientRegister(msg, clientWs, registry, logger);
2574
2641
  return;
2575
2642
  }
2576
2643
  if (msg.type === "relay_client_list_request") {
@@ -2668,13 +2735,15 @@ function handleClientConnection(ws, registry, logger, chaos, voiceConfigStore, v
2668
2735
  return;
2669
2736
  }
2670
2737
  if (msg.type === "proxy_select") {
2738
+ if (!clientWs.clientId) {
2739
+ rejectNotRegistered2(clientWs, msg.requestId);
2740
+ closeRejectedClientProtocol(clientWs);
2741
+ return;
2742
+ }
2671
2743
  if (!registry.isProxyOnline(msg.proxyId)) {
2672
2744
  rejectProxySelect(clientWs, msg.requestId, msg.proxyId);
2673
2745
  return;
2674
2746
  }
2675
- if (!clientWs.clientId) {
2676
- clientWs.clientId = `anon-${nanoid3(10)}`;
2677
- }
2678
2747
  const bound = registry.bindClientById(clientWs.clientId, msg.proxyId, clientWs);
2679
2748
  if (!bound) {
2680
2749
  rejectProxySelect(clientWs, msg.requestId, msg.proxyId);
@@ -2723,6 +2792,9 @@ function handleClientConnection(ws, registry, logger, chaos, voiceConfigStore, v
2723
2792
  message: `${result.error} | raw: ${raw.slice(0, 200)}`
2724
2793
  })
2725
2794
  );
2795
+ if (isMalformedClientRegister(raw)) {
2796
+ closeRejectedClientProtocol(clientWs);
2797
+ }
2726
2798
  });
2727
2799
  clientWs.on("close", () => {
2728
2800
  registry.removeClientWs(clientWs);
@@ -3526,4 +3598,4 @@ export {
3526
3598
  parseRelayChaosFromEnv,
3527
3599
  createRelayServer
3528
3600
  };
3529
- //# sourceMappingURL=chunk-H7OL7UK7.js.map
3601
+ //# sourceMappingURL=chunk-UV7DNQUI.js.map