@fuzdev/fuz_app 0.177.0 → 0.179.0

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 (98) hide show
  1. package/dist/actions/CLAUDE.md +117 -12
  2. package/dist/actions/connection_registry.d.ts +18 -0
  3. package/dist/actions/connection_registry.d.ts.map +1 -1
  4. package/dist/actions/connection_registry.js +23 -0
  5. package/dist/actions/room_action_specs.d.ts +733 -0
  6. package/dist/actions/room_action_specs.d.ts.map +1 -0
  7. package/dist/actions/room_action_specs.js +506 -0
  8. package/dist/actions/room_actions.d.ts +276 -0
  9. package/dist/actions/room_actions.d.ts.map +1 -0
  10. package/dist/actions/room_actions.js +394 -0
  11. package/dist/actions/room_client.svelte.d.ts +399 -0
  12. package/dist/actions/room_client.svelte.d.ts.map +1 -0
  13. package/dist/actions/room_client.svelte.js +942 -0
  14. package/dist/actions/room_registry.d.ts +454 -0
  15. package/dist/actions/room_registry.d.ts.map +1 -0
  16. package/dist/actions/room_registry.js +927 -0
  17. package/dist/actions/ws_socket_session.d.ts +2 -2
  18. package/dist/actions/ws_socket_session.js +3 -3
  19. package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
  20. package/dist/auth/role_grant_queries.d.ts +17 -0
  21. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  22. package/dist/auth/role_grant_queries.js +30 -0
  23. package/dist/rtc/rtc_mesh.svelte.d.ts +102 -0
  24. package/dist/rtc/rtc_mesh.svelte.d.ts.map +1 -0
  25. package/dist/rtc/rtc_mesh.svelte.js +232 -0
  26. package/dist/rtc/rtc_peer.svelte.d.ts +180 -0
  27. package/dist/rtc/rtc_peer.svelte.d.ts.map +1 -0
  28. package/dist/rtc/rtc_peer.svelte.js +397 -0
  29. package/dist/rtc/rtc_signal.d.ts +74 -0
  30. package/dist/rtc/rtc_signal.d.ts.map +1 -0
  31. package/dist/rtc/rtc_signal.js +87 -0
  32. package/dist/server/app_server.d.ts +16 -27
  33. package/dist/server/app_server.d.ts.map +1 -1
  34. package/dist/server/app_server.js +7 -9
  35. package/dist/testing/CLAUDE.md +72 -18
  36. package/dist/testing/cross_backend/action_manifest.d.ts +34 -2
  37. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  38. package/dist/testing/cross_backend/action_manifest.js +33 -6
  39. package/dist/testing/cross_backend/capabilities.d.ts +23 -5
  40. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  41. package/dist/testing/cross_backend/capabilities.js +4 -1
  42. package/dist/testing/cross_backend/default_backend_configs.js +1 -1
  43. package/dist/testing/cross_backend/full_spine_mount.d.ts +31 -6
  44. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  45. package/dist/testing/cross_backend/full_spine_mount.js +45 -13
  46. package/dist/testing/cross_backend/rooms_ws.d.ts +20 -0
  47. package/dist/testing/cross_backend/rooms_ws.d.ts.map +1 -0
  48. package/dist/testing/cross_backend/rooms_ws.js +534 -0
  49. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  50. package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -1
  51. package/dist/testing/cross_backend/spine_suites.d.ts +5 -2
  52. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  53. package/dist/testing/cross_backend/spine_suites.js +24 -5
  54. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  55. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  56. package/dist/testing/cross_backend/spine_surface_constants.js +2 -1
  57. package/dist/testing/cross_backend/test_room_authorize.d.ts +47 -0
  58. package/dist/testing/cross_backend/test_room_authorize.d.ts.map +1 -0
  59. package/dist/testing/cross_backend/test_room_authorize.js +58 -0
  60. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  61. package/dist/testing/cross_backend/testing_backdoor.js +10 -4
  62. package/dist/testing/cross_backend/testing_reset_actions.d.ts +85 -1
  63. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  64. package/dist/testing/cross_backend/testing_reset_actions.js +57 -3
  65. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  66. package/dist/testing/cross_backend/testing_server_bun.js +6 -7
  67. package/dist/testing/cross_backend/testing_server_core.d.ts +23 -37
  68. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  69. package/dist/testing/cross_backend/testing_server_core.js +1 -8
  70. package/dist/testing/cross_backend/testing_server_node.d.ts.map +1 -1
  71. package/dist/testing/cross_backend/testing_server_node.js +35 -46
  72. package/dist/testing/cross_backend/transport_composition.js +2 -2
  73. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  74. package/dist/testing/cross_backend/ts_spine_backend_config.js +6 -3
  75. package/dist/testing/stubs.d.ts +1 -1
  76. package/dist/testing/stubs.js +1 -1
  77. package/dist/ui/AccountSessions.svelte.d.ts.map +1 -1
  78. package/dist/ui/AdminAccounts.svelte.d.ts.map +1 -1
  79. package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -1
  80. package/dist/ui/AdminInvites.svelte.d.ts.map +1 -1
  81. package/dist/ui/AdminOverview.svelte.d.ts.map +1 -1
  82. package/dist/ui/AdminRoleGrantHistory.svelte.d.ts.map +1 -1
  83. package/dist/ui/AdminSessions.svelte.d.ts.map +1 -1
  84. package/dist/ui/AdminSettings.svelte.d.ts.map +1 -1
  85. package/dist/ui/AdminSurface.svelte.d.ts.map +1 -1
  86. package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
  87. package/dist/ui/ConfirmButton.svelte.d.ts.map +1 -1
  88. package/dist/ui/Datatable.svelte.d.ts.map +1 -1
  89. package/dist/ui/LoginForm.svelte.d.ts.map +1 -1
  90. package/dist/ui/LogoutButton.svelte.d.ts.map +1 -1
  91. package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -1
  92. package/dist/ui/PopoverButton.svelte.d.ts.map +1 -1
  93. package/dist/ui/RoleGrantOfferForm.svelte.d.ts.map +1 -1
  94. package/dist/ui/RoleGrantOfferHistory.svelte.d.ts.map +1 -1
  95. package/dist/ui/RoleGrantOfferInbox.svelte.d.ts.map +1 -1
  96. package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
  97. package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -1
  98. package/package.json +21 -26
@@ -94,7 +94,7 @@
94
94
  * ## A server-closed socket dispatches nothing
95
95
  *
96
96
  * A runtime adapter can keep delivering inbound frames after the server calls
97
- * `ws.close(…)`, until the close handshake completes (`@hono/node-ws` does —
97
+ * `ws.close(…)`, until the close handshake completes (`@hono/node-server` does —
98
98
  * up to the `ws` close timeout when the client withholds its close frame).
99
99
  * So every server-side close — revocation, cap eviction, heartbeat timeout,
100
100
  * an oversized message, a refused admission — removes the connection from the
@@ -160,7 +160,7 @@ export declare const PRE_ADMISSION_QUEUE_BYTES_FACTOR = 4;
160
160
  * stays open, and the requests already running keep answering.
161
161
  *
162
162
  * A runtime adapter can hand frames over without awaiting the previous one's
163
- * dispatch (`@hono/node-ws` does not await `onMessage`), so without a ceiling
163
+ * dispatch (`@hono/node-server` does not await `onMessage`), so without a ceiling
164
164
  * one socket could hold any number of handlers — and their pooled database
165
165
  * work — at once. Shedding rather than queueing keeps the socket reading, so a
166
166
  * reply to a server-initiated request still reaches the handler awaiting it.
@@ -94,7 +94,7 @@
94
94
  * ## A server-closed socket dispatches nothing
95
95
  *
96
96
  * A runtime adapter can keep delivering inbound frames after the server calls
97
- * `ws.close(…)`, until the close handshake completes (`@hono/node-ws` does —
97
+ * `ws.close(…)`, until the close handshake completes (`@hono/node-server` does —
98
98
  * up to the `ws` close timeout when the client withholds its close frame).
99
99
  * So every server-side close — revocation, cap eviction, heartbeat timeout,
100
100
  * an oversized message, a refused admission — removes the connection from the
@@ -161,7 +161,7 @@ export const PRE_ADMISSION_QUEUE_BYTES_FACTOR = 4;
161
161
  * stays open, and the requests already running keep answering.
162
162
  *
163
163
  * A runtime adapter can hand frames over without awaiting the previous one's
164
- * dispatch (`@hono/node-ws` does not await `onMessage`), so without a ceiling
164
+ * dispatch (`@hono/node-server` does not await `onMessage`), so without a ceiling
165
165
  * one socket could hold any number of handlers — and their pooled database
166
166
  * work — at once. Shedding rather than queueing keeps the socket reading, so a
167
167
  * reply to a server-initiated request still reaches the handler awaiting it.
@@ -667,7 +667,7 @@ export const create_ws_socket_events = (endpoint, upgrade) => {
667
667
  };
668
668
  return {
669
669
  onOpen: async (_event, ws) => {
670
- // An adapter may not await this (`@hono/node-ws` doesn't), so it
670
+ // An adapter may not await this (`@hono/node-server` doesn't), so it
671
671
  // must never reject.
672
672
  try {
673
673
  await open_socket(ws);
@@ -684,7 +684,7 @@ export declare const role_grant_assign_action_spec: {
684
684
  }>;
685
685
  async: true;
686
686
  description: string;
687
- error_reasons: ("insufficient_permissions" | "role_grant_offer_not_authorized" | "role_grant_offer_actor_account_mismatch" | "role_grant_builtin_scoped" | "role_not_web_grantable")[];
687
+ error_reasons: ("role_grant_offer_not_authorized" | "role_grant_offer_actor_account_mismatch" | "role_grant_builtin_scoped" | "role_not_web_grantable" | "insufficient_permissions")[];
688
688
  rate_limit: "account";
689
689
  };
690
690
  /**
@@ -176,6 +176,23 @@ export declare const query_account_has_global_role: (deps: QueryDeps, account_id
176
176
  * @returns `true` if the account is active and any of its actors holds an active global `role` grant
177
177
  */
178
178
  export declare const query_account_has_active_global_role: (deps: QueryDeps, account_id: string, role: string) => Promise<boolean>;
179
+ /**
180
+ * Actor-grain check: does `actor_id` hold an active **global** role_grant for
181
+ * `role`, with the actor and its account both active (`deleted_at IS NULL`)?
182
+ *
183
+ * The live read an authorizer makes when it must not trust the role grants
184
+ * the dispatcher loaded for the request — a room authorizer reads inside its
185
+ * reserve window (`actions/room_actions.ts`). Keyed on the acting actor, not
186
+ * the account: another actor of the same account holding the role doesn't
187
+ * count. Twin of the Rust `query_active_actor_holds_any_global_role` for one
188
+ * role.
189
+ *
190
+ * @param deps - query dependencies
191
+ * @param actor_id - the actor to check
192
+ * @param role - the role to check for (e.g. `ROLE_ADMIN`)
193
+ * @returns `true` if the actor and its account are active and the actor holds an active global `role` grant
194
+ */
195
+ export declare const query_actor_has_active_global_role: (deps: QueryDeps, actor_id: Uuid, role: string) => Promise<boolean>;
179
196
  /**
180
197
  * Count **active** accounts (`deleted_at IS NULL`) holding an active global
181
198
  * role_grant for `role`, counting only grants on **active actors**
@@ -1 +1 @@
1
- {"version":3,"file":"role_grant_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/role_grant_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAS3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAGpE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,0KAaoB,CAAC;AAcpD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,SAAS,EACf,OAAO,oBAAoB,KACzB,OAAO,CAAC,SAAS,CA8CnB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,SAAS,EACf,IAAI,IAAI,KACN,OAAO,CAAC,SAAS,GAAG,SAAS,CAI9B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,2CAA2C,GACvD,MAAM,SAAS,EACf,eAAe,MAAM,EACrB,UAAU,MAAM,KACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,IAAI,CAAA;CAAE,GAAG,IAAI,CAS1E,CAAC;AAEF,qHAAqH;AACrH,MAAM,WAAW,qB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ACH,eAAO,MAAM,kCAAkC,GAC9C,MAAM,SAAS,EACf,UAAU,IAAI,EACd,MAAM,MAAM,KACV,OAAO,CAAC,OAAO,CAgBjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,uDAAuD,GACnE,MAAM,SAAS,EACf,MAAM,MAAM,EACZ,wBAAuB,IAAI,GAAG,IAAW,KACvC,OAAO,CAAC,MAAM,CAuBhB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,yCAAyC,GACrD,MAAM,SAAS,EACf,MAAM,MAAM,KACV,OAAO,CAAC,MAAM,GAAG,IAAI,CAgBvB,CAAC;AAEF,8IAA8I;AAC9I,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;OAQG;IACH,OAAO,EAAE,KAAK,CAAC;QACd,aAAa,EAAE,IAAI,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,UAAU,EAAE,IAAI,CAAC;KACjB,CAAC,CAAC;IACH;;;;;;;;;;OAUG;IACH,iBAAiB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,iCAAiC,GAC7C,MAAM,SAAS,EACf,UAAU,IAAI,EACd,YAAY,IAAI,GAAG,IAAI,EACvB,SAAS,MAAM,GAAG,IAAI,KACpB,OAAO,CAAC,oBAAoB,CA0C9B,CAAC"}
@@ -283,6 +283,36 @@ export const query_account_has_active_global_role = async (deps, account_id, rol
283
283
  ) AS exists`, [account_id, role]);
284
284
  return row?.exists ?? false;
285
285
  };
286
+ /**
287
+ * Actor-grain check: does `actor_id` hold an active **global** role_grant for
288
+ * `role`, with the actor and its account both active (`deleted_at IS NULL`)?
289
+ *
290
+ * The live read an authorizer makes when it must not trust the role grants
291
+ * the dispatcher loaded for the request — a room authorizer reads inside its
292
+ * reserve window (`actions/room_actions.ts`). Keyed on the acting actor, not
293
+ * the account: another actor of the same account holding the role doesn't
294
+ * count. Twin of the Rust `query_active_actor_holds_any_global_role` for one
295
+ * role.
296
+ *
297
+ * @param deps - query dependencies
298
+ * @param actor_id - the actor to check
299
+ * @param role - the role to check for (e.g. `ROLE_ADMIN`)
300
+ * @returns `true` if the actor and its account are active and the actor holds an active global `role` grant
301
+ */
302
+ export const query_actor_has_active_global_role = async (deps, actor_id, role) => {
303
+ const row = await deps.db.query_one(`SELECT EXISTS(
304
+ SELECT 1 FROM role_grant rg
305
+ JOIN actor act ON act.id = rg.actor_id
306
+ JOIN account a ON a.id = act.account_id
307
+ WHERE act.id = $1
308
+ AND act.deleted_at IS NULL
309
+ AND a.deleted_at IS NULL
310
+ AND rg.role = $2
311
+ AND rg.scope_id IS NULL
312
+ AND ${role_grant_active_sql('rg')}
313
+ ) AS exists`, [actor_id, role]);
314
+ return row?.exists ?? false;
315
+ };
286
316
  /**
287
317
  * Count **active** accounts (`deleted_at IS NULL`) holding an active global
288
318
  * role_grant for `role`, counting only grants on **active actors**
@@ -0,0 +1,102 @@
1
+ /**
2
+ * A full-mesh call over one room: `RtcMesh` keeps an `RtcPeer` to every other
3
+ * member of the room while the caller holds a seat in it, carrying the peers'
4
+ * signals as room payloads (`rtc/rtc_signal.ts`) and fanning the local tracks
5
+ * out to every peer.
6
+ *
7
+ * The room is any `RtcMeshRoom` — `RoomClient`'s `RoomState` is one. The mesh
8
+ * follows its seat: when a seat is taken it connects to each member the join
9
+ * answered, then to each member who joins after; a member who leaves has its
10
+ * peer closed; when the seat ends (left, lost, or the socket closed) every
11
+ * peer closes, and a seat taken again (a rejoin after a reconnect, with a new
12
+ * member id) connects afresh. The local tracks outlive the seats: each new
13
+ * peer starts with them.
14
+ *
15
+ * Only the `mesh` topology is connected: a seat whose join answers another
16
+ * one sets `error` and connects nothing, since an SFU member needs a
17
+ * different client. A peer that can't be made (`new RTCPeerConnection`
18
+ * refusing a malformed ICE server, say) sets `error` too, and the mesh
19
+ * carries on without it.
20
+ *
21
+ * A connection serving several actors hears each room message once, whoever
22
+ * it is for, so a message addressed to another member is not this mesh's
23
+ * and is dropped.
24
+ *
25
+ * ## Sends, one at a time per peer
26
+ *
27
+ * The server dispatches a socket's requests concurrently, so two `room_send`
28
+ * requests can relay out of order — a candidate ahead of the offer it belongs
29
+ * to. Each peer's signals therefore go through one chain: a send waits for the
30
+ * previous one's answer. Peers don't wait on each other.
31
+ *
32
+ * ## ICE servers
33
+ *
34
+ * `ice_servers` is a list, or a function of the seat, so servers the join
35
+ * answer carries in its `extra` (short-lived TURN credentials, minted per
36
+ * join) can be read there.
37
+ *
38
+ * @module
39
+ */
40
+ import { SvelteMap } from 'svelte/reactivity';
41
+ import type { MemberId, RoomMember } from '../actions/room_action_specs.js';
42
+ import type { RoomListener, RoomRpcResult, RoomSeat } from '../actions/room_client.svelte.js';
43
+ import { RtcPeer, type RtcPeerDeps, type RtcSlot } from './rtc_peer.svelte.js';
44
+ /** What the mesh needs of a room — `RoomState` satisfies it. */
45
+ export interface RtcMeshRoom {
46
+ /** The caller's seat, `null` while it holds none. */
47
+ readonly seat: RoomSeat | null;
48
+ /** The room's members, the caller's own seat included. */
49
+ readonly members: ReadonlyArray<RoomMember>;
50
+ /** Subscribe to the room's events; returns the remover. */
51
+ add_listener: (listener: RoomListener) => () => void;
52
+ /** Relay a payload to one member. */
53
+ send: (to: MemberId, payload: string) => Promise<RoomRpcResult<null>>;
54
+ }
55
+ /** Options for `RtcMesh`. */
56
+ export interface RtcMeshOptions {
57
+ room: RtcMeshRoom;
58
+ /**
59
+ * The media slots every peer carries, the same list on every member's end.
60
+ *
61
+ * @default RTC_VOICE_SLOTS
62
+ */
63
+ slots?: ReadonlyArray<RtcSlot>;
64
+ /** The ICE servers, or a function of the seat that reads them (from its `extra`, say). */
65
+ ice_servers?: ReadonlyArray<RTCIceServer> | ((seat: RoomSeat) => ReadonlyArray<RTCIceServer>);
66
+ /** See `RtcPeerOptions.ice_disconnected_restart_ms`. */
67
+ ice_disconnected_restart_ms?: number | null;
68
+ }
69
+ /** The peers of a full-mesh call over one room. See the module doc. */
70
+ export declare class RtcMesh {
71
+ #private;
72
+ readonly slots: ReadonlyArray<RtcSlot>;
73
+ /** A peer for each other member while seated, by member id. */
74
+ readonly peers: SvelteMap<MemberId, RtcPeer>;
75
+ /** The seat's member id while connected, else `null`. */
76
+ local_member_id: MemberId | null;
77
+ /**
78
+ * Why the mesh connects nothing (an unsupported topology), or the last peer
79
+ * that couldn't be made, else `null`; cleared by the next seat.
80
+ */
81
+ error: string | null;
82
+ /** Whether `close` was called. */
83
+ closed: boolean;
84
+ constructor(deps: RtcPeerDeps, options: RtcMeshOptions);
85
+ /**
86
+ * Send `track` in `slot` to every peer, and to each peer made later; `null`
87
+ * sends nothing there. No renegotiation: each peer replaces its slot's track.
88
+ *
89
+ * @param slot - the slot's name
90
+ * @param track - the track, of the slot's kind, or `null`
91
+ * @throws Error when no slot has that name
92
+ */
93
+ set_track(slot: string, track: MediaStreamTrack | null): Promise<void>;
94
+ /**
95
+ * Close every peer and stop following the room. The local tracks are the
96
+ * caller's and stay live.
97
+ *
98
+ * @mutates this - sets `closed`, empties `peers`
99
+ */
100
+ close(): void;
101
+ }
102
+ //# sourceMappingURL=rtc_mesh.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtc_mesh.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/rtc/rtc_mesh.svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAqB,MAAM,iCAAiC,CAAC;AAC/F,OAAO,KAAK,EACX,YAAY,EACZ,aAAa,EACb,QA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,CAAqB;gBAUxB,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc;IAmBtD;;;;;;;OAOG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5E;;;;;OAKG;IACH,KAAK,IAAI,IAAI;CA8Hb"}
@@ -0,0 +1,232 @@
1
+ /**
2
+ * A full-mesh call over one room: `RtcMesh` keeps an `RtcPeer` to every other
3
+ * member of the room while the caller holds a seat in it, carrying the peers'
4
+ * signals as room payloads (`rtc/rtc_signal.ts`) and fanning the local tracks
5
+ * out to every peer.
6
+ *
7
+ * The room is any `RtcMeshRoom` — `RoomClient`'s `RoomState` is one. The mesh
8
+ * follows its seat: when a seat is taken it connects to each member the join
9
+ * answered, then to each member who joins after; a member who leaves has its
10
+ * peer closed; when the seat ends (left, lost, or the socket closed) every
11
+ * peer closes, and a seat taken again (a rejoin after a reconnect, with a new
12
+ * member id) connects afresh. The local tracks outlive the seats: each new
13
+ * peer starts with them.
14
+ *
15
+ * Only the `mesh` topology is connected: a seat whose join answers another
16
+ * one sets `error` and connects nothing, since an SFU member needs a
17
+ * different client. A peer that can't be made (`new RTCPeerConnection`
18
+ * refusing a malformed ICE server, say) sets `error` too, and the mesh
19
+ * carries on without it.
20
+ *
21
+ * A connection serving several actors hears each room message once, whoever
22
+ * it is for, so a message addressed to another member is not this mesh's
23
+ * and is dropped.
24
+ *
25
+ * ## Sends, one at a time per peer
26
+ *
27
+ * The server dispatches a socket's requests concurrently, so two `room_send`
28
+ * requests can relay out of order — a candidate ahead of the offer it belongs
29
+ * to. Each peer's signals therefore go through one chain: a send waits for the
30
+ * previous one's answer. Peers don't wait on each other.
31
+ *
32
+ * ## ICE servers
33
+ *
34
+ * `ice_servers` is a list, or a function of the seat, so servers the join
35
+ * answer carries in its `extra` (short-lived TURN credentials, minted per
36
+ * join) can be read there.
37
+ *
38
+ * @module
39
+ */
40
+ import { untrack } from 'svelte';
41
+ import { SvelteMap } from 'svelte/reactivity';
42
+ import { to_error_message } from '@fuzdev/fuz_util/error.ts';
43
+ import { decode_rtc_signal, encode_rtc_signal } from './rtc_signal.js';
44
+ import { RTC_VOICE_SLOTS, RtcPeer, rtc_peer_is_polite } from './rtc_peer.svelte.js';
45
+ /** The peers of a full-mesh call over one room. See the module doc. */
46
+ export class RtcMesh {
47
+ slots;
48
+ /** A peer for each other member while seated, by member id. */
49
+ peers = new SvelteMap();
50
+ /** The seat's member id while connected, else `null`. */
51
+ local_member_id = $state.raw(null);
52
+ /**
53
+ * Why the mesh connects nothing (an unsupported topology), or the last peer
54
+ * that couldn't be made, else `null`; cleared by the next seat.
55
+ */
56
+ error = $state.raw(null);
57
+ /** Whether `close` was called. */
58
+ closed = $state.raw(false);
59
+ #deps;
60
+ #room;
61
+ #options;
62
+ #remove_listener;
63
+ #local_tracks = new Map();
64
+ #send_chains = new Map();
65
+ #ice_servers = [];
66
+ constructor(deps, options) {
67
+ this.#deps = deps;
68
+ this.#room = options.room;
69
+ this.#options = options;
70
+ this.slots = options.slots ?? RTC_VOICE_SLOTS;
71
+ this.#remove_listener = this.#room.add_listener({
72
+ seated: (seat) => this.#start(seat),
73
+ unseated: (seat, reason) => this.#stop(seat, reason),
74
+ member_joined: (member) => this.#add_peer(member.member_id),
75
+ member_left: (member_id) => this.#remove_peer(member_id),
76
+ message: (message) => this.#receive(message)
77
+ });
78
+ // untracked, so an `$effect` that makes the mesh doesn't depend on the room's seat or members
79
+ untrack(() => {
80
+ const { seat } = this.#room;
81
+ if (seat)
82
+ this.#start(seat);
83
+ });
84
+ }
85
+ /**
86
+ * Send `track` in `slot` to every peer, and to each peer made later; `null`
87
+ * sends nothing there. No renegotiation: each peer replaces its slot's track.
88
+ *
89
+ * @param slot - the slot's name
90
+ * @param track - the track, of the slot's kind, or `null`
91
+ * @throws Error when no slot has that name
92
+ */
93
+ async set_track(slot, track) {
94
+ if (!this.slots.some((s) => s.name === slot)) {
95
+ throw new Error(`RtcMesh: no slot named '${slot}'`);
96
+ }
97
+ this.#local_tracks.set(slot, track);
98
+ // untracked, peers and their own state both, so an `$effect` that sets a
99
+ // track doesn't re-run when a peer comes or goes
100
+ await untrack(() => Promise.all([...this.peers.values()].map((peer) => this.#set_peer_track(peer, slot, track))));
101
+ }
102
+ /**
103
+ * Close every peer and stop following the room. The local tracks are the
104
+ * caller's and stay live.
105
+ *
106
+ * @mutates this - sets `closed`, empties `peers`
107
+ */
108
+ close() {
109
+ if (this.closed)
110
+ return;
111
+ this.closed = true;
112
+ this.#remove_listener();
113
+ this.#close_peers();
114
+ this.local_member_id = null;
115
+ }
116
+ #start(seat) {
117
+ if (this.closed)
118
+ return;
119
+ this.#close_peers();
120
+ this.local_member_id = null;
121
+ if (seat.topology !== 'mesh') {
122
+ this.error = `unsupported room topology '${seat.topology}': RtcMesh connects only 'mesh' rooms`;
123
+ return;
124
+ }
125
+ this.error = null;
126
+ const { ice_servers } = this.#options;
127
+ try {
128
+ this.#ice_servers =
129
+ typeof ice_servers === 'function' ? ice_servers(seat) : (ice_servers ?? []);
130
+ }
131
+ catch (error) {
132
+ this.#set_error(`the ICE servers couldn't be read: ${to_error_message(error)}`, error);
133
+ return;
134
+ }
135
+ this.local_member_id = seat.member_id;
136
+ for (const member of this.#room.members)
137
+ this.#add_peer(member.member_id);
138
+ }
139
+ #stop(seat, reason) {
140
+ if (seat.member_id !== this.local_member_id)
141
+ return;
142
+ this.#deps.log?.debug('[rtc_mesh] seat ended:', reason);
143
+ this.#close_peers();
144
+ this.local_member_id = null;
145
+ }
146
+ #add_peer(member_id) {
147
+ const local = this.local_member_id;
148
+ if (this.closed || local === null || member_id === local || this.peers.has(member_id))
149
+ return;
150
+ let peer;
151
+ try {
152
+ peer = new RtcPeer(this.#deps, {
153
+ remote_member_id: member_id,
154
+ polite: rtc_peer_is_polite(local, member_id),
155
+ slots: this.slots,
156
+ ice_servers: this.#ice_servers,
157
+ ice_disconnected_restart_ms: this.#options.ice_disconnected_restart_ms,
158
+ send: (signal) => this.#send(peer, signal)
159
+ });
160
+ }
161
+ catch (error) {
162
+ this.#set_error(`a peer for ${member_id} couldn't be made: ${to_error_message(error)}`, error);
163
+ return;
164
+ }
165
+ this.peers.set(member_id, peer);
166
+ for (const [slot, track] of this.#local_tracks) {
167
+ if (track)
168
+ void this.#set_peer_track(peer, slot, track);
169
+ }
170
+ }
171
+ /** Set one peer's track, logging a failed `replaceTrack` rather than throwing. */
172
+ #set_peer_track(peer, slot, track) {
173
+ return peer.set_track(slot, track).catch((error) => {
174
+ this.#deps.log?.warn('[rtc_mesh] replaceTrack failed:', peer.remote_member_id, error);
175
+ });
176
+ }
177
+ #remove_peer(member_id) {
178
+ const peer = this.peers.get(member_id);
179
+ if (!peer)
180
+ return;
181
+ this.peers.delete(member_id);
182
+ this.#send_chains.delete(member_id);
183
+ peer.close();
184
+ }
185
+ #close_peers() {
186
+ for (const peer of this.peers.values())
187
+ peer.close();
188
+ this.peers.clear();
189
+ this.#send_chains.clear();
190
+ }
191
+ /** Queue a signal behind the peer's previous send, dropped once the peer is gone. */
192
+ #send(peer, signal) {
193
+ const member_id = peer.remote_member_id;
194
+ const payload = encode_rtc_signal(signal);
195
+ const previous = this.#send_chains.get(member_id) ?? Promise.resolve();
196
+ const next = previous.then(async () => {
197
+ if (this.peers.get(member_id) !== peer)
198
+ return;
199
+ const result = await this.#room.send(member_id, payload);
200
+ if (!result.ok && this.peers.get(member_id) === peer) {
201
+ this.#deps.log?.warn('[rtc_mesh] signal send refused:', member_id, result.error);
202
+ }
203
+ });
204
+ this.#send_chains.set(member_id, next.catch((error) => {
205
+ this.#deps.log?.error('[rtc_mesh] signal send failed:', member_id, error);
206
+ }));
207
+ }
208
+ #set_error(message, error) {
209
+ this.error = message;
210
+ this.#deps.log?.error('[rtc_mesh]', message, error);
211
+ }
212
+ #receive(message) {
213
+ if (this.local_member_id === null)
214
+ return;
215
+ // another actor's seat on the same connection
216
+ if (message.to !== null && message.to !== this.local_member_id)
217
+ return;
218
+ const decoded = decode_rtc_signal(message.payload);
219
+ if (!decoded.ok) {
220
+ if (decoded.reason !== 'not_rtc_signal') {
221
+ this.#deps.log?.warn('[rtc_mesh] signal refused:', message.from, decoded.reason);
222
+ }
223
+ return;
224
+ }
225
+ const peer = this.peers.get(message.from);
226
+ if (!peer) {
227
+ this.#deps.log?.debug('[rtc_mesh] signal from a member with no peer:', message.from);
228
+ return;
229
+ }
230
+ void peer.on_signal(decoded.value);
231
+ }
232
+ }
@@ -0,0 +1,180 @@
1
+ /**
2
+ * One WebRTC connection to one remote member: `RtcPeer`, over an injected
3
+ * `RTCPeerConnection`, exchanging signals through a `send` function and an
4
+ * `on_signal` entry rather than any transport, so two peers cross-wire in a
5
+ * test and a room carries them in the app (`rtc/rtc_mesh.svelte.ts`).
6
+ *
7
+ * ## Perfect negotiation
8
+ *
9
+ * Either end may need to renegotiate at any time (an ICE restart, say), so the
10
+ * two follow the perfect negotiation pattern: each sends an offer whenever its
11
+ * connection says negotiation is needed, and when two offers cross, the
12
+ * **polite** end rolls its own back and answers the other's, while the
13
+ * **impolite** end ignores the offer it receives. Which end is polite is a
14
+ * pure function of the two member ids (`rtc_peer_is_polite`), so both agree
15
+ * without a word: the lower id is polite.
16
+ *
17
+ * Candidates that arrive before the remote description is set are queued and
18
+ * added once it is — a candidate is meaningless without one, and the
19
+ * connection refuses it. Candidates that arrive while the impolite end is
20
+ * ignoring an offer may belong to it and fail to add, queued or not; that
21
+ * failure is expected and dropped.
22
+ *
23
+ * Inbound signals are handled one at a time, in the order they arrive. A
24
+ * caller that delivers them over a channel that can reorder (concurrently
25
+ * dispatched requests) serializes its sends per peer, as `RtcMesh` does.
26
+ * Since no signal is handled while another's remote answer is being applied,
27
+ * the standard pattern's "setting a remote answer" flag would never read true
28
+ * here, and there is none.
29
+ *
30
+ * Once `close` is called, nothing more reaches the connection, and a failure
31
+ * of work in flight at the close is expected and not recorded.
32
+ *
33
+ * ## Fixed transceiver slots
34
+ *
35
+ * The media a peer carries is a fixed list of slots (`RtcSlot`), each one
36
+ * `sendrecv` transceiver of one kind: `RTC_VOICE_SLOTS` is the microphone's
37
+ * audio; camera, screen, and screen audio are further slots of the same shape,
38
+ * added to the list when they land. Every slot exists from the start, so
39
+ * turning a source on or off is `set_track` — a `replaceTrack` on the slot's
40
+ * sender, with no renegotiation — and a slot with no track sends nothing.
41
+ *
42
+ * The impolite end creates the transceivers, in slot order, and its first
43
+ * offer carries them; the polite end adopts the transceivers that offer
44
+ * creates on its side, by position, sets them `sendrecv`, and answers. Both
45
+ * ends creating their own would give each side two transceivers per slot,
46
+ * since a transceiver made by `addTransceiver` is never matched to a remote
47
+ * offer's media section. So both ends must use the same slot list.
48
+ *
49
+ * Two ends whose lists differ degrade rather than fail: a slot the offer has
50
+ * no media section for stays empty (no transceiver, its track kept unsent), a
51
+ * media section past the polite end's slots stays `recvonly` and unnamed, and
52
+ * a section whose kind differs from its slot's is logged and skipped, that
53
+ * slot staying empty. The slot list is protocol: changing its shape (the
54
+ * slots, their order, or their kinds) bumps `RTC_SIGNAL_VERSION`
55
+ * (`rtc/rtc_signal.ts`), so mismatched ends refuse each other's signals
56
+ * instead of degrading.
57
+ *
58
+ * Remote media is `remote_tracks`, by slot name: the receiver's track for each
59
+ * slot once the far end's description reaches it (muted while the far end
60
+ * sends nothing on it).
61
+ *
62
+ * ## ICE restart
63
+ *
64
+ * When ICE fails, the peer restarts it (`restartIce`, which renegotiates with
65
+ * new credentials through the same pattern). A connection that stays
66
+ * `disconnected` past `ice_disconnected_restart_ms` is restarted too, since a
67
+ * disconnect is often a network change that ICE alone won't recover from.
68
+ *
69
+ * @module
70
+ */
71
+ import type { Logger } from '@fuzdev/fuz_util/log.ts';
72
+ import type { MemberId } from '../actions/room_action_specs.js';
73
+ import type { RtcSignal } from './rtc_signal.js';
74
+ /** One media slot of a peer connection: a name, and the kind of track it carries. */
75
+ export interface RtcSlot {
76
+ name: string;
77
+ kind: 'audio' | 'video';
78
+ }
79
+ /**
80
+ * The slots of a voice call: the microphone's audio. A call with video adds
81
+ * slots after it (camera, screen, screen audio), in an order both ends share.
82
+ */
83
+ export declare const RTC_VOICE_SLOTS: ReadonlyArray<RtcSlot>;
84
+ /**
85
+ * Default `RtcPeerOptions.ice_disconnected_restart_ms`: long enough for a
86
+ * brief network blip to recover on its own.
87
+ */
88
+ export declare const RTC_ICE_DISCONNECTED_RESTART_MS = 5000;
89
+ /**
90
+ * Whether the local end is the polite one of a pair: the lower member id is
91
+ * polite. Both ends compute it alike, so they always disagree on who yields.
92
+ *
93
+ * @param local_member_id - this end's member id
94
+ * @param remote_member_id - the far end's
95
+ * @returns whether this end yields when offers cross
96
+ */
97
+ export declare const rtc_peer_is_polite: (local_member_id: MemberId, remote_member_id: MemberId) => boolean;
98
+ /** The side effects a peer runs on. */
99
+ export interface RtcPeerDeps {
100
+ /** `new RTCPeerConnection(configuration)`. */
101
+ create_peer_connection: (configuration: RTCConfiguration) => RTCPeerConnection;
102
+ /** `setTimeout`. */
103
+ set_timeout: (callback: () => void, ms: number) => unknown;
104
+ /** `clearTimeout`, given what `set_timeout` returned. */
105
+ clear_timeout: (handle: unknown) => void;
106
+ /** Where negotiation diagnostics go; `null` or omitted, nowhere. */
107
+ log?: Logger | null;
108
+ }
109
+ /** `RtcPeerDeps` over the browser's own globals, each read when it's called. */
110
+ export declare const create_rtc_peer_deps: (log?: Logger | null) => RtcPeerDeps;
111
+ /** Options for `RtcPeer`. */
112
+ export interface RtcPeerOptions {
113
+ /** The far end's member id. */
114
+ remote_member_id: MemberId;
115
+ /** Whether this end yields when offers cross — `rtc_peer_is_polite`. */
116
+ polite: boolean;
117
+ /** The media slots, the same list on both ends. */
118
+ slots?: ReadonlyArray<RtcSlot>;
119
+ /** The ICE servers (STUN, TURN); none, host candidates only. */
120
+ ice_servers?: ReadonlyArray<RTCIceServer>;
121
+ /**
122
+ * Deliver a signal to the far end's `on_signal`, in the order given. Called
123
+ * synchronously; it must not throw.
124
+ */
125
+ send: (signal: RtcSignal) => void;
126
+ /**
127
+ * How long ICE may stay `disconnected` before the peer restarts it; `null`
128
+ * restarts only on `failed`.
129
+ *
130
+ * @default RTC_ICE_DISCONNECTED_RESTART_MS
131
+ */
132
+ ice_disconnected_restart_ms?: number | null;
133
+ }
134
+ /** One connection to one remote member. See the module doc. */
135
+ export declare class RtcPeer {
136
+ #private;
137
+ readonly remote_member_id: MemberId;
138
+ readonly polite: boolean;
139
+ readonly slots: ReadonlyArray<RtcSlot>;
140
+ /** The connection's `connectionState`. */
141
+ connection_state: RTCPeerConnectionState;
142
+ /** The connection's `iceConnectionState`. */
143
+ ice_connection_state: RTCIceConnectionState;
144
+ /** The connection's `signalingState`. */
145
+ signaling_state: RTCSignalingState;
146
+ /** The far end's track for each slot, by slot name, `null` until its description reaches it. */
147
+ remote_tracks: Readonly<Record<string, MediaStreamTrack | null>>;
148
+ /** Whether `close` was called. */
149
+ closed: boolean;
150
+ /** The last negotiation failure, for diagnostics. */
151
+ last_error: string | null;
152
+ constructor(deps: RtcPeerDeps, options: RtcPeerOptions);
153
+ /**
154
+ * Take a signal from the far end. Signals are handled one at a time, in
155
+ * call order; a failure is logged and kept in `last_error`, never thrown.
156
+ *
157
+ * @returns resolves once this signal is handled
158
+ */
159
+ on_signal(signal: RtcSignal): Promise<void>;
160
+ /**
161
+ * Send `track` in `slot` (`null` sends nothing) — a `replaceTrack`, never a
162
+ * renegotiation. On the polite end before the first offer, the track is
163
+ * kept and sent once the slot's transceiver arrives.
164
+ *
165
+ * @param slot - the slot's name
166
+ * @param track - the track, of the slot's kind, or `null`
167
+ * @throws Error when no slot has that name
168
+ */
169
+ set_track(slot: string, track: MediaStreamTrack | null): Promise<void>;
170
+ /** Restart ICE: a renegotiation with new credentials. */
171
+ restart_ice(): void;
172
+ /**
173
+ * Close the connection. Idempotent; local tracks are the caller's and stay
174
+ * live.
175
+ *
176
+ * @mutates this - sets `closed`, clears `remote_tracks`
177
+ */
178
+ close(): void;
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