@net-mesh/browser 0.37.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 (110) hide show
  1. package/CHANGELOG.md +517 -0
  2. package/LICENSE-APACHE +190 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +666 -0
  5. package/dist/async-queue.d.ts +26 -0
  6. package/dist/async-queue.js +62 -0
  7. package/dist/credential.d.ts +70 -0
  8. package/dist/credential.js +95 -0
  9. package/dist/errors.d.ts +400 -0
  10. package/dist/errors.js +726 -0
  11. package/dist/events.d.ts +232 -0
  12. package/dist/events.js +298 -0
  13. package/dist/identity.d.ts +40 -0
  14. package/dist/identity.js +78 -0
  15. package/dist/index.bundle.js +2 -0
  16. package/dist/index.d.ts +38 -0
  17. package/dist/index.js +46 -0
  18. package/dist/leader/events.d.ts +111 -0
  19. package/dist/leader/events.js +116 -0
  20. package/dist/leader/index.d.ts +14 -0
  21. package/dist/leader/index.js +11 -0
  22. package/dist/leader/session.d.ts +539 -0
  23. package/dist/leader/session.js +770 -0
  24. package/dist/leader/wasm.d.ts +123 -0
  25. package/dist/leader/wasm.js +39 -0
  26. package/dist/lobby.d.ts +183 -0
  27. package/dist/lobby.js +504 -0
  28. package/dist/local.d.ts +80 -0
  29. package/dist/local.js +160 -0
  30. package/dist/net_leaf.d.ts +1494 -0
  31. package/dist/net_leaf.js +3753 -0
  32. package/dist/net_leaf_bg.wasm +0 -0
  33. package/dist/net_leaf_bg.wasm.d.ts +137 -0
  34. package/dist/netcode/client.d.ts +102 -0
  35. package/dist/netcode/client.js +296 -0
  36. package/dist/netcode/clock.d.ts +45 -0
  37. package/dist/netcode/clock.js +54 -0
  38. package/dist/netcode/host.d.ts +118 -0
  39. package/dist/netcode/host.js +276 -0
  40. package/dist/netcode/index.d.ts +19 -0
  41. package/dist/netcode/index.js +14 -0
  42. package/dist/netcode/interpolate.d.ts +50 -0
  43. package/dist/netcode/interpolate.js +100 -0
  44. package/dist/netcode/wire.d.ts +125 -0
  45. package/dist/netcode/wire.js +117 -0
  46. package/dist/node.d.ts +908 -0
  47. package/dist/node.js +1085 -0
  48. package/dist/org.d.ts +412 -0
  49. package/dist/org.js +567 -0
  50. package/dist/peer-driver.d.ts +117 -0
  51. package/dist/peer-driver.js +224 -0
  52. package/dist/store/assembly.d.ts +176 -0
  53. package/dist/store/assembly.js +325 -0
  54. package/dist/store/chunker.d.ts +83 -0
  55. package/dist/store/chunker.js +190 -0
  56. package/dist/store/core.d.ts +136 -0
  57. package/dist/store/core.js +477 -0
  58. package/dist/store/definition.d.ts +23 -0
  59. package/dist/store/definition.js +83 -0
  60. package/dist/store/errors.d.ts +77 -0
  61. package/dist/store/errors.js +94 -0
  62. package/dist/store/host.d.ts +247 -0
  63. package/dist/store/host.js +675 -0
  64. package/dist/store/index.d.ts +50 -0
  65. package/dist/store/index.js +40 -0
  66. package/dist/store/interest.d.ts +40 -0
  67. package/dist/store/interest.js +77 -0
  68. package/dist/store/inventory.d.ts +81 -0
  69. package/dist/store/inventory.js +140 -0
  70. package/dist/store/join.d.ts +118 -0
  71. package/dist/store/join.js +724 -0
  72. package/dist/store/json.d.ts +50 -0
  73. package/dist/store/json.js +283 -0
  74. package/dist/store/ledger.d.ts +187 -0
  75. package/dist/store/ledger.js +292 -0
  76. package/dist/store/owner.d.ts +616 -0
  77. package/dist/store/owner.js +1711 -0
  78. package/dist/store/patch.d.ts +70 -0
  79. package/dist/store/patch.js +166 -0
  80. package/dist/store/player.d.ts +65 -0
  81. package/dist/store/player.js +261 -0
  82. package/dist/store/replica.d.ts +187 -0
  83. package/dist/store/replica.js +740 -0
  84. package/dist/store/state.d.ts +42 -0
  85. package/dist/store/state.js +165 -0
  86. package/dist/store/types.d.ts +200 -0
  87. package/dist/store/types.js +25 -0
  88. package/dist/store/visibility.d.ts +118 -0
  89. package/dist/store/visibility.js +282 -0
  90. package/dist/store/wire.d.ts +309 -0
  91. package/dist/store/wire.js +834 -0
  92. package/dist/stream.d.ts +174 -0
  93. package/dist/stream.js +238 -0
  94. package/dist/three/index.d.ts +109 -0
  95. package/dist/three/index.js +130 -0
  96. package/dist/udp-probe.d.ts +159 -0
  97. package/dist/udp-probe.js +245 -0
  98. package/dist/wasm.d.ts +642 -0
  99. package/dist/wasm.js +98 -0
  100. package/dist/world/border.d.ts +84 -0
  101. package/dist/world/border.js +99 -0
  102. package/dist/world/handoff.d.ts +187 -0
  103. package/dist/world/handoff.js +222 -0
  104. package/dist/world/index.d.ts +13 -0
  105. package/dist/world/index.js +9 -0
  106. package/dist/world/link.d.ts +179 -0
  107. package/dist/world/link.js +476 -0
  108. package/dist/world/regions.d.ts +154 -0
  109. package/dist/world/regions.js +314 -0
  110. package/package.json +72 -0
@@ -0,0 +1,3753 @@
1
+ /* @ts-self-types="./net_leaf.d.ts" */
2
+
3
+ /**
4
+ * A browser node.
5
+ */
6
+ export class LeafNode {
7
+ static __wrap(ptr) {
8
+ const obj = Object.create(LeafNode.prototype);
9
+ obj.__wbg_ptr = ptr;
10
+ LeafNodeFinalization.register(obj, obj.__wbg_ptr, obj);
11
+ return obj;
12
+ }
13
+ __destroy_into_raw() {
14
+ const ptr = this.__wbg_ptr;
15
+ this.__wbg_ptr = 0;
16
+ LeafNodeFinalization.unregister(this);
17
+ return ptr;
18
+ }
19
+ free() {
20
+ const ptr = this.__destroy_into_raw();
21
+ wasm.__wbg_leafnode_free(ptr, 0);
22
+ }
23
+ /**
24
+ * The anchor's node id, as 16 lowercase hex digits.
25
+ * @returns {string}
26
+ */
27
+ anchor_id_hex() {
28
+ let deferred1_0;
29
+ let deferred1_1;
30
+ try {
31
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
32
+ wasm.leafnode_anchor_id_hex(retptr, this.__wbg_ptr);
33
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
34
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
35
+ deferred1_0 = r0;
36
+ deferred1_1 = r1;
37
+ return getStringFromWasm0(r0, r1);
38
+ } finally {
39
+ wasm.__wbindgen_add_to_stack_pointer(16);
40
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
41
+ }
42
+ }
43
+ /**
44
+ * Build, sign and publish this leaf's announcement.
45
+ *
46
+ * `capabilities` become tags alongside the mandatory `leaf` and
47
+ * `transport:rtc`; `reflex_addr` and `rtc_addr` stay absent.
48
+ * @param {string[]} capabilities
49
+ * @returns {Promise<void>}
50
+ */
51
+ announce(capabilities) {
52
+ const ptr0 = passArrayJsValueToWasm0(capabilities, wasm.__wbindgen_export);
53
+ const len0 = WASM_VECTOR_LEN;
54
+ const ret = wasm.leafnode_announce(this.__wbg_ptr, ptr0, len0);
55
+ return takeObject(ret);
56
+ }
57
+ /**
58
+ * Apply one signed revocation bundle from the control-plane
59
+ * feed, and say how many floors it raised.
60
+ *
61
+ * The landing point of the revocation feed: signed
62
+ * `OrgRevocationBundle` wire bytes, verified **in-leaf** by the
63
+ * node's own org authority before any floor moves. This is
64
+ * never a trust-the-JS setter — a forged bundle is refused here
65
+ * exactly as it is refused on the carrier's other paths — and
66
+ * the raise-only merge means an old but validly signed bundle
67
+ * can never roll floors back.
68
+ * @param {string} bundle_hex
69
+ * @returns {number}
70
+ */
71
+ apply_org_revocation_bundle(bundle_hex) {
72
+ try {
73
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
74
+ const ptr0 = passStringToWasm0(bundle_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
75
+ const len0 = WASM_VECTOR_LEN;
76
+ wasm.leafnode_apply_org_revocation_bundle(retptr, this.__wbg_ptr, ptr0, len0);
77
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
78
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
79
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
80
+ if (r2) {
81
+ throw takeObject(r1);
82
+ }
83
+ return r0 >>> 0;
84
+ } finally {
85
+ wasm.__wbindgen_add_to_stack_pointer(16);
86
+ }
87
+ }
88
+ /**
89
+ * Arm the network-change re-attempt trigger.
90
+ *
91
+ * Installs the window's `online` listener; the ICE
92
+ * `disconnected` → `failed` watcher is already on every peer
93
+ * connection this transport owns. From here, either
94
+ * observation files a trigger and
95
+ * [`crate::retry::RetryPolicy`] decides — once per network
96
+ * change, per peer.
97
+ *
98
+ * # Why a page has to ask
99
+ *
100
+ * Re-dialling is policy, and policy is the application's. A
101
+ * library that re-offered on its own would take that decision
102
+ * away from a page that has a reason not to: one that is
103
+ * deliberately holding a pair on the routed path, one tearing
104
+ * down, one whose user is on a metered link. §9 step 6 makes
105
+ * the routed session a supported disposition rather than a
106
+ * degraded one, so "the pair is relayed" is not a fault this
107
+ * leaf may assume it should fix.
108
+ *
109
+ * **Idempotent.** A second call adds no second listener,
110
+ * because two listeners for one `online` event are two triggers
111
+ * for one network change — and while the owner would coalesce
112
+ * them, a page that armed twice should not be relying on that.
113
+ *
114
+ * Only pairs this leaf took direct **as the offerer** are
115
+ * re-attempted: §9 step 4 gives the offerer the initiating
116
+ * role, and both sides re-offering one network change is two
117
+ * attempts per pair plus a supersession race.
118
+ */
119
+ arm_network_retry() {
120
+ try {
121
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
122
+ wasm.leafnode_arm_network_retry(retptr, this.__wbg_ptr);
123
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
124
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
125
+ if (r1) {
126
+ throw takeObject(r0);
127
+ }
128
+ } finally {
129
+ wasm.__wbindgen_add_to_stack_pointer(16);
130
+ }
131
+ }
132
+ /**
133
+ * Call `service` on the anchor.
134
+ *
135
+ * Resolves to the reply body, or rejects with the typed
136
+ * failure — `Timeout`, `SessionLost`, `Refused(status)`. Never
137
+ * a silent retry.
138
+ * @param {string} service
139
+ * @param {Uint8Array} payload
140
+ * @param {number | null} [timeout_ms]
141
+ * @returns {Promise<Uint8Array>}
142
+ */
143
+ call(service, payload, timeout_ms) {
144
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
145
+ const len0 = WASM_VECTOR_LEN;
146
+ const ret = wasm.leafnode_call(this.__wbg_ptr, ptr0, len0, addHeapObject(payload), !isLikeNone(timeout_ms), isLikeNone(timeout_ms) ? 0 : timeout_ms);
147
+ return takeObject(ret);
148
+ }
149
+ /**
150
+ * One org-scoped unary call.
151
+ *
152
+ * The call runs the full admission (the org proof kinds and the
153
+ * session fence included) and resolves the response body.
154
+ * Opening refusal rejects `admission-denied` with its coarse
155
+ * reason (`rpc: refused (9): <coarse>`); a midstream revocation
156
+ * is the same denial as the terminal.
157
+ *
158
+ * The deadline is **absolute** and defaults to 300 s (`deadlineMs`
159
+ * absent is never "no deadline"); a frozen tab gets no lease
160
+ * extension and on wake an overdue call retires with its
161
+ * deadline terminal. Nothing here ever resumes a retired call —
162
+ * re-opening is a fresh call with a fresh proof and MAY repeat
163
+ * effects. Node or tab close retires ownership: pending calls
164
+ * fail typed.
165
+ * @param {string} service
166
+ * @param {Uint8Array} payload
167
+ * @param {any} opts
168
+ * @returns {Promise<Uint8Array>}
169
+ */
170
+ call_org(service, payload, opts) {
171
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
172
+ const len0 = WASM_VECTOR_LEN;
173
+ const ret = wasm.leafnode_call_org(this.__wbg_ptr, ptr0, len0, addHeapObject(payload), addHeapObject(opts));
174
+ return takeObject(ret);
175
+ }
176
+ /**
177
+ * One org-scoped client-streaming call. `send` pushes items,
178
+ * `finish` half-closes and resolves the response body. See
179
+ * [`Self::call_org`] for the deadline, suspension and closure
180
+ * contract.
181
+ * @param {string} service
182
+ * @param {any} opts
183
+ * @returns {Promise<OrgUploadCallHandle>}
184
+ */
185
+ call_org_client_stream(service, opts) {
186
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
187
+ const len0 = WASM_VECTOR_LEN;
188
+ const ret = wasm.leafnode_call_org_client_stream(this.__wbg_ptr, ptr0, len0, addHeapObject(opts));
189
+ return takeObject(ret);
190
+ }
191
+ /**
192
+ * One org-scoped duplex call. See [`Self::call_org`] for the
193
+ * deadline, suspension and closure contract.
194
+ * @param {string} service
195
+ * @param {any} opts
196
+ * @returns {Promise<OrgDuplexCallHandle>}
197
+ */
198
+ call_org_duplex(service, opts) {
199
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
200
+ const len0 = WASM_VECTOR_LEN;
201
+ const ret = wasm.leafnode_call_org_duplex(this.__wbg_ptr, ptr0, len0, addHeapObject(opts));
202
+ return takeObject(ret);
203
+ }
204
+ /**
205
+ * One org-scoped server-streaming call. See [`Self::call_org`]
206
+ * for the deadline, suspension and closure contract — it holds
207
+ * for every shape. The typed terminal error arrives as the
208
+ * stream's final `next()` item, and dropping/cancelling the
209
+ * handle emits exactly one CANCEL.
210
+ * @param {string} service
211
+ * @param {Uint8Array} payload
212
+ * @param {any} opts
213
+ * @returns {Promise<OrgByteStreamHandle>}
214
+ */
215
+ call_org_streaming(service, payload, opts) {
216
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
217
+ const len0 = WASM_VECTOR_LEN;
218
+ const ret = wasm.leafnode_call_org_streaming(this.__wbg_ptr, ptr0, len0, addHeapObject(payload), addHeapObject(opts));
219
+ return takeObject(ret);
220
+ }
221
+ /**
222
+ * Close the node: every session, every channel, every pending
223
+ * call.
224
+ *
225
+ * Pending calls fail `RpcError::SessionLost` — typed, and not
226
+ * re-issued by anybody.
227
+ */
228
+ close() {
229
+ wasm.leafnode_close(this.__wbg_ptr);
230
+ }
231
+ /**
232
+ * Bootstrap against an anchor and return a connected node.
233
+ *
234
+ * `opts`: `{ credentialB64, bootstrapUrl?, origin, iceServers? }`.
235
+ * `bootstrapUrl` overrides the credential's when present;
236
+ * everything else Layer 0 needs — the pinned anchor key, the
237
+ * PSK, the listener URL — comes from the credential itself.
238
+ *
239
+ * `iceServers` is optional and **defaults to the anchor's
240
+ * separately announced STUN endpoint** (the `stun_addr` field
241
+ * of `GET /rtc/anchor`), so the advertised configuration works
242
+ * without the page choosing a STUN service. An anchor that
243
+ * announced none leaves the connection with no ICE servers.
244
+ *
245
+ * A supplied `iceServers` is honoured verbatim, with one
246
+ * refusal: an entry naming this connection's peer RTC endpoint
247
+ * as its STUN server is
248
+ * [`LeafError::IceServerConflictsWithPeer`], returned before
249
+ * any ICE work. Detection is endpoint equality only; see
250
+ * [`crate::bootstrap::check_ice_servers_against_peer`].
251
+ * @param {any} opts
252
+ * @returns {Promise<LeafNode>}
253
+ */
254
+ static connect(opts) {
255
+ const ret = wasm.leafnode_connect(addHeapObject(opts));
256
+ return takeObject(ret);
257
+ }
258
+ /**
259
+ * Every counter, as JSON. u64s are decimal strings.
260
+ * @returns {string}
261
+ */
262
+ counters_json() {
263
+ let deferred1_0;
264
+ let deferred1_1;
265
+ try {
266
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
267
+ wasm.leafnode_counters_json(retptr, this.__wbg_ptr);
268
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
269
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
270
+ deferred1_0 = r0;
271
+ deferred1_1 = r1;
272
+ return getStringFromWasm0(r0, r1);
273
+ } finally {
274
+ wasm.__wbindgen_add_to_stack_pointer(16);
275
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
276
+ }
277
+ }
278
+ /**
279
+ * The ICE servers a `connect(opts)` with this options object
280
+ * would configure its `RTCPeerConnection` with, as JSON.
281
+ *
282
+ * Not a convenience: it is the only way for a caller — or a
283
+ * test — to see what the leaf made of the `RTCIceServer[]` it
284
+ * was handed *before* a connection attempt consumes it. Stage 5
285
+ * read those objects with `as_string`, so every one of them
286
+ * dropped and a page's STUN/TURN configuration was silently
287
+ * absent from the offer. Reads through exactly the parser
288
+ * [`Self::connect`] uses.
289
+ *
290
+ * Shape: `[{"urls":["stun:host:3478"],"username":"u",
291
+ * "credential":"c"}]`, `username`/`credential` present only
292
+ * when the entry carried them.
293
+ *
294
+ * It reports what the **caller** configured, so an options
295
+ * object with no `iceServers` reads `[]` here even though
296
+ * [`Self::connect`] will substitute the anchor's announced
297
+ * STUN endpoint: the substitute is not knowable without an
298
+ * anchor to ask, and inventing one would make this method lie
299
+ * about the only thing it can see.
300
+ * @param {any} opts
301
+ * @returns {string}
302
+ */
303
+ static effective_ice_servers(opts) {
304
+ let deferred2_0;
305
+ let deferred2_1;
306
+ try {
307
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
308
+ wasm.leafnode_effective_ice_servers(retptr, addHeapObject(opts));
309
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
310
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
311
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
312
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
313
+ var ptr1 = r0;
314
+ var len1 = r1;
315
+ if (r3) {
316
+ ptr1 = 0; len1 = 0;
317
+ throw takeObject(r2);
318
+ }
319
+ deferred2_0 = ptr1;
320
+ deferred2_1 = len1;
321
+ return getStringFromWasm0(ptr1, len1);
322
+ } finally {
323
+ wasm.__wbindgen_add_to_stack_pointer(16);
324
+ wasm.__wbindgen_export5(deferred2_0, deferred2_1, 1);
325
+ }
326
+ }
327
+ /**
328
+ * What an `open_stream(opts)` with this options object would
329
+ * actually ask the node for, as JSON — the same read, without
330
+ * the stream.
331
+ *
332
+ * Shape: `{"reliability":"reliable","label":"app",
333
+ * "streamId":"0000000000000009","channelHash":7,
334
+ * "peer":"00366d403ce19dac"}`, with `streamId` `null` when the
335
+ * caller did not pin one (the node allocates), `channelHash`
336
+ * `null` when absent, and `peer` `null` when the stream
337
+ * addresses the anchor.
338
+ * @param {any} opts
339
+ * @returns {string}
340
+ */
341
+ static effective_stream_options(opts) {
342
+ let deferred2_0;
343
+ let deferred2_1;
344
+ try {
345
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
346
+ wasm.leafnode_effective_stream_options(retptr, addHeapObject(opts));
347
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
348
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
349
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
350
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
351
+ var ptr1 = r0;
352
+ var len1 = r1;
353
+ if (r3) {
354
+ ptr1 = 0; len1 = 0;
355
+ throw takeObject(r2);
356
+ }
357
+ deferred2_0 = ptr1;
358
+ deferred2_1 = len1;
359
+ return getStringFromWasm0(ptr1, len1);
360
+ } finally {
361
+ wasm.__wbindgen_add_to_stack_pointer(16);
362
+ wasm.__wbindgen_export5(deferred2_0, deferred2_1, 1);
363
+ }
364
+ }
365
+ /**
366
+ * Run the enrollment exchange against the anchor.
367
+ *
368
+ * [`Self::connect`] awaits this already, so a page never needs
369
+ * it; it is here because "still provisional" and "the anchor
370
+ * was slow" are the same symptom from the outside — an nRPC
371
+ * timeout — and a harness needs to be able to drive and
372
+ * observe the step that distinguishes them.
373
+ *
374
+ * A refusal is typed and final: the invite is single-use, so
375
+ * nothing here retries. Retrying would burn it and turn a
376
+ * legible refusal into an illegible replay.
377
+ * @returns {Promise<void>}
378
+ */
379
+ enroll() {
380
+ const ret = wasm.leafnode_enroll(this.__wbg_ptr);
381
+ return takeObject(ret);
382
+ }
383
+ /**
384
+ * Whether the anchor has admitted this leaf.
385
+ *
386
+ * `false` after a successful handshake means the session is
387
+ * still provisional, which is the discriminator a harness needs
388
+ * when a call times out: §12 refused it, rather than the
389
+ * service being slow.
390
+ * @returns {boolean}
391
+ */
392
+ is_enrolled() {
393
+ const ret = wasm.leafnode_is_enrolled(this.__wbg_ptr);
394
+ return ret !== 0;
395
+ }
396
+ /**
397
+ * How many callbacks are registered on this node right now.
398
+ *
399
+ * **Observable so the bound can be asserted rather than
400
+ * inferred**, exactly as `Reassembler::outstanding` is. The
401
+ * property that matters is that repeated stream open/close
402
+ * leaves this flat: a registration that close does not remove
403
+ * is retained for the life of the node, keeps being invoked
404
+ * for every event, and keeps its captured consumer wrapper
405
+ * alive. A number nobody can read is a bound nobody can test.
406
+ * @returns {number}
407
+ */
408
+ listener_count() {
409
+ const ret = wasm.leafnode_listener_count(this.__wbg_ptr);
410
+ return ret >>> 0;
411
+ }
412
+ /**
413
+ * The largest payload one packet carries, as the wire defines
414
+ * it: `MAX_PAYLOAD_SIZE` minus the event frame's length prefix.
415
+ *
416
+ * Published because an application that must keep a message
417
+ * inside one packet has no other way to learn the number, and
418
+ * the two wrong ways are both reachable: hardcoding 8 108
419
+ * treats the packet cap as available data bytes and overruns by
420
+ * the prefix, and hardcoding any figure freezes a wire constant
421
+ * into application code.
422
+ *
423
+ * A **static**, not a node method: it is a property of the wire,
424
+ * identical for every node, so reading it must not require a
425
+ * connection.
426
+ * @returns {number}
427
+ */
428
+ static maxEventBytes() {
429
+ const ret = wasm.leafnode_maxEventBytes();
430
+ return ret >>> 0;
431
+ }
432
+ /**
433
+ * This node's id, as 16 lowercase hex digits.
434
+ * @returns {string}
435
+ */
436
+ node_id_hex() {
437
+ let deferred1_0;
438
+ let deferred1_1;
439
+ try {
440
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
441
+ wasm.leafnode_node_id_hex(retptr, this.__wbg_ptr);
442
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
443
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
444
+ deferred1_0 = r0;
445
+ deferred1_1 = r1;
446
+ return getStringFromWasm0(r0, r1);
447
+ } finally {
448
+ wasm.__wbindgen_add_to_stack_pointer(16);
449
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
450
+ }
451
+ }
452
+ /**
453
+ * Register an event listener. Each receives one JSON string per
454
+ * event.
455
+ *
456
+ * Returns the token that cancels it, the same currency
457
+ * [`LeafStream::on_message`] hands back. A node-wide listener
458
+ * lives as long as the node by default, which is what a page
459
+ * registering one at startup wants; a harness or a component
460
+ * that registers per episode needs to be able to give it back.
461
+ * @param {Function} callback
462
+ * @returns {string}
463
+ */
464
+ on_event(callback) {
465
+ let deferred1_0;
466
+ let deferred1_1;
467
+ try {
468
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
469
+ wasm.leafnode_on_event(retptr, this.__wbg_ptr, addHeapObject(callback));
470
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
471
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
472
+ deferred1_0 = r0;
473
+ deferred1_1 = r1;
474
+ return getStringFromWasm0(r0, r1);
475
+ } finally {
476
+ wasm.__wbindgen_add_to_stack_pointer(16);
477
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
478
+ }
479
+ }
480
+ /**
481
+ * Open an application stream.
482
+ *
483
+ * `opts`: `{ reliability: "reliable" | "fireAndForget",
484
+ * reliable?: boolean, label?, streamId?, channelHash?, peer? }`.
485
+ * `streamId` (a decimal or `0x`-hex **string**, because a `u64`
486
+ * never crosses as a JS number) and `channelHash` (a **number**
487
+ * in `0..=65535`) are used verbatim when present, so a stream
488
+ * can match a publish contract a native handler dispatches on.
489
+ *
490
+ * `peer` is **16 hex digits** — the spelling `node_id_hex()`
491
+ * hands out and the four §9 peer methods take — and names the
492
+ * node the stream addresses; absent, it is the anchor, which is
493
+ * what every caller before this option got and still gets. It
494
+ * is the page-facing half of §9: `connectPeer` installs a
495
+ * direct leaf ↔ leaf session and this is what puts application
496
+ * bytes on it. Nothing below it changes —
497
+ * `crate::node::LeafNode::open_stream` has always taken a peer
498
+ * and `route_outbound` has always decided routed vs direct, so
499
+ * a stream to a peer whose session is still ROUTED rides the
500
+ * anchor and needs no second call to start riding the
501
+ * DataChannel.
502
+ *
503
+ * **But the HANDLE does not survive the upgrade.** §9 step 4
504
+ * installs a *replacement* session, so the peer's incarnation
505
+ * changes, and a `StreamHandle` is fenced to the incarnation it
506
+ * was opened on
507
+ * (`LeafNode::check_handle` — the alias the
508
+ * native R12 fix closed): a handle opened while the pair was
509
+ * routed refuses with "stale stream handle … reopen the
510
+ * stream" once the direct session lands. The addressing is
511
+ * unchanged — same peer, same `streamId` if one was pinned —
512
+ * so reopening is one call and the far end sees the same
513
+ * stream; what is not true is that the old handle keeps
514
+ * working. A page driving a peer across the upgrade should
515
+ * reopen on that refusal.
516
+ *
517
+ * A peer with no session at all refuses typed from `send`,
518
+ * unchanged.
519
+ *
520
+ * Both are read by `stream_options`, which
521
+ * [`crate::leader_session::MeshSession::open_stream`] also
522
+ * calls: the direct and the proxied surface cannot read the
523
+ * same option object two ways. That surface now **carries**
524
+ * `peer` in its request rather than refusing it, so a follower
525
+ * addresses a peer exactly as this surface does.
526
+ * @param {any} opts
527
+ * @returns {LeafStream}
528
+ */
529
+ open_stream(opts) {
530
+ try {
531
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
532
+ wasm.leafnode_open_stream(retptr, this.__wbg_ptr, addHeapObject(opts));
533
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
534
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
535
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
536
+ if (r2) {
537
+ throw takeObject(r1);
538
+ }
539
+ return LeafStream.__wrap(r0);
540
+ } finally {
541
+ wasm.__wbindgen_add_to_stack_pointer(16);
542
+ }
543
+ }
544
+ /**
545
+ * This node's **origin hash**, as 16 lowercase hex digits.
546
+ *
547
+ * Not the node id, and not interchangeable with it: the origin
548
+ * hash is derived from the entity key and is what rides every
549
+ * packet header this node seals, what names its nRPC reply
550
+ * channels (`<service>.replies.<origin>`), and what a receiver
551
+ * compares an event's `EventMeta.origin_hash` against — a
552
+ * direct peer whose packet origin and payload origin disagree
553
+ * has its frame dropped before admission, so anything that
554
+ * builds an event payload for this node to send MUST name this
555
+ * value.
556
+ * @returns {string}
557
+ */
558
+ origin_hash_hex() {
559
+ let deferred1_0;
560
+ let deferred1_1;
561
+ try {
562
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
563
+ wasm.leafnode_origin_hash_hex(retptr, this.__wbg_ptr);
564
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
565
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
566
+ deferred1_0 = r0;
567
+ deferred1_1 = r1;
568
+ return getStringFromWasm0(r0, r1);
569
+ } finally {
570
+ wasm.__wbindgen_add_to_stack_pointer(16);
571
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
572
+ }
573
+ }
574
+ /**
575
+ * Answer the offer `peer` sent — the other half of §9 step 3.
576
+ *
577
+ * Resolves to the dialog id the offerer minted, which the page
578
+ * uses exactly as `peer_offer`'s caller does.
579
+ *
580
+ * The offer applied here is the one that arrived as a
581
+ * **verified** envelope: signature checked against the sender's
582
+ * signed announcement, inside its `not_after`, and unreplayed.
583
+ * The page passes no SDP, which is why an offer it never
584
+ * received cannot be answered and an offer it did receive
585
+ * cannot be altered.
586
+ *
587
+ * A second offer from the same peer supersedes the first: the
588
+ * old dialog is counted `ice_failed` and its id stops being the
589
+ * live one, which is what the page's next call sees.
590
+ * @param {string} peer_hex
591
+ * @returns {Promise<string>}
592
+ */
593
+ peer_accept_offer(peer_hex) {
594
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
595
+ const len0 = WASM_VECTOR_LEN;
596
+ const ret = wasm.leafnode_peer_accept_offer(this.__wbg_ptr, ptr0, len0);
597
+ return takeObject(ret);
598
+ }
599
+ /**
600
+ * Service `peer`'s attempt once, and say where it stands.
601
+ *
602
+ * This is the trickle pump the page's drive loop calls. It does
603
+ * four things, all of them for one attempt:
604
+ *
605
+ * - applies the peer's `Answer` if one has arrived (an offerer
606
+ * only: an answerer already has the offer's description);
607
+ * - sends every candidate this browser has gathered for `peer`
608
+ * as a signed `Candidate` envelope;
609
+ * - applies every candidate the peer trickled;
610
+ * - evaluates the attempt's ICE deadline, and settles
611
+ * `udp_blocked` or `ice_relayed` when it has passed.
612
+ *
613
+ * Resolves to JSON: `{"dialog":"<16 hex>","state":"gathering"
614
+ * |"open"|"iceTimeout"|"udpBlocked","sent":<n>,"applied":<n>,
615
+ * "answered":<bool>,"remainingMs":"<decimal>"}`. `dialog` is
616
+ * the attempt that is CURRENTLY live for this peer, so a page
617
+ * whose dialog id no longer matches has been superseded — the
618
+ * one disposition this call cannot report for itself, because
619
+ * the attempt it would report about is gone.
620
+ *
621
+ * A candidate the browser rejects is not fatal to the attempt —
622
+ * the channel opening is what matters — but it is no longer
623
+ * SILENT. The engine's own error text rides back as
624
+ * `candidateError` (first one only, JSON-escaped) and is warned
625
+ * to the console. It was previously swallowed entirely: the
626
+ * success count rose or it did not, and nothing anywhere said
627
+ * why, which is the difference between "ICE is working on it"
628
+ * and "ICE has nothing to work with".
629
+ * @param {string} peer_hex
630
+ * @returns {Promise<string>}
631
+ */
632
+ peer_candidate(peer_hex) {
633
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
634
+ const len0 = WASM_VECTOR_LEN;
635
+ const ret = wasm.leafnode_peer_candidate(this.__wbg_ptr, ptr0, len0);
636
+ return takeObject(ret);
637
+ }
638
+ /**
639
+ * [`Self::peer_candidate`], for a caller that names the dialog
640
+ * it is driving.
641
+ *
642
+ * The proxied form. A follower's request is served by another
643
+ * tab after crossing a channel, so the attempt it was issued for
644
+ * may already have been replaced — and servicing a *replacement*
645
+ * under a stale request is a mutation, not a misclassification.
646
+ * `attempt_for` refuses first.
647
+ * @param {string} peer_hex
648
+ * @param {string} dialog_hex
649
+ * @returns {Promise<string>}
650
+ */
651
+ peer_candidate_in(peer_hex, dialog_hex) {
652
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
653
+ const len0 = WASM_VECTOR_LEN;
654
+ const ptr1 = passStringToWasm0(dialog_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
655
+ const len1 = WASM_VECTOR_LEN;
656
+ const ret = wasm.leafnode_peer_candidate_in(this.__wbg_ptr, ptr0, len0, ptr1, len1);
657
+ return takeObject(ret);
658
+ }
659
+ /**
660
+ * The live attempt's dialog, 16 hex digits, when `peer` is
661
+ * **already a healthy direct pair** — session installed, no
662
+ * relay entry, transport open — and `null` otherwise.
663
+ *
664
+ * What makes `connectPeer` idempotent. A second offer to a
665
+ * healthy pair is not a no-op: its connection replaces the
666
+ * transport's link, which closes the working one under the other
667
+ * side, and the answerer never asked for a new attempt — so the
668
+ * pair ends up reading direct with a closed channel. A page (or a
669
+ * library, like netcode or a lobby) that calls `connectPeer` "to
670
+ * be sure" must get the pair it already has.
671
+ * @param {string} peer_hex
672
+ * @returns {string | undefined}
673
+ */
674
+ peer_direct_dialog(peer_hex) {
675
+ try {
676
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
677
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
678
+ const len0 = WASM_VECTOR_LEN;
679
+ wasm.leafnode_peer_direct_dialog(retptr, this.__wbg_ptr, ptr0, len0);
680
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
681
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
682
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
683
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
684
+ if (r3) {
685
+ throw takeObject(r2);
686
+ }
687
+ let v2;
688
+ if (r0 !== 0) {
689
+ v2 = getStringFromWasm0(r0, r1);
690
+ wasm.__wbindgen_export5(r0, r1 * 1, 1);
691
+ }
692
+ return v2;
693
+ } finally {
694
+ wasm.__wbindgen_add_to_stack_pointer(16);
695
+ }
696
+ }
697
+ /**
698
+ * Run the Noise handshake with `peer` over the direct
699
+ * DataChannel — §9 step 4.
700
+ *
701
+ * **Takes a peer id and nothing else.** A page that could
702
+ * supply a Noise key could supply *any* key, so the responder
703
+ * static this handshake authenticates comes from `peer`'s
704
+ * signature-verified announcement and the PSK from the
705
+ * credential `connect` was given. There is no parameter through
706
+ * which either can be substituted, which is the point.
707
+ *
708
+ * The offerer's role, per §9 step 4: the leaf that created the
709
+ * offer is the NKpsk0 initiator. The answerer never calls this
710
+ * — its half runs from the inbound packet, in
711
+ * `Inner::on_handshake`.
712
+ *
713
+ * On success the direct session is installed on this side and
714
+ * the relay entry for `peer` is gone, so the pair's traffic
715
+ * leaves on its own channel. The session replacement itself is
716
+ * the node's — `LeafNode::install_session`, the
717
+ * Stage 3/4a fence, unchanged and unreached from here.
718
+ * @param {string} peer_hex
719
+ * @returns {Promise<string>}
720
+ */
721
+ peer_handshake(peer_hex) {
722
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
723
+ const len0 = WASM_VECTOR_LEN;
724
+ const ret = wasm.leafnode_peer_handshake(this.__wbg_ptr, ptr0, len0);
725
+ return takeObject(ret);
726
+ }
727
+ /**
728
+ * [`Self::peer_handshake`], for a caller that names the dialog
729
+ * it is driving.
730
+ *
731
+ * The proxied form, and the one where a stale request costs most:
732
+ * the Noise wait is the longest await on this surface, and the
733
+ * session it installs must belong to the attempt that negotiated
734
+ * the channel. A peer-only resolution would run a superseded
735
+ * request's handshake on the replacement.
736
+ * @param {string} peer_hex
737
+ * @param {string} dialog_hex
738
+ * @returns {Promise<string>}
739
+ */
740
+ peer_handshake_in(peer_hex, dialog_hex) {
741
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
742
+ const len0 = WASM_VECTOR_LEN;
743
+ const ptr1 = passStringToWasm0(dialog_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
744
+ const len1 = WASM_VECTOR_LEN;
745
+ const ret = wasm.leafnode_peer_handshake_in(this.__wbg_ptr, ptr0, len0, ptr1, len1);
746
+ return takeObject(ret);
747
+ }
748
+ /**
749
+ * Offer a direct connection to `peer` — §9 steps 2 and 3.
750
+ *
751
+ * Resolves to the dialog id, 16 hex digits, which is what the
752
+ * page correlates every later call on this attempt against.
753
+ *
754
+ * Three things happen, in this order:
755
+ *
756
+ * 1. **Discovery is required.** With no verified announcement
757
+ * for `peer` this refuses before anything is allocated:
758
+ * there is no key to handshake against and no authority to
759
+ * verify the peer's envelopes with, and guessing either is
760
+ * the failure mode this whole surface exists to prevent.
761
+ * 2. **The relayed session comes up** if there is not one
762
+ * already (§9 step 2): NKpsk0 over the anchor's blind
763
+ * forwarding, keys from the announcement. Failing here
764
+ * counts nothing — no offer was created, so there is no
765
+ * attempt to charge.
766
+ * 3. **The offer goes out** as a signed `Offer` envelope inside
767
+ * that session, and `ice_attempted` moves.
768
+ *
769
+ * The deadline the attempt runs under is
770
+ * [`PEER_ICE_DEADLINE_MS`] from now. The re-attempt owner calls
771
+ * `offer_peer` directly with the episode's deadline
772
+ * instead, which is how a repair and the window that absorbs
773
+ * its duplicate triggers end up being one absolute instant
774
+ * rather than two that nearly agree.
775
+ * @param {string} peer_hex
776
+ * @returns {Promise<string>}
777
+ */
778
+ peer_offer(peer_hex) {
779
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
780
+ const len0 = WASM_VECTOR_LEN;
781
+ const ret = wasm.leafnode_peer_offer(this.__wbg_ptr, ptr0, len0);
782
+ return takeObject(ret);
783
+ }
784
+ /**
785
+ * Publish `payload` on `channel`.
786
+ * @param {string} channel
787
+ * @param {Uint8Array} payload
788
+ * @returns {Promise<void>}
789
+ */
790
+ publish(channel, payload) {
791
+ const ptr0 = passStringToWasm0(channel, wasm.__wbindgen_export, wasm.__wbindgen_export2);
792
+ const len0 = WASM_VECTOR_LEN;
793
+ const ret = wasm.leafnode_publish(this.__wbg_ptr, ptr0, len0, addHeapObject(payload));
794
+ return takeObject(ret);
795
+ }
796
+ /**
797
+ * Answer a capability query from the announcements this leaf
798
+ * verified. A JSON array of
799
+ * `{ node_id, entity_id, capabilities, rtc_addr, noise_pubkey, version }`.
800
+ * @param {string} capability
801
+ * @returns {Promise<string>}
802
+ */
803
+ query(capability) {
804
+ const ptr0 = passStringToWasm0(capability, wasm.__wbindgen_export, wasm.__wbindgen_export2);
805
+ const len0 = WASM_VECTOR_LEN;
806
+ const ret = wasm.leafnode_query(this.__wbg_ptr, ptr0, len0);
807
+ return takeObject(ret);
808
+ }
809
+ /**
810
+ * Cancel the registration `token` names.
811
+ *
812
+ * `false` when it is already gone, which is the outcome a
813
+ * second cancellation wanted. An unparseable token is also
814
+ * `false`: it names no registration, and throwing for it would
815
+ * make a double-close harder to write than a leak.
816
+ * @param {string} token
817
+ * @returns {boolean}
818
+ */
819
+ remove_listener(token) {
820
+ const ptr0 = passStringToWasm0(token, wasm.__wbindgen_export, wasm.__wbindgen_export2);
821
+ const len0 = WASM_VECTOR_LEN;
822
+ const ret = wasm.leafnode_remove_listener(this.__wbg_ptr, ptr0, len0);
823
+ return ret !== 0;
824
+ }
825
+ /**
826
+ * Retire the node because leadership moved off this tab, and say
827
+ * how many pending calls that failed.
828
+ *
829
+ * [`Self::close`] is the page saying "I am done with this node";
830
+ * this is the lifecycle saying "this node no longer holds the
831
+ * identity". The difference is the disposition of the pending
832
+ * calls, and it matters to the caller: a close is a
833
+ * `SessionLost`, and a stand-down is a `LeaderLost` naming the
834
+ * generation that owned the call, because "which leader did I
835
+ * lose" is the question a page asks next and this is the only
836
+ * place that knows the answer.
837
+ *
838
+ * `closed` is set **first**, so the pump the failure path runs
839
+ * through emits nothing, and everything after it is teardown.
840
+ * @param {bigint} generation
841
+ * @returns {number}
842
+ */
843
+ retire(generation) {
844
+ const ret = wasm.leafnode_retire(this.__wbg_ptr, generation);
845
+ return ret >>> 0;
846
+ }
847
+ /**
848
+ * The re-attempt owner's ledger, as JSON.
849
+ *
850
+ * `{"armed":<bool>,"online":"<n>","iceFailed":"<n>",
851
+ * "triggers":"<n>","started":"<n>","coalesced":"<n>",
852
+ * "notEligible":"<n>","openEpisodes":<n>,"owned":<n>,
853
+ * "last":"<disposition>"|null}`.
854
+ *
855
+ * `started` is the number the witness asserts: one network
856
+ * change, one re-attempt, however many observations of it
857
+ * arrived. `triggers` is how many arrived, and `coalesced` is
858
+ * the difference the owner absorbed — reported rather than
859
+ * hidden, because "the trigger never fired" and "it fired and
860
+ * was absorbed" are different facts and only one of them is a
861
+ * defect.
862
+ *
863
+ * `owned` is how many pairs this leaf took direct as the
864
+ * offerer, i.e. the set a network change is evaluated against.
865
+ * @returns {string}
866
+ */
867
+ retry_report() {
868
+ let deferred1_0;
869
+ let deferred1_1;
870
+ try {
871
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
872
+ wasm.leafnode_retry_report(retptr, this.__wbg_ptr);
873
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
874
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
875
+ deferred1_0 = r0;
876
+ deferred1_1 = r1;
877
+ return getStringFromWasm0(r0, r1);
878
+ } finally {
879
+ wasm.__wbindgen_add_to_stack_pointer(16);
880
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
881
+ }
882
+ }
883
+ /**
884
+ * `RtcStats` on the leaf — plan §10's telemetry surface, in the
885
+ * field names the NATIVE `RtcStats` uses.
886
+ *
887
+ * Page-facing as `node.rtcStats()` through
888
+ * `@net-mesh/browser`. `u64`s are decimal strings, the rule
889
+ * [`Self::counters_json`] follows.
890
+ *
891
+ * Two halves, one reading: the transport's own ledger
892
+ * (admission, writes, the buffered-amount high water) and the
893
+ * ICE attempt ledger the conformance matrix asserts on. Plus
894
+ * `not_applicable`, which names the 24 native fields a leaf has
895
+ * no meaning for **and says why** — see
896
+ * [`crate::counters::LeafCounters::rtc_stats_json`] for the
897
+ * reason that is a list of reasons rather than a wall of
898
+ * zeros.
899
+ * @returns {string}
900
+ */
901
+ rtc_stats_json() {
902
+ let deferred1_0;
903
+ let deferred1_1;
904
+ try {
905
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
906
+ wasm.leafnode_rtc_stats_json(retptr, this.__wbg_ptr);
907
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
908
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
909
+ deferred1_0 = r0;
910
+ deferred1_1 = r1;
911
+ return getStringFromWasm0(r0, r1);
912
+ } finally {
913
+ wasm.__wbindgen_add_to_stack_pointer(16);
914
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
915
+ }
916
+ }
917
+ /**
918
+ * Serve one org-scoped unary service: `handler(caller, request)`
919
+ * resolves the response body.
920
+ *
921
+ * # The handler-drop contract (F-S3.1-2)
922
+ *
923
+ * The retire supervisor may drop the handler future without a
924
+ * final poll — cancellation is observed through the retirement
925
+ * observables (the terminal item, the sink's typed closed
926
+ * refusal, and `retired`), never assumed as a handler-side
927
+ * event; a detached observer holding `retired` observes the
928
+ * signal. After retirement the handler sees typed refusals and
929
+ * its return value is discarded — the terminal was already
930
+ * sent.
931
+ *
932
+ * Closing the returned handle retires this registration's live
933
+ * protected calls with their exact terminals and refuses new
934
+ * openings (C9's protected split).
935
+ * @param {string} service
936
+ * @param {string} access
937
+ * @param {Function} handler
938
+ * @param {any} opts
939
+ * @returns {OrgServeHandle}
940
+ */
941
+ serve_org(service, access, handler, opts) {
942
+ try {
943
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
944
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
945
+ const len0 = WASM_VECTOR_LEN;
946
+ const ptr1 = passStringToWasm0(access, wasm.__wbindgen_export, wasm.__wbindgen_export2);
947
+ const len1 = WASM_VECTOR_LEN;
948
+ wasm.leafnode_serve_org(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(handler), addHeapObject(opts));
949
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
950
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
951
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
952
+ if (r2) {
953
+ throw takeObject(r1);
954
+ }
955
+ return OrgServeHandle.__wrap(r0);
956
+ } finally {
957
+ wasm.__wbindgen_add_to_stack_pointer(16);
958
+ }
959
+ }
960
+ /**
961
+ * Serve one org-scoped client-streaming service:
962
+ * `handler(caller, requests)` resolves the response body. See
963
+ * [`Self::serve_org`] for the handler-drop contract and the
964
+ * close semantics.
965
+ * @param {string} service
966
+ * @param {string} access
967
+ * @param {Function} handler
968
+ * @param {any} opts
969
+ * @returns {OrgServeHandle}
970
+ */
971
+ serve_org_client_stream(service, access, handler, opts) {
972
+ try {
973
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
974
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
975
+ const len0 = WASM_VECTOR_LEN;
976
+ const ptr1 = passStringToWasm0(access, wasm.__wbindgen_export, wasm.__wbindgen_export2);
977
+ const len1 = WASM_VECTOR_LEN;
978
+ wasm.leafnode_serve_org_client_stream(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(handler), addHeapObject(opts));
979
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
980
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
981
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
982
+ if (r2) {
983
+ throw takeObject(r1);
984
+ }
985
+ return OrgServeHandle.__wrap(r0);
986
+ } finally {
987
+ wasm.__wbindgen_add_to_stack_pointer(16);
988
+ }
989
+ }
990
+ /**
991
+ * Serve one org-scoped duplex service:
992
+ * `handler(caller, requests, sink)` pulls requests and pushes
993
+ * responses. See [`Self::serve_org`] for the handler-drop
994
+ * contract and the close semantics.
995
+ * @param {string} service
996
+ * @param {string} access
997
+ * @param {Function} handler
998
+ * @param {any} opts
999
+ * @returns {OrgServeHandle}
1000
+ */
1001
+ serve_org_duplex(service, access, handler, opts) {
1002
+ try {
1003
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1004
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1005
+ const len0 = WASM_VECTOR_LEN;
1006
+ const ptr1 = passStringToWasm0(access, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1007
+ const len1 = WASM_VECTOR_LEN;
1008
+ wasm.leafnode_serve_org_duplex(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(handler), addHeapObject(opts));
1009
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1010
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1011
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1012
+ if (r2) {
1013
+ throw takeObject(r1);
1014
+ }
1015
+ return OrgServeHandle.__wrap(r0);
1016
+ } finally {
1017
+ wasm.__wbindgen_add_to_stack_pointer(16);
1018
+ }
1019
+ }
1020
+ /**
1021
+ * Serve one org-scoped server-streaming service:
1022
+ * `handler(caller, request, sink)` pushes through `sink` and
1023
+ * ends with `sink.close()` or by returning. See
1024
+ * [`Self::serve_org`] for the handler-drop contract and the
1025
+ * close semantics.
1026
+ * @param {string} service
1027
+ * @param {string} access
1028
+ * @param {Function} handler
1029
+ * @param {any} opts
1030
+ * @returns {OrgServeHandle}
1031
+ */
1032
+ serve_org_streaming(service, access, handler, opts) {
1033
+ try {
1034
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1035
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1036
+ const len0 = WASM_VECTOR_LEN;
1037
+ const ptr1 = passStringToWasm0(access, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1038
+ const len1 = WASM_VECTOR_LEN;
1039
+ wasm.leafnode_serve_org_streaming(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(handler), addHeapObject(opts));
1040
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1041
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1042
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1043
+ if (r2) {
1044
+ throw takeObject(r1);
1045
+ }
1046
+ return OrgServeHandle.__wrap(r0);
1047
+ } finally {
1048
+ wasm.__wbindgen_add_to_stack_pointer(16);
1049
+ }
1050
+ }
1051
+ /**
1052
+ * Sign a `0x0D02` signalling envelope for `peer` and hand it to
1053
+ * the control plane — no session with `peer` needed.
1054
+ *
1055
+ * Through the boundary, not the data path. An envelope
1056
+ * authenticates itself, so the carrier is untrusted and can be
1057
+ * anything.
1058
+ *
1059
+ * **The v1 anchor carrier refuses** (R14). `AnchorControlPlane`
1060
+ * does not carry envelopes: the Stage 4b listener reads one
1061
+ * trickle frame type, `candidate`, and forwards nothing to a
1062
+ * third party, so `signal` on a node connected to a real anchor
1063
+ * returns `LeafError::ControlPlane` naming the peer it could not
1064
+ * reach. That is deliberate — the first cut reported the local
1065
+ * send as a delivery the anchor discarded. The carrier that does
1066
+ * deliver today is the anchorless `MockControlPlane`; a
1067
+ * forwarding anchor route is Stage 6's, and the trait's shape
1068
+ * already admits it, which is why this takes a peer id and an
1069
+ * envelope rather than a session.
1070
+ * @param {string} peer_hex
1071
+ * @param {string} dialog_hex
1072
+ * @param {string} kind
1073
+ * @param {Uint8Array} payload
1074
+ * @returns {Promise<void>}
1075
+ */
1076
+ signal(peer_hex, dialog_hex, kind, payload) {
1077
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1078
+ const len0 = WASM_VECTOR_LEN;
1079
+ const ptr1 = passStringToWasm0(dialog_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1080
+ const len1 = WASM_VECTOR_LEN;
1081
+ const ptr2 = passStringToWasm0(kind, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1082
+ const len2 = WASM_VECTOR_LEN;
1083
+ const ret = wasm.leafnode_signal(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, addHeapObject(payload));
1084
+ return takeObject(ret);
1085
+ }
1086
+ /**
1087
+ * Subscribe to `channel` on the anchor.
1088
+ * @param {string} channel
1089
+ * @returns {Promise<void>}
1090
+ */
1091
+ subscribe(channel) {
1092
+ const ptr0 = passStringToWasm0(channel, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1093
+ const len0 = WASM_VECTOR_LEN;
1094
+ const ret = wasm.leafnode_subscribe(this.__wbg_ptr, ptr0, len0);
1095
+ return takeObject(ret);
1096
+ }
1097
+ /**
1098
+ * Release membership of `channel` on the anchor.
1099
+ *
1100
+ * The direct surface's release is unconditional — this node is
1101
+ * the only consumer it knows about. The last-consumer arithmetic
1102
+ * belongs to the session surface, where several tabs share one
1103
+ * node and one of them stopping is not all of them stopping.
1104
+ * @param {string} channel
1105
+ * @returns {Promise<void>}
1106
+ */
1107
+ unsubscribe(channel) {
1108
+ const ptr0 = passStringToWasm0(channel, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1109
+ const len0 = WASM_VECTOR_LEN;
1110
+ const ret = wasm.leafnode_unsubscribe(this.__wbg_ptr, ptr0, len0);
1111
+ return takeObject(ret);
1112
+ }
1113
+ }
1114
+ if (Symbol.dispose) LeafNode.prototype[Symbol.dispose] = LeafNode.prototype.free;
1115
+
1116
+ /**
1117
+ * One application stream.
1118
+ */
1119
+ export class LeafStream {
1120
+ static __wrap(ptr) {
1121
+ const obj = Object.create(LeafStream.prototype);
1122
+ obj.__wbg_ptr = ptr;
1123
+ LeafStreamFinalization.register(obj, obj.__wbg_ptr, obj);
1124
+ return obj;
1125
+ }
1126
+ __destroy_into_raw() {
1127
+ const ptr = this.__wbg_ptr;
1128
+ this.__wbg_ptr = 0;
1129
+ LeafStreamFinalization.unregister(this);
1130
+ return ptr;
1131
+ }
1132
+ free() {
1133
+ const ptr = this.__destroy_into_raw();
1134
+ wasm.__wbg_leafstream_free(ptr, 0);
1135
+ }
1136
+ /**
1137
+ * Stop using the stream. The session stays; a stream is
1138
+ * per-stream state, not a connection.
1139
+ *
1140
+ * Nothing leaves the wire: one DataChannel carries every stream
1141
+ * and there is no per-stream teardown frame. What it does do is
1142
+ * release the node's own per-stream state — the receive cursor
1143
+ * and the stream's classification — through the same fenced
1144
+ * entry point a stale handle is refused by. It used to do
1145
+ * literally nothing, which meant a proxied `StreamClose`
1146
+ * removed the leader's handle and left the node holding the
1147
+ * stream: a page that closed and reopened the same id got the
1148
+ * old cursor.
1149
+ *
1150
+ * **Every registration this stream took is given back**, so
1151
+ * repeated open/close leaves [`LeafNode::listener_count`] flat.
1152
+ * A callback registered through [`Self::on_message`] lives on
1153
+ * the node, not on this object, and it captures the consumer's
1154
+ * own callback — so a close that removed only the node's stream
1155
+ * state left the closure attached, still invoked for every
1156
+ * event the node produced and still holding its consumer
1157
+ * alive, for as long as the node lived.
1158
+ *
1159
+ * A refusal here is reported rather than returned: the handle is
1160
+ * being discarded either way, and `close` is the one operation
1161
+ * for which "it was already gone" is the outcome the caller
1162
+ * wanted.
1163
+ */
1164
+ close() {
1165
+ wasm.leafstream_close(this.__wbg_ptr);
1166
+ }
1167
+ /**
1168
+ * The incarnation of the session this stream was opened on,
1169
+ * decimal — the spelling the event carries, so there is no
1170
+ * conversion to get wrong.
1171
+ *
1172
+ * Provenance, not part of the filter key: see
1173
+ * [`crate::node::LeafEvent::StreamData`].
1174
+ * @returns {string}
1175
+ */
1176
+ incarnation() {
1177
+ let deferred1_0;
1178
+ let deferred1_1;
1179
+ try {
1180
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1181
+ wasm.leafstream_incarnation(retptr, this.__wbg_ptr);
1182
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1183
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1184
+ deferred1_0 = r0;
1185
+ deferred1_1 = r1;
1186
+ return getStringFromWasm0(r0, r1);
1187
+ } finally {
1188
+ wasm.__wbindgen_add_to_stack_pointer(16);
1189
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
1190
+ }
1191
+ }
1192
+ /**
1193
+ * Whether this stream retransmits.
1194
+ * @returns {boolean}
1195
+ */
1196
+ is_reliable() {
1197
+ const ret = wasm.leafstream_is_reliable(this.__wbg_ptr);
1198
+ return ret !== 0;
1199
+ }
1200
+ /**
1201
+ * Listen for this stream's inbound payloads.
1202
+ *
1203
+ * **The callback receives the node's `stream_data` event JSON
1204
+ * string**, not bytes — the same string
1205
+ * [`LeafNode::on_event`] delivers, filtered to this stream's
1206
+ * **peer and** id:
1207
+ *
1208
+ * ```text
1209
+ * {"type":"stream_data","peer_node":"200","incarnation":"1","stream_id":"9","seq":"1","payload":"AQI="}
1210
+ * ```
1211
+ *
1212
+ * Every `u64` is a decimal string and `payload` is standard
1213
+ * padded base64. One contract, one direction: the leaf emits
1214
+ * its canonical event JSON and the consumer decodes it.
1215
+ * Emitting bytes here instead would mean a second encoding of
1216
+ * an event that already exists, and would throw away `seq` and
1217
+ * the rest of the event's provenance at the boundary.
1218
+ * `@net-mesh/browser`'s `LeafStream` does that decode, which is
1219
+ * why its `onMessage` and its async iterator yield
1220
+ * `Uint8Array`; a host wiring this callback itself must parse
1221
+ * the same way.
1222
+ *
1223
+ * **The peer is half of the key, not decoration.** A stream id
1224
+ * comes from a label or from a publish contract and neither
1225
+ * involves the peer, so one label opened to two peers is one id
1226
+ * on two sessions — a supported composition. Filtering the
1227
+ * node-wide event stream by the id alone made both wrappers
1228
+ * accept whichever peer's payload arrived, delivering one
1229
+ * peer's bytes into the other peer's inbox; a page that echoes
1230
+ * then amplifies it. The incarnation rides the event as
1231
+ * provenance and is deliberately **not** part of this key: see
1232
+ * [`crate::node::LeafEvent::StreamData`].
1233
+ *
1234
+ * The callback runs with **no** borrow of the node held, so it
1235
+ * may call straight back in: [`Self::send`], [`LeafNode::close`]
1236
+ * and the rest are all reachable from here. That was not true
1237
+ * before — the event was emitted from inside `flush`'s `&mut
1238
+ * self` — so the advertised echo trapped instead of sending.
1239
+ *
1240
+ * **Returns the token that cancels the registration**, decimal.
1241
+ * The closure is registered on the node and captures the
1242
+ * consumer's callback, so a registration nothing names is
1243
+ * retained for the node's whole life and keeps being invoked
1244
+ * for every event it produces — which is what repeated
1245
+ * open/close accumulated before the token existed.
1246
+ * [`Self::close`] gives back every token this stream took, so
1247
+ * an ordinary consumer never has to; [`Self::remove_listener`]
1248
+ * is for one that wants to stop listening without closing.
1249
+ * @param {Function} callback
1250
+ * @returns {string}
1251
+ */
1252
+ on_message(callback) {
1253
+ let deferred1_0;
1254
+ let deferred1_1;
1255
+ try {
1256
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1257
+ wasm.leafstream_on_message(retptr, this.__wbg_ptr, addHeapObject(callback));
1258
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1259
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1260
+ deferred1_0 = r0;
1261
+ deferred1_1 = r1;
1262
+ return getStringFromWasm0(r0, r1);
1263
+ } finally {
1264
+ wasm.__wbindgen_add_to_stack_pointer(16);
1265
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
1266
+ }
1267
+ }
1268
+ /**
1269
+ * The peer this stream is with, 16 lowercase hex digits.
1270
+ *
1271
+ * **Spelled exactly like [`Self::stream_id_hex`], deliberately.**
1272
+ * A stream is addressed by `(peer, stream_id)` and both halves
1273
+ * of that key are read through the same accessor shape and
1274
+ * reconciled against the event's decimal field by the same
1275
+ * `BigInt` conversion, so a consumer has one idiom to get right
1276
+ * rather than two. A peer-blind filter is the R4-10 defect: one
1277
+ * label opened to two peers is one id on two sessions, and
1278
+ * filtering the node-wide event stream by the id alone hands
1279
+ * each wrapper whichever peer's payload arrived.
1280
+ * @returns {string}
1281
+ */
1282
+ peer_node_hex() {
1283
+ let deferred1_0;
1284
+ let deferred1_1;
1285
+ try {
1286
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1287
+ wasm.leafstream_peer_node_hex(retptr, this.__wbg_ptr);
1288
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1289
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1290
+ deferred1_0 = r0;
1291
+ deferred1_1 = r1;
1292
+ return getStringFromWasm0(r0, r1);
1293
+ } finally {
1294
+ wasm.__wbindgen_add_to_stack_pointer(16);
1295
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
1296
+ }
1297
+ }
1298
+ /**
1299
+ * Cancel one registration [`Self::on_message`] returned.
1300
+ *
1301
+ * `false` when the token names no live registration of this
1302
+ * stream — already cancelled, already closed, or never ours.
1303
+ * Scoped to this stream on purpose: a token is the right to
1304
+ * remove one subscription, and one stream must not be able to
1305
+ * silence another's consumer by guessing a number.
1306
+ * @param {string} token
1307
+ * @returns {boolean}
1308
+ */
1309
+ remove_listener(token) {
1310
+ const ptr0 = passStringToWasm0(token, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1311
+ const len0 = WASM_VECTOR_LEN;
1312
+ const ret = wasm.leafstream_remove_listener(this.__wbg_ptr, ptr0, len0);
1313
+ return ret !== 0;
1314
+ }
1315
+ /**
1316
+ * Send one payload. The bytes ride verbatim as one event in one
1317
+ * packet — no leaf-added framing.
1318
+ *
1319
+ * Callable from [`Self::on_message`]: the borrow this takes is
1320
+ * released before any listener runs, which is what makes
1321
+ * `stream.onMessage(p => stream.send(p))` — the echo shape the
1322
+ * TypeScript surface advertises — a supported operation rather
1323
+ * than a `RefCell` trap.
1324
+ * @param {Uint8Array} payload
1325
+ */
1326
+ send(payload) {
1327
+ try {
1328
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1329
+ wasm.leafstream_send(retptr, this.__wbg_ptr, addHeapObject(payload));
1330
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1331
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1332
+ if (r1) {
1333
+ throw takeObject(r0);
1334
+ }
1335
+ } finally {
1336
+ wasm.__wbindgen_add_to_stack_pointer(16);
1337
+ }
1338
+ }
1339
+ /**
1340
+ * The stream id, 16 lowercase hex digits.
1341
+ * @returns {string}
1342
+ */
1343
+ stream_id_hex() {
1344
+ let deferred1_0;
1345
+ let deferred1_1;
1346
+ try {
1347
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1348
+ wasm.leafstream_stream_id_hex(retptr, this.__wbg_ptr);
1349
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1350
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1351
+ deferred1_0 = r0;
1352
+ deferred1_1 = r1;
1353
+ return getStringFromWasm0(r0, r1);
1354
+ } finally {
1355
+ wasm.__wbindgen_add_to_stack_pointer(16);
1356
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
1357
+ }
1358
+ }
1359
+ }
1360
+ if (Symbol.dispose) LeafStream.prototype[Symbol.dispose] = LeafStream.prototype.free;
1361
+
1362
+ /**
1363
+ * A Net node as a tab sees it, whether or not this tab runs it.
1364
+ *
1365
+ * ```text
1366
+ * class MeshSession {
1367
+ * static open(opts): Promise<MeshSession>
1368
+ * role(): "leader" | "follower"
1369
+ * generation(): string
1370
+ * node_id_hex(): string | undefined
1371
+ * fingerprint(): string
1372
+ * scope(): string
1373
+ * interruption_ms(): number | undefined
1374
+ * call(service, payload, timeout_ms?): Promise<Uint8Array>
1375
+ * subscribe(channel): Promise<void>
1376
+ * publish(channel, payload): Promise<void>
1377
+ * announce(capabilities): Promise<void>
1378
+ * query(capability): Promise<string>
1379
+ * counters_json(): Promise<string>
1380
+ * signal(peer_hex, dialog, kind, payload): Promise<void>
1381
+ * open_stream(opts): Promise<ProxyStream>
1382
+ * on_event(cb): void
1383
+ * close(): void
1384
+ * }
1385
+ * ```
1386
+ *
1387
+ * One honest difference from `crate::wasm::LeafNode`: `open_stream`
1388
+ * returns a promise, because on a follower the stream is opened by
1389
+ * another tab. Everything else has the same shape, and every
1390
+ * operation carries the generation.
1391
+ */
1392
+ export class MeshSession {
1393
+ static __wrap(ptr) {
1394
+ const obj = Object.create(MeshSession.prototype);
1395
+ obj.__wbg_ptr = ptr;
1396
+ MeshSessionFinalization.register(obj, obj.__wbg_ptr, obj);
1397
+ return obj;
1398
+ }
1399
+ __destroy_into_raw() {
1400
+ const ptr = this.__wbg_ptr;
1401
+ this.__wbg_ptr = 0;
1402
+ MeshSessionFinalization.unregister(this);
1403
+ return ptr;
1404
+ }
1405
+ free() {
1406
+ const ptr = this.__destroy_into_raw();
1407
+ wasm.__wbg_meshsession_free(ptr, 0);
1408
+ }
1409
+ /**
1410
+ * Publish this node's capability announcement.
1411
+ *
1412
+ * Also records it as this tab's current intent, so a takeover
1413
+ * re-publishes what the page last announced rather than what it
1414
+ * opened with.
1415
+ * @param {string[]} capabilities
1416
+ * @returns {Promise<void>}
1417
+ */
1418
+ announce(capabilities) {
1419
+ const ptr0 = passArrayJsValueToWasm0(capabilities, wasm.__wbindgen_export);
1420
+ const len0 = WASM_VECTOR_LEN;
1421
+ const ret = wasm.meshsession_announce(this.__wbg_ptr, ptr0, len0);
1422
+ return takeObject(ret);
1423
+ }
1424
+ /**
1425
+ * Call an nRPC service.
1426
+ * @param {string} service
1427
+ * @param {Uint8Array} payload
1428
+ * @param {number | null} [timeout_ms]
1429
+ * @returns {Promise<Uint8Array>}
1430
+ */
1431
+ call(service, payload, timeout_ms) {
1432
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1433
+ const len0 = WASM_VECTOR_LEN;
1434
+ const ret = wasm.meshsession_call(this.__wbg_ptr, ptr0, len0, addHeapObject(payload), !isLikeNone(timeout_ms), isLikeNone(timeout_ms) ? 0 : timeout_ms);
1435
+ return takeObject(ret);
1436
+ }
1437
+ /**
1438
+ * One org-scoped unary call through the shared session.
1439
+ *
1440
+ * Identical contract to [`crate::wasm::LeafNode::call_org`] —
1441
+ * the deadline is absolute, a frozen tab gets no lease
1442
+ * extension, and nothing here ever resumes a retired call. On a
1443
+ * follower the request crosses the proxy with the caller's
1444
+ * proofs as opaque credential bytes (the leader's node mints the
1445
+ * signed opening — the entity key never leaves a node); a
1446
+ * generation move mid-call fails typed `LeaderLost` and is never
1447
+ * resumed, and a retained handle from an older generation
1448
+ * refuses rather than addressing a successor's call.
1449
+ * @param {string} service
1450
+ * @param {Uint8Array} payload
1451
+ * @param {any} opts
1452
+ * @returns {Promise<Uint8Array>}
1453
+ */
1454
+ call_org(service, payload, opts) {
1455
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1456
+ const len0 = WASM_VECTOR_LEN;
1457
+ const ret = wasm.meshsession_call_org(this.__wbg_ptr, ptr0, len0, addHeapObject(payload), addHeapObject(opts));
1458
+ return takeObject(ret);
1459
+ }
1460
+ /**
1461
+ * One org-scoped client-streaming call through the shared
1462
+ * session. See [`Self::call_org`] for the contract.
1463
+ * @param {string} service
1464
+ * @param {any} opts
1465
+ * @returns {Promise<OrgUploadCallHandle>}
1466
+ */
1467
+ call_org_client_stream(service, opts) {
1468
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1469
+ const len0 = WASM_VECTOR_LEN;
1470
+ const ret = wasm.meshsession_call_org_client_stream(this.__wbg_ptr, ptr0, len0, addHeapObject(opts));
1471
+ return takeObject(ret);
1472
+ }
1473
+ /**
1474
+ * One org-scoped duplex call through the shared session. See
1475
+ * [`Self::call_org`] for the contract.
1476
+ * @param {string} service
1477
+ * @param {any} opts
1478
+ * @returns {Promise<OrgDuplexCallHandle>}
1479
+ */
1480
+ call_org_duplex(service, opts) {
1481
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1482
+ const len0 = WASM_VECTOR_LEN;
1483
+ const ret = wasm.meshsession_call_org_duplex(this.__wbg_ptr, ptr0, len0, addHeapObject(opts));
1484
+ return takeObject(ret);
1485
+ }
1486
+ /**
1487
+ * One org-scoped server-streaming call through the shared
1488
+ * session. See [`Self::call_org`] for the deadline, suspension
1489
+ * and closure contract. An opening denial REJECTS this promise;
1490
+ * the typed terminal error arrives as the stream's final
1491
+ * `next()` item.
1492
+ * @param {string} service
1493
+ * @param {Uint8Array} payload
1494
+ * @param {any} opts
1495
+ * @returns {Promise<OrgByteStreamHandle>}
1496
+ */
1497
+ call_org_streaming(service, payload, opts) {
1498
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1499
+ const len0 = WASM_VECTOR_LEN;
1500
+ const ret = wasm.meshsession_call_org_streaming(this.__wbg_ptr, ptr0, len0, addHeapObject(payload), addHeapObject(opts));
1501
+ return takeObject(ret);
1502
+ }
1503
+ /**
1504
+ * Stand down and release the lock.
1505
+ */
1506
+ close() {
1507
+ wasm.meshsession_close(this.__wbg_ptr);
1508
+ }
1509
+ /**
1510
+ * Every leaf counter as JSON; `u64`s are decimal strings.
1511
+ * @returns {Promise<string>}
1512
+ */
1513
+ counters_json() {
1514
+ const ret = wasm.meshsession_counters_json(this.__wbg_ptr);
1515
+ return takeObject(ret);
1516
+ }
1517
+ /**
1518
+ * Run the enrollment exchange if the node is not enrolled.
1519
+ *
1520
+ * Proxied, so a follower's `enroll()` works: one node per origin
1521
+ * means one enrollment per origin, and the follower is asking
1522
+ * the only session there is. Idempotent on the leader's side —
1523
+ * an already-enrolled node answers immediately.
1524
+ * @returns {Promise<void>}
1525
+ */
1526
+ enroll() {
1527
+ const ret = wasm.meshsession_enroll(this.__wbg_ptr);
1528
+ return takeObject(ret);
1529
+ }
1530
+ /**
1531
+ * The identity fingerprint the lock is named after.
1532
+ * @returns {string}
1533
+ */
1534
+ fingerprint() {
1535
+ let deferred1_0;
1536
+ let deferred1_1;
1537
+ try {
1538
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1539
+ wasm.meshsession_fingerprint(retptr, this.__wbg_ptr);
1540
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1541
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1542
+ deferred1_0 = r0;
1543
+ deferred1_1 = r1;
1544
+ return getStringFromWasm0(r0, r1);
1545
+ } finally {
1546
+ wasm.__wbindgen_add_to_stack_pointer(16);
1547
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
1548
+ }
1549
+ }
1550
+ /**
1551
+ * The generation in force, as a decimal string.
1552
+ * @returns {string}
1553
+ */
1554
+ generation() {
1555
+ let deferred1_0;
1556
+ let deferred1_1;
1557
+ try {
1558
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1559
+ wasm.meshsession_generation(retptr, this.__wbg_ptr);
1560
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1561
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1562
+ deferred1_0 = r0;
1563
+ deferred1_1 = r1;
1564
+ return getStringFromWasm0(r0, r1);
1565
+ } finally {
1566
+ wasm.__wbindgen_add_to_stack_pointer(16);
1567
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
1568
+ }
1569
+ }
1570
+ /**
1571
+ * The measured interruption, in milliseconds, for a tab that was
1572
+ * promoted. `undefined` on the first leader.
1573
+ * @returns {number | undefined}
1574
+ */
1575
+ interruption_ms() {
1576
+ try {
1577
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1578
+ wasm.meshsession_interruption_ms(retptr, this.__wbg_ptr);
1579
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1580
+ var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true);
1581
+ return r0 === 0 ? undefined : r2;
1582
+ } finally {
1583
+ wasm.__wbindgen_add_to_stack_pointer(16);
1584
+ }
1585
+ }
1586
+ /**
1587
+ * Whether the node has completed enrollment.
1588
+ *
1589
+ * A promise, where [`crate::wasm::LeafNode::is_enrolled`] is
1590
+ * synchronous: on a follower the answer lives in another tab.
1591
+ * @returns {Promise<boolean>}
1592
+ */
1593
+ is_enrolled() {
1594
+ const ret = wasm.meshsession_is_enrolled(this.__wbg_ptr);
1595
+ return takeObject(ret);
1596
+ }
1597
+ /**
1598
+ * The node's id, 16 lowercase hex digits, once one is known.
1599
+ * @returns {string | undefined}
1600
+ */
1601
+ node_id_hex() {
1602
+ try {
1603
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1604
+ wasm.meshsession_node_id_hex(retptr, this.__wbg_ptr);
1605
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1606
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1607
+ let v1;
1608
+ if (r0 !== 0) {
1609
+ v1 = getStringFromWasm0(r0, r1);
1610
+ wasm.__wbindgen_export5(r0, r1 * 1, 1);
1611
+ }
1612
+ return v1;
1613
+ } finally {
1614
+ wasm.__wbindgen_add_to_stack_pointer(16);
1615
+ }
1616
+ }
1617
+ /**
1618
+ * Register an event listener. One JSON string per event.
1619
+ *
1620
+ * Beyond [`crate::node::LeafEvent`]'s tags, a session emits
1621
+ * `leader_changed`, `subscription_restored`, `leader_lost`,
1622
+ * `generation_fenced`, `not_leader` and
1623
+ * `serve_registration_refused` — the lifecycle made observable,
1624
+ * because a page that cannot see a leader change cannot explain
1625
+ * one, and a page that cannot see a permanent serve-registration
1626
+ * refusal cannot explain why its service never dispatches
1627
+ * (LEAF-14: the typed message a local `org_serve` would have
1628
+ * thrown, exactly once, with no retry storm behind it).
1629
+ * @param {Function} callback
1630
+ */
1631
+ on_event(callback) {
1632
+ wasm.meshsession_on_event(this.__wbg_ptr, addHeapObject(callback));
1633
+ }
1634
+ /**
1635
+ * Resolve the identity, contend for the origin's lock, and return
1636
+ * this tab's session.
1637
+ *
1638
+ * `opts` is everything `LeafNode.connect` takes — `credentialB64`,
1639
+ * `origin`, `bootstrapUrl?`, `iceServers?`, `entitySecretHex?`,
1640
+ * `noiseSecretHex?` — plus `capabilities?`, `subscriptions?`,
1641
+ * `dbName?` and `lockScope?`.
1642
+ *
1643
+ * With no `entitySecretHex` the identity comes from IndexedDB
1644
+ * under a non-extractable AES-GCM key, generated there on first
1645
+ * run. With one, the host holds custody and nothing is stored.
1646
+ * Both paths produce the same value and take the same route in.
1647
+ * @param {any} opts
1648
+ * @returns {Promise<MeshSession>}
1649
+ */
1650
+ static open(opts) {
1651
+ const ret = wasm.meshsession_open(addHeapObject(opts));
1652
+ return takeObject(ret);
1653
+ }
1654
+ /**
1655
+ * Open an application stream, wherever the node is.
1656
+ * @param {any} opts
1657
+ * @returns {Promise<ProxyStream>}
1658
+ */
1659
+ open_stream(opts) {
1660
+ const ret = wasm.meshsession_open_stream(this.__wbg_ptr, addHeapObject(opts));
1661
+ return takeObject(ret);
1662
+ }
1663
+ /**
1664
+ * Answer the offer `peer_hex` filed.
1665
+ * @param {string} peer_hex
1666
+ * @returns {Promise<string>}
1667
+ */
1668
+ peer_accept_offer(peer_hex) {
1669
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1670
+ const len0 = WASM_VECTOR_LEN;
1671
+ const ret = wasm.meshsession_peer_accept_offer(this.__wbg_ptr, ptr0, len0);
1672
+ return takeObject(ret);
1673
+ }
1674
+ /**
1675
+ * Service one polling step of the attempt `dialog_hex`.
1676
+ *
1677
+ * The dialog is required, not optional. A proxied poll that
1678
+ * named only the peer would be applied to whatever attempt is
1679
+ * live when the leader gets to it, which is how a superseded
1680
+ * request drives its replacement.
1681
+ * @param {string} peer_hex
1682
+ * @param {string} dialog_hex
1683
+ * @returns {Promise<string>}
1684
+ */
1685
+ peer_candidate(peer_hex, dialog_hex) {
1686
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1687
+ const len0 = WASM_VECTOR_LEN;
1688
+ const ptr1 = passStringToWasm0(dialog_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1689
+ const len1 = WASM_VECTOR_LEN;
1690
+ const ret = wasm.meshsession_peer_candidate(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1691
+ return takeObject(ret);
1692
+ }
1693
+ /**
1694
+ * The live attempt's dialog when `peer_hex` is already a healthy
1695
+ * direct pair on the leader, or `undefined` — what makes a follower's
1696
+ * `connectPeer` idempotent, as `LeafNode::peer_direct_dialog` makes
1697
+ * the leader's.
1698
+ * @param {string} peer_hex
1699
+ * @returns {Promise<string | undefined>}
1700
+ */
1701
+ peer_direct_dialog(peer_hex) {
1702
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1703
+ const len0 = WASM_VECTOR_LEN;
1704
+ const ret = wasm.meshsession_peer_direct_dialog(this.__wbg_ptr, ptr0, len0);
1705
+ return takeObject(ret);
1706
+ }
1707
+ /**
1708
+ * Run the Noise handshake for the attempt `dialog_hex`.
1709
+ * @param {string} peer_hex
1710
+ * @param {string} dialog_hex
1711
+ * @returns {Promise<string>}
1712
+ */
1713
+ peer_handshake(peer_hex, dialog_hex) {
1714
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1715
+ const len0 = WASM_VECTOR_LEN;
1716
+ const ptr1 = passStringToWasm0(dialog_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1717
+ const len1 = WASM_VECTOR_LEN;
1718
+ const ret = wasm.meshsession_peer_handshake(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1719
+ return takeObject(ret);
1720
+ }
1721
+ /**
1722
+ * Mint an offer and start an attempt with `peer_hex` (§9).
1723
+ *
1724
+ * The four peer methods below are the primitives a **shared**
1725
+ * TypeScript driver calls. The drive loop and its classification
1726
+ * live once, in the package, and are used by `BrowserNode` and
1727
+ * by this session alike — a second implementation of that loop
1728
+ * here would be two spellings of one contract.
1729
+ * @param {string} peer_hex
1730
+ * @returns {Promise<string>}
1731
+ */
1732
+ peer_offer(peer_hex) {
1733
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1734
+ const len0 = WASM_VECTOR_LEN;
1735
+ const ret = wasm.meshsession_peer_offer(this.__wbg_ptr, ptr0, len0);
1736
+ return takeObject(ret);
1737
+ }
1738
+ /**
1739
+ * Publish one payload to a channel.
1740
+ * @param {string} channel
1741
+ * @param {Uint8Array} payload
1742
+ * @returns {Promise<void>}
1743
+ */
1744
+ publish(channel, payload) {
1745
+ const ptr0 = passStringToWasm0(channel, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1746
+ const len0 = WASM_VECTOR_LEN;
1747
+ const ret = wasm.meshsession_publish(this.__wbg_ptr, ptr0, len0, addHeapObject(payload));
1748
+ return takeObject(ret);
1749
+ }
1750
+ /**
1751
+ * Find the nodes offering a capability.
1752
+ * @param {string} capability
1753
+ * @returns {Promise<string>}
1754
+ */
1755
+ query(capability) {
1756
+ const ptr0 = passStringToWasm0(capability, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1757
+ const len0 = WASM_VECTOR_LEN;
1758
+ const ret = wasm.meshsession_query(this.__wbg_ptr, ptr0, len0);
1759
+ return takeObject(ret);
1760
+ }
1761
+ /**
1762
+ * `"leader"` or `"follower"`.
1763
+ * @returns {string}
1764
+ */
1765
+ role() {
1766
+ let deferred1_0;
1767
+ let deferred1_1;
1768
+ try {
1769
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1770
+ wasm.meshsession_role(retptr, this.__wbg_ptr);
1771
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1772
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1773
+ deferred1_0 = r0;
1774
+ deferred1_1 = r1;
1775
+ return getStringFromWasm0(r0, r1);
1776
+ } finally {
1777
+ wasm.__wbindgen_add_to_stack_pointer(16);
1778
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
1779
+ }
1780
+ }
1781
+ /**
1782
+ * The lock and channel name.
1783
+ * @returns {string}
1784
+ */
1785
+ scope() {
1786
+ let deferred1_0;
1787
+ let deferred1_1;
1788
+ try {
1789
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1790
+ wasm.meshsession_scope(retptr, this.__wbg_ptr);
1791
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1792
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1793
+ deferred1_0 = r0;
1794
+ deferred1_1 = r1;
1795
+ return getStringFromWasm0(r0, r1);
1796
+ } finally {
1797
+ wasm.__wbindgen_add_to_stack_pointer(16);
1798
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
1799
+ }
1800
+ }
1801
+ /**
1802
+ * Serve one org-scoped unary service through the shared
1803
+ * session: `handler(caller, request)` resolves the response
1804
+ * body. The registration rides the proxy registry and its
1805
+ * inbound calls dispatch to THIS follower's handle and no other.
1806
+ *
1807
+ * # The handler-drop contract (F-S3.1-2)
1808
+ *
1809
+ * The retire supervisor may drop the handler future without a
1810
+ * final poll — cancellation is observed through the retirement
1811
+ * observables (the terminal item, the sink's typed closed
1812
+ * refusal, and `retired`), never assumed as a handler-side
1813
+ * event; a detached observer holding `retired` observes the
1814
+ * signal. After retirement the handler sees typed refusals and
1815
+ * its return value is discarded — the terminal was already
1816
+ * sent. Closing the returned handle retires this registration's
1817
+ * live protected calls with their exact terminals and refuses
1818
+ * new openings (C9's protected split).
1819
+ * @param {string} service
1820
+ * @param {string} access
1821
+ * @param {Function} handler
1822
+ * @param {any} opts
1823
+ * @returns {OrgServeHandle}
1824
+ */
1825
+ serve_org(service, access, handler, opts) {
1826
+ try {
1827
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1828
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1829
+ const len0 = WASM_VECTOR_LEN;
1830
+ const ptr1 = passStringToWasm0(access, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1831
+ const len1 = WASM_VECTOR_LEN;
1832
+ wasm.meshsession_serve_org(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(handler), addHeapObject(opts));
1833
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1834
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1835
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1836
+ if (r2) {
1837
+ throw takeObject(r1);
1838
+ }
1839
+ return OrgServeHandle.__wrap(r0);
1840
+ } finally {
1841
+ wasm.__wbindgen_add_to_stack_pointer(16);
1842
+ }
1843
+ }
1844
+ /**
1845
+ * Serve one org-scoped client-streaming service through the
1846
+ * shared session. See [`Self::serve_org`] for the handler-drop
1847
+ * contract and the close semantics.
1848
+ * @param {string} service
1849
+ * @param {string} access
1850
+ * @param {Function} handler
1851
+ * @param {any} opts
1852
+ * @returns {OrgServeHandle}
1853
+ */
1854
+ serve_org_client_stream(service, access, handler, opts) {
1855
+ try {
1856
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1857
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1858
+ const len0 = WASM_VECTOR_LEN;
1859
+ const ptr1 = passStringToWasm0(access, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1860
+ const len1 = WASM_VECTOR_LEN;
1861
+ wasm.meshsession_serve_org_client_stream(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(handler), addHeapObject(opts));
1862
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1863
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1864
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1865
+ if (r2) {
1866
+ throw takeObject(r1);
1867
+ }
1868
+ return OrgServeHandle.__wrap(r0);
1869
+ } finally {
1870
+ wasm.__wbindgen_add_to_stack_pointer(16);
1871
+ }
1872
+ }
1873
+ /**
1874
+ * Serve one org-scoped duplex service through the shared
1875
+ * session. See [`Self::serve_org`] for the handler-drop
1876
+ * contract and the close semantics.
1877
+ * @param {string} service
1878
+ * @param {string} access
1879
+ * @param {Function} handler
1880
+ * @param {any} opts
1881
+ * @returns {OrgServeHandle}
1882
+ */
1883
+ serve_org_duplex(service, access, handler, opts) {
1884
+ try {
1885
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1886
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1887
+ const len0 = WASM_VECTOR_LEN;
1888
+ const ptr1 = passStringToWasm0(access, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1889
+ const len1 = WASM_VECTOR_LEN;
1890
+ wasm.meshsession_serve_org_duplex(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(handler), addHeapObject(opts));
1891
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1892
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1893
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1894
+ if (r2) {
1895
+ throw takeObject(r1);
1896
+ }
1897
+ return OrgServeHandle.__wrap(r0);
1898
+ } finally {
1899
+ wasm.__wbindgen_add_to_stack_pointer(16);
1900
+ }
1901
+ }
1902
+ /**
1903
+ * Serve one org-scoped server-streaming service through the
1904
+ * shared session. See [`Self::serve_org`] for the handler-drop
1905
+ * contract and the close semantics.
1906
+ * @param {string} service
1907
+ * @param {string} access
1908
+ * @param {Function} handler
1909
+ * @param {any} opts
1910
+ * @returns {OrgServeHandle}
1911
+ */
1912
+ serve_org_streaming(service, access, handler, opts) {
1913
+ try {
1914
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1915
+ const ptr0 = passStringToWasm0(service, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1916
+ const len0 = WASM_VECTOR_LEN;
1917
+ const ptr1 = passStringToWasm0(access, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1918
+ const len1 = WASM_VECTOR_LEN;
1919
+ wasm.meshsession_serve_org_streaming(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(handler), addHeapObject(opts));
1920
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1921
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1922
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1923
+ if (r2) {
1924
+ throw takeObject(r1);
1925
+ }
1926
+ return OrgServeHandle.__wrap(r0);
1927
+ } finally {
1928
+ wasm.__wbindgen_add_to_stack_pointer(16);
1929
+ }
1930
+ }
1931
+ /**
1932
+ * Sign and send a session-independent signalling envelope.
1933
+ * @param {string} peer_hex
1934
+ * @param {string} dialog_hex
1935
+ * @param {string} kind
1936
+ * @param {Uint8Array} payload
1937
+ * @returns {Promise<void>}
1938
+ */
1939
+ signal(peer_hex, dialog_hex, kind, payload) {
1940
+ const ptr0 = passStringToWasm0(peer_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1941
+ const len0 = WASM_VECTOR_LEN;
1942
+ const ptr1 = passStringToWasm0(dialog_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1943
+ const len1 = WASM_VECTOR_LEN;
1944
+ const ptr2 = passStringToWasm0(kind, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1945
+ const len2 = WASM_VECTOR_LEN;
1946
+ const ret = wasm.meshsession_signal(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, addHeapObject(payload));
1947
+ return takeObject(ret);
1948
+ }
1949
+ /**
1950
+ * Subscribe to a channel.
1951
+ *
1952
+ * Recorded as this tab's own declaration, which is what a
1953
+ * successor restores and what an attach carries to a new leader.
1954
+ * @param {string} channel
1955
+ * @returns {Promise<void>}
1956
+ */
1957
+ subscribe(channel) {
1958
+ const ptr0 = passStringToWasm0(channel, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1959
+ const len0 = WASM_VECTOR_LEN;
1960
+ const ret = wasm.meshsession_subscribe(this.__wbg_ptr, ptr0, len0);
1961
+ return takeObject(ret);
1962
+ }
1963
+ /**
1964
+ * Release this tab's claim on a channel.
1965
+ *
1966
+ * The membership itself is given up only when no other tab still
1967
+ * declares the channel: the origin runs one node, and one tab
1968
+ * closing a subscription is not every tab closing it.
1969
+ * @param {string} channel
1970
+ * @returns {Promise<void>}
1971
+ */
1972
+ unsubscribe(channel) {
1973
+ const ptr0 = passStringToWasm0(channel, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1974
+ const len0 = WASM_VECTOR_LEN;
1975
+ const ret = wasm.meshsession_unsubscribe(this.__wbg_ptr, ptr0, len0);
1976
+ return takeObject(ret);
1977
+ }
1978
+ }
1979
+ if (Symbol.dispose) MeshSession.prototype[Symbol.dispose] = MeshSession.prototype.free;
1980
+
1981
+ /**
1982
+ * One org-scoped response stream as JavaScript sees it.
1983
+ *
1984
+ * `next()` resolves `{ done: false, value }`, `{ done: true }` (or
1985
+ * `{ done: true, value }` when the terminal carries a final body),
1986
+ * or `{ done: true, error }` with the typed terminal error — which
1987
+ * the TypeScript wrapper throws at the terminal item, so `for
1988
+ * await` sees a typed rejection. `cancel()` emits exactly one
1989
+ * CANCEL. Deadlines are absolute: a frozen tab gets no lease
1990
+ * extension and an overdue call retires with its deadline terminal;
1991
+ * nothing here ever resumes a retired call.
1992
+ */
1993
+ export class OrgByteStreamHandle {
1994
+ static __wrap(ptr) {
1995
+ const obj = Object.create(OrgByteStreamHandle.prototype);
1996
+ obj.__wbg_ptr = ptr;
1997
+ OrgByteStreamHandleFinalization.register(obj, obj.__wbg_ptr, obj);
1998
+ return obj;
1999
+ }
2000
+ __destroy_into_raw() {
2001
+ const ptr = this.__wbg_ptr;
2002
+ this.__wbg_ptr = 0;
2003
+ OrgByteStreamHandleFinalization.unregister(this);
2004
+ return ptr;
2005
+ }
2006
+ free() {
2007
+ const ptr = this.__destroy_into_raw();
2008
+ wasm.__wbg_orgbytestreamhandle_free(ptr, 0);
2009
+ }
2010
+ /**
2011
+ * Cancel the call. Exactly one CANCEL reaches the provider, and
2012
+ * the terminal is latched locally — dropping this handle later
2013
+ * emits nothing (the exactly-once guard already fired).
2014
+ */
2015
+ cancel() {
2016
+ wasm.orgbytestreamhandle_cancel(this.__wbg_ptr);
2017
+ }
2018
+ /**
2019
+ * The next item, the end of the stream, or the typed terminal
2020
+ * error item.
2021
+ * @returns {Promise<any>}
2022
+ */
2023
+ next() {
2024
+ const ret = wasm.orgbytestreamhandle_next(this.__wbg_ptr);
2025
+ return takeObject(ret);
2026
+ }
2027
+ }
2028
+ if (Symbol.dispose) OrgByteStreamHandle.prototype[Symbol.dispose] = OrgByteStreamHandle.prototype.free;
2029
+
2030
+ /**
2031
+ * One org-scoped duplex call as JavaScript sees it: an inline
2032
+ * upload sink and a response stream over the same call.
2033
+ */
2034
+ export class OrgDuplexCallHandle {
2035
+ static __wrap(ptr) {
2036
+ const obj = Object.create(OrgDuplexCallHandle.prototype);
2037
+ obj.__wbg_ptr = ptr;
2038
+ OrgDuplexCallHandleFinalization.register(obj, obj.__wbg_ptr, obj);
2039
+ return obj;
2040
+ }
2041
+ __destroy_into_raw() {
2042
+ const ptr = this.__wbg_ptr;
2043
+ this.__wbg_ptr = 0;
2044
+ OrgDuplexCallHandleFinalization.unregister(this);
2045
+ return ptr;
2046
+ }
2047
+ free() {
2048
+ const ptr = this.__destroy_into_raw();
2049
+ wasm.__wbg_orgduplexcallhandle_free(ptr, 0);
2050
+ }
2051
+ /**
2052
+ * Cancel the call (one CANCEL, terminal latched).
2053
+ */
2054
+ cancel() {
2055
+ wasm.orgduplexcallhandle_cancel(this.__wbg_ptr);
2056
+ }
2057
+ /**
2058
+ * Half-close the upload direction. The response side stays
2059
+ * open — this is `finishSending`, not a completion.
2060
+ * @returns {Promise<void>}
2061
+ */
2062
+ finish_sending() {
2063
+ const ret = wasm.orgduplexcallhandle_finish_sending(this.__wbg_ptr);
2064
+ return takeObject(ret);
2065
+ }
2066
+ /**
2067
+ * Push one upload item.
2068
+ * @param {Uint8Array} payload
2069
+ * @returns {Promise<void>}
2070
+ */
2071
+ send(payload) {
2072
+ const ret = wasm.orgduplexcallhandle_send(this.__wbg_ptr, addHeapObject(payload));
2073
+ return takeObject(ret);
2074
+ }
2075
+ /**
2076
+ * The response half of this call.
2077
+ *
2078
+ * Every handle this mints shares the call's latched terminal:
2079
+ * each consumer observes the real typed terminal (a
2080
+ * `Retired { Revoked }`, an `AdmissionDenied`, a refusal), never
2081
+ * a fabricated clean completion left for whoever polls second.
2082
+ * @returns {OrgByteStreamHandle}
2083
+ */
2084
+ stream() {
2085
+ const ret = wasm.orgduplexcallhandle_stream(this.__wbg_ptr);
2086
+ return OrgByteStreamHandle.__wrap(ret);
2087
+ }
2088
+ }
2089
+ if (Symbol.dispose) OrgDuplexCallHandle.prototype[Symbol.dispose] = OrgDuplexCallHandle.prototype.free;
2090
+
2091
+ /**
2092
+ * The handler-facing request stream of a client-streaming or duplex
2093
+ * serve.
2094
+ *
2095
+ * # The handler-drop contract (F-S3.1-2)
2096
+ *
2097
+ * The retire supervisor may drop the handler future without a final
2098
+ * poll — cancellation is observed through the retirement
2099
+ * observables (the terminal item, the sink's typed closed refusal,
2100
+ * and `retired`), never assumed as a handler-side event; a detached
2101
+ * observer holding `retired` observes the signal. After retirement
2102
+ * `next` yields nothing more and the handler's return value is
2103
+ * discarded — the terminal was already sent.
2104
+ */
2105
+ export class OrgRequestStreamHandle {
2106
+ static __wrap(ptr) {
2107
+ const obj = Object.create(OrgRequestStreamHandle.prototype);
2108
+ obj.__wbg_ptr = ptr;
2109
+ OrgRequestStreamHandleFinalization.register(obj, obj.__wbg_ptr, obj);
2110
+ return obj;
2111
+ }
2112
+ __destroy_into_raw() {
2113
+ const ptr = this.__wbg_ptr;
2114
+ this.__wbg_ptr = 0;
2115
+ OrgRequestStreamHandleFinalization.unregister(this);
2116
+ return ptr;
2117
+ }
2118
+ free() {
2119
+ const ptr = this.__destroy_into_raw();
2120
+ wasm.__wbg_orgrequeststreamhandle_free(ptr, 0);
2121
+ }
2122
+ /**
2123
+ * The next request item, or `{ done: true }` at the end of the
2124
+ * upload. There is no error arm: a terminated call is observed
2125
+ * through `retired`, and an ended upload is a clean `done`. A
2126
+ * retired call reports `done` — the pull never hangs the
2127
+ * handler (the F-S3.1-2 level).
2128
+ * @returns {Promise<any>}
2129
+ */
2130
+ next() {
2131
+ const ret = wasm.orgrequeststreamhandle_next(this.__wbg_ptr);
2132
+ return takeObject(ret);
2133
+ }
2134
+ /**
2135
+ * The retirement signal — same contract and vocabulary as
2136
+ * [`OrgResponseSinkHandle::retired`].
2137
+ * @returns {Promise<any>}
2138
+ */
2139
+ retired() {
2140
+ const ret = wasm.orgrequeststreamhandle_retired(this.__wbg_ptr);
2141
+ return takeObject(ret);
2142
+ }
2143
+ }
2144
+ if (Symbol.dispose) OrgRequestStreamHandle.prototype[Symbol.dispose] = OrgRequestStreamHandle.prototype.free;
2145
+
2146
+ /**
2147
+ * The handler-facing response sink of a streaming or duplex serve.
2148
+ *
2149
+ * # The handler-drop contract (F-S3.1-2)
2150
+ *
2151
+ * The retire supervisor may drop the handler future without a final
2152
+ * poll — cancellation is observed through the retirement
2153
+ * observables (the terminal item, the sink's typed closed refusal
2154
+ * below, and `retired`), never assumed as a handler-side event; a
2155
+ * detached observer holding `retired` observes the signal. After
2156
+ * retirement `send` and `close` refuse with the typed closed text
2157
+ * and the handler's return value is discarded — the terminal was
2158
+ * already sent.
2159
+ */
2160
+ export class OrgResponseSinkHandle {
2161
+ static __wrap(ptr) {
2162
+ const obj = Object.create(OrgResponseSinkHandle.prototype);
2163
+ obj.__wbg_ptr = ptr;
2164
+ OrgResponseSinkHandleFinalization.register(obj, obj.__wbg_ptr, obj);
2165
+ return obj;
2166
+ }
2167
+ __destroy_into_raw() {
2168
+ const ptr = this.__wbg_ptr;
2169
+ this.__wbg_ptr = 0;
2170
+ OrgResponseSinkHandleFinalization.unregister(this);
2171
+ return ptr;
2172
+ }
2173
+ free() {
2174
+ const ptr = this.__destroy_into_raw();
2175
+ wasm.__wbg_orgresponsesinkhandle_free(ptr, 0);
2176
+ }
2177
+ /**
2178
+ * End the response side successfully. Idempotent: the terminal
2179
+ * frame is sent exactly once whether the handler closed the sink
2180
+ * or simply returned. After retirement this SETTLES with the
2181
+ * typed closed refusal (the F-S3.1-2 level: the promise never
2182
+ * hangs the handler — the terminal was already sent and the
2183
+ * handler's return is discarded).
2184
+ * @returns {Promise<void>}
2185
+ */
2186
+ close() {
2187
+ const ret = wasm.orgresponsesinkhandle_close(this.__wbg_ptr);
2188
+ return takeObject(ret);
2189
+ }
2190
+ /**
2191
+ * The retirement signal: resolves with one of `timeout`,
2192
+ * `cancelled`, `revoked`, `session-lost`, `leader-lost`,
2193
+ * `node-closed`, `replaced` exactly when the call retires. A
2194
+ * call that completes normally never retires, so this promise
2195
+ * stays pending — it is the retirement observable, not a
2196
+ * completion signal.
2197
+ * @returns {Promise<any>}
2198
+ */
2199
+ retired() {
2200
+ const ret = wasm.orgresponsesinkhandle_retired(this.__wbg_ptr);
2201
+ return takeObject(ret);
2202
+ }
2203
+ /**
2204
+ * Push one response item. Refuses (typed) after retirement, and
2205
+ * parks (retries) while the response window has no credit — the
2206
+ * same permit semantics as the caller-side sinks.
2207
+ *
2208
+ * # Settling (the F-S3.1-2 level)
2209
+ *
2210
+ * Once `retired` resolves this promise SETTLES with the typed
2211
+ * closed refusal — a post-retirement `send` never hangs the
2212
+ * handler: it refuses, the handler resolves (or rejects), and
2213
+ * its return value is discarded because the terminal was
2214
+ * already sent.
2215
+ * @param {Uint8Array} payload
2216
+ * @returns {Promise<void>}
2217
+ */
2218
+ send(payload) {
2219
+ const ret = wasm.orgresponsesinkhandle_send(this.__wbg_ptr, addHeapObject(payload));
2220
+ return takeObject(ret);
2221
+ }
2222
+ }
2223
+ if (Symbol.dispose) OrgResponseSinkHandle.prototype[Symbol.dispose] = OrgResponseSinkHandle.prototype.free;
2224
+
2225
+ /**
2226
+ * A registration of one org service.
2227
+ */
2228
+ export class OrgServeHandle {
2229
+ static __wrap(ptr) {
2230
+ const obj = Object.create(OrgServeHandle.prototype);
2231
+ obj.__wbg_ptr = ptr;
2232
+ OrgServeHandleFinalization.register(obj, obj.__wbg_ptr, obj);
2233
+ return obj;
2234
+ }
2235
+ __destroy_into_raw() {
2236
+ const ptr = this.__wbg_ptr;
2237
+ this.__wbg_ptr = 0;
2238
+ OrgServeHandleFinalization.unregister(this);
2239
+ return ptr;
2240
+ }
2241
+ free() {
2242
+ const ptr = this.__destroy_into_raw();
2243
+ wasm.__wbg_orgservehandle_free(ptr, 0);
2244
+ }
2245
+ /**
2246
+ * Close the registration.
2247
+ *
2248
+ * **The protected-path split (C9):** closing an ORG serve
2249
+ * handle retires its live protected calls — each with its exact
2250
+ * retirement terminal — and refuses new openings. This is NOT
2251
+ * the public-path "let existing calls finish" behaviour.
2252
+ */
2253
+ close() {
2254
+ wasm.orgservehandle_close(this.__wbg_ptr);
2255
+ }
2256
+ /**
2257
+ * The service name.
2258
+ * @returns {string}
2259
+ */
2260
+ service() {
2261
+ let deferred1_0;
2262
+ let deferred1_1;
2263
+ try {
2264
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2265
+ wasm.orgservehandle_service(retptr, this.__wbg_ptr);
2266
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2267
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2268
+ deferred1_0 = r0;
2269
+ deferred1_1 = r1;
2270
+ return getStringFromWasm0(r0, r1);
2271
+ } finally {
2272
+ wasm.__wbindgen_add_to_stack_pointer(16);
2273
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
2274
+ }
2275
+ }
2276
+ }
2277
+ if (Symbol.dispose) OrgServeHandle.prototype[Symbol.dispose] = OrgServeHandle.prototype.free;
2278
+
2279
+ /**
2280
+ * One org-scoped client-streaming call as JavaScript sees it.
2281
+ */
2282
+ export class OrgUploadCallHandle {
2283
+ static __wrap(ptr) {
2284
+ const obj = Object.create(OrgUploadCallHandle.prototype);
2285
+ obj.__wbg_ptr = ptr;
2286
+ OrgUploadCallHandleFinalization.register(obj, obj.__wbg_ptr, obj);
2287
+ return obj;
2288
+ }
2289
+ __destroy_into_raw() {
2290
+ const ptr = this.__wbg_ptr;
2291
+ this.__wbg_ptr = 0;
2292
+ OrgUploadCallHandleFinalization.unregister(this);
2293
+ return ptr;
2294
+ }
2295
+ free() {
2296
+ const ptr = this.__destroy_into_raw();
2297
+ wasm.__wbg_orguploadcallhandle_free(ptr, 0);
2298
+ }
2299
+ /**
2300
+ * Cancel the call (one CANCEL, terminal latched).
2301
+ */
2302
+ cancel() {
2303
+ wasm.orguploadcallhandle_cancel(this.__wbg_ptr);
2304
+ }
2305
+ /**
2306
+ * Half-close the upload and await the response body.
2307
+ *
2308
+ * Resolves the terminal body; rejects with the typed terminal
2309
+ * error's `Display` text (an admission denial is
2310
+ * `rpc: refused (9): <coarse>`).
2311
+ * @returns {Promise<Uint8Array>}
2312
+ */
2313
+ finish() {
2314
+ const ret = wasm.orguploadcallhandle_finish(this.__wbg_ptr);
2315
+ return takeObject(ret);
2316
+ }
2317
+ /**
2318
+ * Push one upload item.
2319
+ * @param {Uint8Array} payload
2320
+ * @returns {Promise<void>}
2321
+ */
2322
+ send(payload) {
2323
+ const ret = wasm.orguploadcallhandle_send(this.__wbg_ptr, addHeapObject(payload));
2324
+ return takeObject(ret);
2325
+ }
2326
+ }
2327
+ if (Symbol.dispose) OrgUploadCallHandle.prototype[Symbol.dispose] = OrgUploadCallHandle.prototype.free;
2328
+
2329
+ /**
2330
+ * One application stream, on whichever tab runs the node.
2331
+ *
2332
+ * # Why it remembers its generation
2333
+ *
2334
+ * A stream id names per-session state, and leadership moving means a
2335
+ * new node with a new and independently allocated stream table. A
2336
+ * handle that carried only the id would therefore address *whatever*
2337
+ * stream the successor happened to open with that id — so a retained
2338
+ * object's `send` could push a payload into a stranger's stream and
2339
+ * its `close` could tear that stream down. Carrying the opening
2340
+ * generation makes the handle refuse instead, and the refusal is
2341
+ * typed, because "the leader changed" is an answer a page can act on
2342
+ * and silence is not.
2343
+ *
2344
+ * # Why it remembers a handle *and* an id
2345
+ *
2346
+ * The same argument one level down. Two opens to two peers under one
2347
+ * label share a wire stream id, so the id does not name an open
2348
+ * either: addressing the backend by it let one handle's `send` reach
2349
+ * another peer's stream. The `handle` names the open; the
2350
+ * `stream_id` is what the application filters on; and
2351
+ * [`Self::peer_node_hex`] is what makes that filter a peer filter
2352
+ * rather than a peer-blind one.
2353
+ */
2354
+ export class ProxyStream {
2355
+ static __wrap(ptr) {
2356
+ const obj = Object.create(ProxyStream.prototype);
2357
+ obj.__wbg_ptr = ptr;
2358
+ ProxyStreamFinalization.register(obj, obj.__wbg_ptr, obj);
2359
+ return obj;
2360
+ }
2361
+ __destroy_into_raw() {
2362
+ const ptr = this.__wbg_ptr;
2363
+ this.__wbg_ptr = 0;
2364
+ ProxyStreamFinalization.unregister(this);
2365
+ return ptr;
2366
+ }
2367
+ free() {
2368
+ const ptr = this.__destroy_into_raw();
2369
+ wasm.__wbg_proxystream_free(ptr, 0);
2370
+ }
2371
+ /**
2372
+ * Stop using the stream.
2373
+ *
2374
+ * Not a resurrection point: D2 is explicit that a stream is
2375
+ * session-scoped and is **not** restored across a leader change.
2376
+ * A page whose leader went away opens a new stream — and this
2377
+ * handle refuses to close anything on a successor, because the
2378
+ * stream it named is already gone with the node that owned it.
2379
+ *
2380
+ * The generation is checked twice, and the second one is the one
2381
+ * that matters. This method is synchronous and the request is
2382
+ * not, so the admission check below happens in the caller's turn
2383
+ * while the request is dispatched in a later one: a handoff in
2384
+ * between would have stamped the close as *current* and torn
2385
+ * down whatever stream the successor had opened with this id.
2386
+ * The check at admission stays because it is the one that makes a
2387
+ * stale close cost no task at all.
2388
+ */
2389
+ close() {
2390
+ wasm.proxystream_close(this.__wbg_ptr);
2391
+ }
2392
+ /**
2393
+ * The generation that opened this stream, as a decimal string.
2394
+ * @returns {string}
2395
+ */
2396
+ generation() {
2397
+ let deferred1_0;
2398
+ let deferred1_1;
2399
+ try {
2400
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2401
+ wasm.proxystream_generation(retptr, this.__wbg_ptr);
2402
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2403
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2404
+ deferred1_0 = r0;
2405
+ deferred1_1 = r1;
2406
+ return getStringFromWasm0(r0, r1);
2407
+ } finally {
2408
+ wasm.__wbindgen_add_to_stack_pointer(16);
2409
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
2410
+ }
2411
+ }
2412
+ /**
2413
+ * The incarnation of the session this stream was opened on,
2414
+ * decimal — the spelling the event carries.
2415
+ * @returns {string}
2416
+ */
2417
+ incarnation() {
2418
+ let deferred1_0;
2419
+ let deferred1_1;
2420
+ try {
2421
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2422
+ wasm.proxystream_incarnation(retptr, this.__wbg_ptr);
2423
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2424
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2425
+ deferred1_0 = r0;
2426
+ deferred1_1 = r1;
2427
+ return getStringFromWasm0(r0, r1);
2428
+ } finally {
2429
+ wasm.__wbindgen_add_to_stack_pointer(16);
2430
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
2431
+ }
2432
+ }
2433
+ /**
2434
+ * Whether this stream retransmits.
2435
+ * @returns {boolean}
2436
+ */
2437
+ is_reliable() {
2438
+ const ret = wasm.proxystream_is_reliable(this.__wbg_ptr);
2439
+ return ret !== 0;
2440
+ }
2441
+ /**
2442
+ * Listen for inbound payloads on this stream.
2443
+ *
2444
+ * Filtered from the session's event stream by **both halves of
2445
+ * the key** — the peer and the stream id — which is the same
2446
+ * mechanism and the same event spelling a leader-local stream
2447
+ * uses ([`crate::wasm::LeafStream::on_message`]), so a
2448
+ * follower's stream and a leader's deliver through one path;
2449
+ * **and** by the generation that opened it, so a stale handle's
2450
+ * consumer stops receiving rather than starts receiving a
2451
+ * successor's bytes.
2452
+ *
2453
+ * The peer half was missing here, and the id alone is not the
2454
+ * identity of a stream: two peers under one label share it, so a
2455
+ * proxied consumer received whichever peer's payload arrived.
2456
+ * That is R4-10, on the proxied path.
2457
+ * @param {Function} callback
2458
+ */
2459
+ on_message(callback) {
2460
+ wasm.proxystream_on_message(this.__wbg_ptr, addHeapObject(callback));
2461
+ }
2462
+ /**
2463
+ * The peer this stream is with, 16 lowercase hex digits.
2464
+ *
2465
+ * **Spelled exactly like [`crate::wasm::LeafStream::peer_node_hex`]**
2466
+ * because a consumer must not need to know whether its stream is
2467
+ * direct or proxied to filter by peer. Its absence here was the
2468
+ * R4-10 cross-peer admixture, still open on every proxied handle
2469
+ * — including the leader tab's own `MeshSession`, which wraps the
2470
+ * same `ProxyStream`.
2471
+ * @returns {string}
2472
+ */
2473
+ peer_node_hex() {
2474
+ let deferred1_0;
2475
+ let deferred1_1;
2476
+ try {
2477
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2478
+ wasm.proxystream_peer_node_hex(retptr, this.__wbg_ptr);
2479
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2480
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2481
+ deferred1_0 = r0;
2482
+ deferred1_1 = r1;
2483
+ return getStringFromWasm0(r0, r1);
2484
+ } finally {
2485
+ wasm.__wbindgen_add_to_stack_pointer(16);
2486
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
2487
+ }
2488
+ }
2489
+ /**
2490
+ * Send one payload.
2491
+ *
2492
+ * Refused, typed, once leadership has moved: see the type's own
2493
+ * documentation for why this is not merely an optimisation.
2494
+ *
2495
+ * # What resolving means, and what it does not
2496
+ *
2497
+ * Three dispositions are distinct and only the first is this
2498
+ * promise's:
2499
+ *
2500
+ * 1. **Admission.** Resolving says the node that owns the stream
2501
+ * accepted the bytes and enqueued them — a reliable stream has
2502
+ * taken ownership of them for retransmission, a
2503
+ * fire-and-forget one has queued one packet. That is the
2504
+ * contract, and it is the same one `LeafStream.send` has on
2505
+ * the direct surface.
2506
+ * 2. **Transport refusal.** A DataChannel that refuses the
2507
+ * packet at the flush boundary is reported there
2508
+ * (`crate::wasm::Inner::flush`) and does *not* reject this
2509
+ * promise: the flush happens after admission, on the node's
2510
+ * own pump, and a reliable stream's retransmission is what
2511
+ * answers for it.
2512
+ * 3. **Acknowledgement.** Nothing here waits for one. A reliable
2513
+ * stream's delivery is observable through its peer, not
2514
+ * through the resolution of this call; an unacknowledged
2515
+ * payload is retransmitted, and a stream that exhausts its
2516
+ * retries fails the stream rather than this send.
2517
+ *
2518
+ * A page that needs end-to-end confirmation asks for one in its
2519
+ * own protocol — an nRPC call, or a reply on the stream. Making
2520
+ * this promise wait for an ACK would turn every send into a round
2521
+ * trip and still could not speak for a fire-and-forget stream.
2522
+ * @param {Uint8Array} payload
2523
+ * @returns {Promise<void>}
2524
+ */
2525
+ send(payload) {
2526
+ const ret = wasm.proxystream_send(this.__wbg_ptr, addHeapObject(payload));
2527
+ return takeObject(ret);
2528
+ }
2529
+ /**
2530
+ * The stream id, 16 lowercase hex digits.
2531
+ * @returns {string}
2532
+ */
2533
+ stream_id_hex() {
2534
+ let deferred1_0;
2535
+ let deferred1_1;
2536
+ try {
2537
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2538
+ wasm.proxystream_stream_id_hex(retptr, this.__wbg_ptr);
2539
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2540
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2541
+ deferred1_0 = r0;
2542
+ deferred1_1 = r1;
2543
+ return getStringFromWasm0(r0, r1);
2544
+ } finally {
2545
+ wasm.__wbindgen_add_to_stack_pointer(16);
2546
+ wasm.__wbindgen_export5(deferred1_0, deferred1_1, 1);
2547
+ }
2548
+ }
2549
+ }
2550
+ if (Symbol.dispose) ProxyStream.prototype[Symbol.dispose] = ProxyStream.prototype.free;
2551
+
2552
+ /**
2553
+ * Route panics to `console.error`, so a wasm surprise is legible in
2554
+ * the browser log instead of an opaque `unreachable`.
2555
+ */
2556
+ export function start() {
2557
+ wasm.start();
2558
+ }
2559
+ function __wbg_get_imports() {
2560
+ const import0 = {
2561
+ __proto__: null,
2562
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
2563
+ const ret = Error(getStringFromWasm0(arg0, arg1));
2564
+ return addHeapObject(ret);
2565
+ },
2566
+ __wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
2567
+ const v = getObject(arg0);
2568
+ const ret = typeof(v) === 'boolean' ? v : undefined;
2569
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
2570
+ },
2571
+ __wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
2572
+ const ret = debugString(getObject(arg1));
2573
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2574
+ const len1 = WASM_VECTOR_LEN;
2575
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2576
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2577
+ },
2578
+ __wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
2579
+ const ret = typeof(getObject(arg0)) === 'function';
2580
+ return ret;
2581
+ },
2582
+ __wbg___wbindgen_is_null_e343b7d08827ba72: function(arg0) {
2583
+ const ret = getObject(arg0) === null;
2584
+ return ret;
2585
+ },
2586
+ __wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
2587
+ const val = getObject(arg0);
2588
+ const ret = typeof(val) === 'object' && val !== null;
2589
+ return ret;
2590
+ },
2591
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
2592
+ const ret = getObject(arg0) === undefined;
2593
+ return ret;
2594
+ },
2595
+ __wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
2596
+ const obj = getObject(arg1);
2597
+ const ret = typeof(obj) === 'number' ? obj : undefined;
2598
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
2599
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
2600
+ },
2601
+ __wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
2602
+ const obj = getObject(arg1);
2603
+ const ret = typeof(obj) === 'string' ? obj : undefined;
2604
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2605
+ var len1 = WASM_VECTOR_LEN;
2606
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2607
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2608
+ },
2609
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
2610
+ throw new Error(getStringFromWasm0(arg0, arg1));
2611
+ },
2612
+ __wbg___wbindgen_typeof_e777a26e115d416b: function(arg0) {
2613
+ const ret = typeof getObject(arg0);
2614
+ return addHeapObject(ret);
2615
+ },
2616
+ __wbg__wbg_cb_unref_dcc1a90847f04c41: function(arg0) {
2617
+ getObject(arg0)._wbg_cb_unref();
2618
+ },
2619
+ __wbg_addEventListener_4d0db17c671ea324: function() { return handleError(function (arg0, arg1, arg2, arg3) {
2620
+ getObject(arg0).addEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));
2621
+ }, arguments); },
2622
+ __wbg_addIceCandidate_1a39ed3c2726f129: function(arg0, arg1) {
2623
+ const ret = getObject(arg0).addIceCandidate(getObject(arg1));
2624
+ return addHeapObject(ret);
2625
+ },
2626
+ __wbg_assign_e39d243f5fbe1e2d: function(arg0, arg1) {
2627
+ const ret = Object.assign(getObject(arg0), getObject(arg1));
2628
+ return addHeapObject(ret);
2629
+ },
2630
+ __wbg_bufferedAmount_ffae037ee3ccb36c: function(arg0) {
2631
+ const ret = getObject(arg0).bufferedAmount;
2632
+ return ret;
2633
+ },
2634
+ __wbg_call_1875a20c43a36133: function() { return handleError(function (arg0, arg1, arg2, arg3) {
2635
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3));
2636
+ return addHeapObject(ret);
2637
+ }, arguments); },
2638
+ __wbg_call_187d372bd5fdd4aa: function() { return handleError(function (arg0, arg1, arg2) {
2639
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
2640
+ return addHeapObject(ret);
2641
+ }, arguments); },
2642
+ __wbg_call_6137034ef55c9d0f: function() { return handleError(function (arg0, arg1) {
2643
+ const ret = getObject(arg0).call(getObject(arg1));
2644
+ return addHeapObject(ret);
2645
+ }, arguments); },
2646
+ __wbg_call_939a2607c4484b0b: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
2647
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4));
2648
+ return addHeapObject(ret);
2649
+ }, arguments); },
2650
+ __wbg_candidate_1b46fc7e7e09ff36: function(arg0) {
2651
+ const ret = getObject(arg0).candidate;
2652
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2653
+ },
2654
+ __wbg_candidate_4706058d90edd65c: function(arg0, arg1) {
2655
+ const ret = getObject(arg1).candidate;
2656
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2657
+ const len1 = WASM_VECTOR_LEN;
2658
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2659
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2660
+ },
2661
+ __wbg_channel_10306b5f88617a95: function(arg0) {
2662
+ const ret = getObject(arg0).channel;
2663
+ return addHeapObject(ret);
2664
+ },
2665
+ __wbg_close_35c28c04c6854ad8: function(arg0) {
2666
+ getObject(arg0).close();
2667
+ },
2668
+ __wbg_close_3dbb67f6997e08f5: function(arg0) {
2669
+ getObject(arg0).close();
2670
+ },
2671
+ __wbg_close_d3ed56b5763be5ae: function() { return handleError(function (arg0) {
2672
+ getObject(arg0).close();
2673
+ }, arguments); },
2674
+ __wbg_close_de72eca08cf70e9c: function(arg0) {
2675
+ getObject(arg0).close();
2676
+ },
2677
+ __wbg_code_4cb6dbcfceec1eac: function(arg0) {
2678
+ const ret = getObject(arg0).code;
2679
+ return ret;
2680
+ },
2681
+ __wbg_createAnswer_4565390027b78031: function(arg0) {
2682
+ const ret = getObject(arg0).createAnswer();
2683
+ return addHeapObject(ret);
2684
+ },
2685
+ __wbg_createDataChannel_83caaab3b3db15e4: function(arg0, arg1, arg2, arg3) {
2686
+ const ret = getObject(arg0).createDataChannel(getStringFromWasm0(arg1, arg2), getObject(arg3));
2687
+ return addHeapObject(ret);
2688
+ },
2689
+ __wbg_createObjectStore_84e0f5101158c82d: function() { return handleError(function (arg0, arg1, arg2) {
2690
+ const ret = getObject(arg0).createObjectStore(getStringFromWasm0(arg1, arg2));
2691
+ return addHeapObject(ret);
2692
+ }, arguments); },
2693
+ __wbg_createOffer_419e0ee0d8a14451: function(arg0) {
2694
+ const ret = getObject(arg0).createOffer();
2695
+ return addHeapObject(ret);
2696
+ },
2697
+ __wbg_crypto_d3d085052e9d631f: function() { return handleError(function (arg0) {
2698
+ const ret = getObject(arg0).crypto;
2699
+ return addHeapObject(ret);
2700
+ }, arguments); },
2701
+ __wbg_data_522f7abc70721269: function(arg0) {
2702
+ const ret = getObject(arg0).data;
2703
+ return addHeapObject(ret);
2704
+ },
2705
+ __wbg_decrypt_0e9566ce8284c64c: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
2706
+ const ret = getObject(arg0).decrypt(getObject(arg1), getObject(arg2), getArrayU8FromWasm0(arg3, arg4));
2707
+ return addHeapObject(ret);
2708
+ }, arguments); },
2709
+ __wbg_encrypt_59d97b75fa4a14ef: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
2710
+ const ret = getObject(arg0).encrypt(getObject(arg1), getObject(arg2), getArrayU8FromWasm0(arg3, arg4));
2711
+ return addHeapObject(ret);
2712
+ }, arguments); },
2713
+ __wbg_error_3da0c81bd4184d52: function(arg0) {
2714
+ const ret = getObject(arg0).error;
2715
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2716
+ },
2717
+ __wbg_error_6600aa1ee85a35e4: function(arg0, arg1) {
2718
+ console.error(getStringFromWasm0(arg0, arg1));
2719
+ },
2720
+ __wbg_error_6a23b57453026a47: function() { return handleError(function (arg0) {
2721
+ const ret = getObject(arg0).error;
2722
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2723
+ }, arguments); },
2724
+ __wbg_fetch_4178962c570137ca: function(arg0, arg1, arg2) {
2725
+ const ret = getObject(arg0).fetch(getStringFromWasm0(arg1, arg2));
2726
+ return addHeapObject(ret);
2727
+ },
2728
+ __wbg_fetch_6835957cc060fb0e: function(arg0, arg1) {
2729
+ const ret = getObject(arg0).fetch(getObject(arg1));
2730
+ return addHeapObject(ret);
2731
+ },
2732
+ __wbg_generateKey_33ce40dff5d452da: function() { return handleError(function (arg0, arg1, arg2, arg3) {
2733
+ const ret = getObject(arg0).generateKey(getObject(arg1), arg2 !== 0, getObject(arg3));
2734
+ return addHeapObject(ret);
2735
+ }, arguments); },
2736
+ __wbg_getRandomValues_436a51d0629d84e1: function() { return handleError(function (arg0, arg1) {
2737
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
2738
+ }, arguments); },
2739
+ __wbg_getRandomValues_a608c4436c19407a: function() { return handleError(function (arg0, arg1) {
2740
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
2741
+ }, arguments); },
2742
+ __wbg_get_31af05bd4842a84f: function() { return handleError(function (arg0, arg1) {
2743
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
2744
+ return addHeapObject(ret);
2745
+ }, arguments); },
2746
+ __wbg_get_e06b8725897cb193: function() { return handleError(function (arg0, arg1) {
2747
+ const ret = getObject(arg0).get(getObject(arg1));
2748
+ return addHeapObject(ret);
2749
+ }, arguments); },
2750
+ __wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
2751
+ const ret = getObject(arg0)[arg1 >>> 0];
2752
+ return addHeapObject(ret);
2753
+ },
2754
+ __wbg_iceConnectionState_dbc63bbbe69109ce: function(arg0) {
2755
+ const ret = getObject(arg0).iceConnectionState;
2756
+ return (__wbindgen_enum_RtcIceConnectionState.indexOf(ret) + 1 || 8) - 1;
2757
+ },
2758
+ __wbg_indexedDB_53d75531b7daa0cd: function() { return handleError(function (arg0) {
2759
+ const ret = getObject(arg0).indexedDB;
2760
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2761
+ }, arguments); },
2762
+ __wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
2763
+ let result;
2764
+ try {
2765
+ result = getObject(arg0) instanceof ArrayBuffer;
2766
+ } catch (_) {
2767
+ result = false;
2768
+ }
2769
+ const ret = result;
2770
+ return ret;
2771
+ },
2772
+ __wbg_instanceof_CryptoKey_744e9d2b2b74d8a0: function(arg0) {
2773
+ let result;
2774
+ try {
2775
+ result = getObject(arg0) instanceof CryptoKey;
2776
+ } catch (_) {
2777
+ result = false;
2778
+ }
2779
+ const ret = result;
2780
+ return ret;
2781
+ },
2782
+ __wbg_instanceof_Error_80a725f81f2e102d: function(arg0) {
2783
+ let result;
2784
+ try {
2785
+ result = getObject(arg0) instanceof Error;
2786
+ } catch (_) {
2787
+ result = false;
2788
+ }
2789
+ const ret = result;
2790
+ return ret;
2791
+ },
2792
+ __wbg_instanceof_IdbDatabase_ee9e122a32a24d91: function(arg0) {
2793
+ let result;
2794
+ try {
2795
+ result = getObject(arg0) instanceof IDBDatabase;
2796
+ } catch (_) {
2797
+ result = false;
2798
+ }
2799
+ const ret = result;
2800
+ return ret;
2801
+ },
2802
+ __wbg_instanceof_Object_67a83cdc00c5d141: function(arg0) {
2803
+ let result;
2804
+ try {
2805
+ result = getObject(arg0) instanceof Object;
2806
+ } catch (_) {
2807
+ result = false;
2808
+ }
2809
+ const ret = result;
2810
+ return ret;
2811
+ },
2812
+ __wbg_instanceof_Promise_e1dc6893aa1ece28: function(arg0) {
2813
+ let result;
2814
+ try {
2815
+ result = getObject(arg0) instanceof Promise;
2816
+ } catch (_) {
2817
+ result = false;
2818
+ }
2819
+ const ret = result;
2820
+ return ret;
2821
+ },
2822
+ __wbg_instanceof_Response_b8758567269c30b2: function(arg0) {
2823
+ let result;
2824
+ try {
2825
+ result = getObject(arg0) instanceof Response;
2826
+ } catch (_) {
2827
+ result = false;
2828
+ }
2829
+ const ret = result;
2830
+ return ret;
2831
+ },
2832
+ __wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
2833
+ let result;
2834
+ try {
2835
+ result = getObject(arg0) instanceof Uint8Array;
2836
+ } catch (_) {
2837
+ result = false;
2838
+ }
2839
+ const ret = result;
2840
+ return ret;
2841
+ },
2842
+ __wbg_instanceof_Window_82d71df4eddf88bc: function(arg0) {
2843
+ let result;
2844
+ try {
2845
+ result = getObject(arg0) instanceof Window;
2846
+ } catch (_) {
2847
+ result = false;
2848
+ }
2849
+ const ret = result;
2850
+ return ret;
2851
+ },
2852
+ __wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
2853
+ const ret = Array.isArray(getObject(arg0));
2854
+ return ret;
2855
+ },
2856
+ __wbg_is_4b278c0bd3caba97: function(arg0, arg1) {
2857
+ const ret = Object.is(getObject(arg0), getObject(arg1));
2858
+ return ret;
2859
+ },
2860
+ __wbg_label_53448c0e5b75bad8: function(arg0, arg1) {
2861
+ const ret = getObject(arg1).label;
2862
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2863
+ const len1 = WASM_VECTOR_LEN;
2864
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2865
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2866
+ },
2867
+ __wbg_leafnode_new: function(arg0) {
2868
+ const ret = LeafNode.__wrap(arg0);
2869
+ return addHeapObject(ret);
2870
+ },
2871
+ __wbg_length_7f3c00c40364105e: function(arg0) {
2872
+ const ret = getObject(arg0).length;
2873
+ return ret;
2874
+ },
2875
+ __wbg_length_d4bdea10311bd9cf: function(arg0) {
2876
+ const ret = getObject(arg0).length;
2877
+ return ret;
2878
+ },
2879
+ __wbg_meshsession_new: function(arg0) {
2880
+ const ret = MeshSession.__wrap(arg0);
2881
+ return addHeapObject(ret);
2882
+ },
2883
+ __wbg_message_5f8387f0c32b90a7: function(arg0) {
2884
+ const ret = getObject(arg0).message;
2885
+ return addHeapObject(ret);
2886
+ },
2887
+ __wbg_message_d988ea596c5f5c9a: function(arg0, arg1) {
2888
+ const ret = getObject(arg1).message;
2889
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2890
+ const len1 = WASM_VECTOR_LEN;
2891
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2892
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2893
+ },
2894
+ __wbg_navigator_2156486643462a87: function(arg0) {
2895
+ const ret = getObject(arg0).navigator;
2896
+ return addHeapObject(ret);
2897
+ },
2898
+ __wbg_new_1dbf7428bba60a42: function(arg0) {
2899
+ const ret = new Uint8Array(getObject(arg0));
2900
+ return addHeapObject(ret);
2901
+ },
2902
+ __wbg_new_4059fb0406225e04: function() { return handleError(function (arg0, arg1) {
2903
+ const ret = new WebSocket(getStringFromWasm0(arg0, arg1));
2904
+ return addHeapObject(ret);
2905
+ }, arguments); },
2906
+ __wbg_new_5502aad30c185fc8: function(arg0, arg1) {
2907
+ try {
2908
+ var state0 = {a: arg0, b: arg1};
2909
+ var cb0 = (arg0, arg1) => {
2910
+ const a = state0.a;
2911
+ state0.a = 0;
2912
+ try {
2913
+ return __wasm_bindgen_func_elem_6506(a, state0.b, arg0, arg1);
2914
+ } finally {
2915
+ state0.a = a;
2916
+ }
2917
+ };
2918
+ const ret = new Promise(cb0);
2919
+ return addHeapObject(ret);
2920
+ } finally {
2921
+ state0.a = 0;
2922
+ }
2923
+ },
2924
+ __wbg_new_617a8cdb8bb1130e: function() {
2925
+ const ret = new Object();
2926
+ return addHeapObject(ret);
2927
+ },
2928
+ __wbg_new_83ca405eae412a62: function() { return handleError(function () {
2929
+ const ret = new Headers();
2930
+ return addHeapObject(ret);
2931
+ }, arguments); },
2932
+ __wbg_new_abaf2d49bbf44a41: function() { return handleError(function (arg0, arg1) {
2933
+ const ret = new BroadcastChannel(getStringFromWasm0(arg0, arg1));
2934
+ return addHeapObject(ret);
2935
+ }, arguments); },
2936
+ __wbg_new_b751d7581190b8c6: function() { return handleError(function (arg0) {
2937
+ const ret = new RTCIceCandidate(getObject(arg0));
2938
+ return addHeapObject(ret);
2939
+ }, arguments); },
2940
+ __wbg_new_ee2291f50781bf1d: function() {
2941
+ const ret = new Array();
2942
+ return addHeapObject(ret);
2943
+ },
2944
+ __wbg_new_from_slice_9a868026ffa4208a: function(arg0, arg1) {
2945
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
2946
+ return addHeapObject(ret);
2947
+ },
2948
+ __wbg_new_typed_b01cb72a8af741a3: function(arg0, arg1) {
2949
+ try {
2950
+ var state0 = {a: arg0, b: arg1};
2951
+ var cb0 = (arg0, arg1) => {
2952
+ const a = state0.a;
2953
+ state0.a = 0;
2954
+ try {
2955
+ return __wasm_bindgen_func_elem_6506(a, state0.b, arg0, arg1);
2956
+ } finally {
2957
+ state0.a = a;
2958
+ }
2959
+ };
2960
+ const ret = new Promise(cb0);
2961
+ return addHeapObject(ret);
2962
+ } finally {
2963
+ state0.a = 0;
2964
+ }
2965
+ },
2966
+ __wbg_new_with_configuration_c6d3ab433d0adb73: function() { return handleError(function (arg0) {
2967
+ const ret = new RTCPeerConnection(getObject(arg0));
2968
+ return addHeapObject(ret);
2969
+ }, arguments); },
2970
+ __wbg_new_with_str_and_init_4618dee4e950224f: function() { return handleError(function (arg0, arg1, arg2) {
2971
+ const ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2));
2972
+ return addHeapObject(ret);
2973
+ }, arguments); },
2974
+ __wbg_new_with_str_d969ab40df6f3773: function() { return handleError(function (arg0, arg1, arg2, arg3) {
2975
+ const ret = new WebSocket(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
2976
+ return addHeapObject(ret);
2977
+ }, arguments); },
2978
+ __wbg_now_aa4ccb83129e9e55: function() {
2979
+ const ret = Date.now();
2980
+ return ret;
2981
+ },
2982
+ __wbg_now_d0b7f4bea9f38490: function(arg0) {
2983
+ const ret = getObject(arg0).now();
2984
+ return ret;
2985
+ },
2986
+ __wbg_now_e7c6795a7f81e10f: function(arg0) {
2987
+ const ret = getObject(arg0).now();
2988
+ return ret;
2989
+ },
2990
+ __wbg_objectStore_43178e7a3459e234: function() { return handleError(function (arg0, arg1, arg2) {
2991
+ const ret = getObject(arg0).objectStore(getStringFromWasm0(arg1, arg2));
2992
+ return addHeapObject(ret);
2993
+ }, arguments); },
2994
+ __wbg_ok_125878a7db256ecb: function(arg0) {
2995
+ const ret = getObject(arg0).ok;
2996
+ return ret;
2997
+ },
2998
+ __wbg_open_dbf85f9611885c1b: function() { return handleError(function (arg0, arg1, arg2, arg3) {
2999
+ const ret = getObject(arg0).open(getStringFromWasm0(arg1, arg2), arg3 >>> 0);
3000
+ return addHeapObject(ret);
3001
+ }, arguments); },
3002
+ __wbg_orgbytestreamhandle_new: function(arg0) {
3003
+ const ret = OrgByteStreamHandle.__wrap(arg0);
3004
+ return addHeapObject(ret);
3005
+ },
3006
+ __wbg_orgduplexcallhandle_new: function(arg0) {
3007
+ const ret = OrgDuplexCallHandle.__wrap(arg0);
3008
+ return addHeapObject(ret);
3009
+ },
3010
+ __wbg_orgrequeststreamhandle_new: function(arg0) {
3011
+ const ret = OrgRequestStreamHandle.__wrap(arg0);
3012
+ return addHeapObject(ret);
3013
+ },
3014
+ __wbg_orgresponsesinkhandle_new: function(arg0) {
3015
+ const ret = OrgResponseSinkHandle.__wrap(arg0);
3016
+ return addHeapObject(ret);
3017
+ },
3018
+ __wbg_orguploadcallhandle_new: function(arg0) {
3019
+ const ret = OrgUploadCallHandle.__wrap(arg0);
3020
+ return addHeapObject(ret);
3021
+ },
3022
+ __wbg_parse_0fc53dead14b3b42: function() { return handleError(function (arg0, arg1) {
3023
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
3024
+ return addHeapObject(ret);
3025
+ }, arguments); },
3026
+ __wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
3027
+ const ret = getObject(arg0).performance;
3028
+ return addHeapObject(ret);
3029
+ },
3030
+ __wbg_performance_d0d7b03fc649b694: function(arg0) {
3031
+ const ret = getObject(arg0).performance;
3032
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
3033
+ },
3034
+ __wbg_postMessage_1e2d73aba527c147: function() { return handleError(function (arg0, arg1) {
3035
+ getObject(arg0).postMessage(getObject(arg1));
3036
+ }, arguments); },
3037
+ __wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
3038
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
3039
+ },
3040
+ __wbg_proxystream_new: function(arg0) {
3041
+ const ret = ProxyStream.__wrap(arg0);
3042
+ return addHeapObject(ret);
3043
+ },
3044
+ __wbg_push_2baf45db356cf468: function(arg0, arg1) {
3045
+ const ret = getObject(arg0).push(getObject(arg1));
3046
+ return ret;
3047
+ },
3048
+ __wbg_put_378af428b16ba8f2: function() { return handleError(function (arg0, arg1, arg2) {
3049
+ const ret = getObject(arg0).put(getObject(arg1), getObject(arg2));
3050
+ return addHeapObject(ret);
3051
+ }, arguments); },
3052
+ __wbg_queueMicrotask_9833f9a49df95a49: function(arg0) {
3053
+ const ret = getObject(arg0).queueMicrotask;
3054
+ return addHeapObject(ret);
3055
+ },
3056
+ __wbg_queueMicrotask_a72f977e97f23c5f: function(arg0) {
3057
+ queueMicrotask(getObject(arg0));
3058
+ },
3059
+ __wbg_readyState_418637f3ca14e818: function(arg0) {
3060
+ const ret = getObject(arg0).readyState;
3061
+ return (__wbindgen_enum_RtcDataChannelState.indexOf(ret) + 1 || 5) - 1;
3062
+ },
3063
+ __wbg_readyState_d8514376867e415b: function(arg0) {
3064
+ const ret = getObject(arg0).readyState;
3065
+ return ret;
3066
+ },
3067
+ __wbg_reason_832acaf5f4083b7b: function(arg0, arg1) {
3068
+ const ret = getObject(arg1).reason;
3069
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
3070
+ const len1 = WASM_VECTOR_LEN;
3071
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
3072
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
3073
+ },
3074
+ __wbg_removeEventListener_6e68185345978771: function() { return handleError(function (arg0, arg1, arg2, arg3) {
3075
+ getObject(arg0).removeEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));
3076
+ }, arguments); },
3077
+ __wbg_resolve_0076e10020304ede: function(arg0) {
3078
+ const ret = Promise.resolve(getObject(arg0));
3079
+ return addHeapObject(ret);
3080
+ },
3081
+ __wbg_result_ea60156c5cd4726f: function() { return handleError(function (arg0) {
3082
+ const ret = getObject(arg0).result;
3083
+ return addHeapObject(ret);
3084
+ }, arguments); },
3085
+ __wbg_sdpMid_d5987403d70d0bb8: function(arg0, arg1) {
3086
+ const ret = getObject(arg1).sdpMid;
3087
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
3088
+ var len1 = WASM_VECTOR_LEN;
3089
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
3090
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
3091
+ },
3092
+ __wbg_send_1e2ed35a61efd7fd: function() { return handleError(function (arg0, arg1, arg2) {
3093
+ getObject(arg0).send(getArrayU8FromWasm0(arg1, arg2));
3094
+ }, arguments); },
3095
+ __wbg_send_b5bdd806efe4baf6: function() { return handleError(function (arg0, arg1, arg2) {
3096
+ getObject(arg0).send(getStringFromWasm0(arg1, arg2));
3097
+ }, arguments); },
3098
+ __wbg_setLocalDescription_c44231625d771b55: function(arg0, arg1) {
3099
+ const ret = getObject(arg0).setLocalDescription(getObject(arg1));
3100
+ return addHeapObject(ret);
3101
+ },
3102
+ __wbg_setRemoteDescription_a8fe607f1eef503d: function(arg0, arg1) {
3103
+ const ret = getObject(arg0).setRemoteDescription(getObject(arg1));
3104
+ return addHeapObject(ret);
3105
+ },
3106
+ __wbg_setTimeout_db7bbc18a17e152a: function() { return handleError(function (arg0, arg1, arg2) {
3107
+ const ret = getObject(arg0).setTimeout(getObject(arg1), arg2);
3108
+ return ret;
3109
+ }, arguments); },
3110
+ __wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
3111
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
3112
+ return ret;
3113
+ }, arguments); },
3114
+ __wbg_set_additional_data_u8_array_7749cb01b56105fc: function(arg0, arg1) {
3115
+ getObject(arg0).additionalData = getObject(arg1);
3116
+ },
3117
+ __wbg_set_af5932e3f78b5648: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
3118
+ getObject(arg0).set(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
3119
+ }, arguments); },
3120
+ __wbg_set_binaryType_9a9ed83755a2cba4: function(arg0, arg1) {
3121
+ getObject(arg0).binaryType = __wbindgen_enum_RtcDataChannelType[arg1];
3122
+ },
3123
+ __wbg_set_body_1fb0f1008bfc7df6: function(arg0, arg1) {
3124
+ getObject(arg0).body = getObject(arg1);
3125
+ },
3126
+ __wbg_set_bufferedAmountLowThreshold_86c29a4759e98eb4: function(arg0, arg1) {
3127
+ getObject(arg0).bufferedAmountLowThreshold = arg1 >>> 0;
3128
+ },
3129
+ __wbg_set_candidate_74317261cf6d6fef: function(arg0, arg1, arg2) {
3130
+ getObject(arg0).candidate = getStringFromWasm0(arg1, arg2);
3131
+ },
3132
+ __wbg_set_headers_40ad33dcf016613f: function(arg0, arg1) {
3133
+ getObject(arg0).headers = getObject(arg1);
3134
+ },
3135
+ __wbg_set_ice_servers_0e993347b54c4c75: function(arg0, arg1) {
3136
+ getObject(arg0).iceServers = getObject(arg1);
3137
+ },
3138
+ __wbg_set_iv_u8_array_6eba816b5eed19f2: function(arg0, arg1) {
3139
+ getObject(arg0).iv = getObject(arg1);
3140
+ },
3141
+ __wbg_set_length_8339027b398747a6: function(arg0, arg1) {
3142
+ getObject(arg0).length = arg1;
3143
+ },
3144
+ __wbg_set_max_retransmits_8c9e61eaf9d25b82: function(arg0, arg1) {
3145
+ getObject(arg0).maxRetransmits = arg1;
3146
+ },
3147
+ __wbg_set_method_dcb32343247ec427: function(arg0, arg1, arg2) {
3148
+ getObject(arg0).method = getStringFromWasm0(arg1, arg2);
3149
+ },
3150
+ __wbg_set_name_3de0dd856e76461a: function(arg0, arg1, arg2) {
3151
+ getObject(arg0).name = getStringFromWasm0(arg1, arg2);
3152
+ },
3153
+ __wbg_set_name_d3391bc1a7f05c87: function(arg0, arg1, arg2) {
3154
+ getObject(arg0).name = getStringFromWasm0(arg1, arg2);
3155
+ },
3156
+ __wbg_set_onabort_ce1ccad84ebb2dbd: function(arg0, arg1) {
3157
+ getObject(arg0).onabort = getObject(arg1);
3158
+ },
3159
+ __wbg_set_onbufferedamountlow_66c387e3fa0467ad: function(arg0, arg1) {
3160
+ getObject(arg0).onbufferedamountlow = getObject(arg1);
3161
+ },
3162
+ __wbg_set_onclose_a84370531f3d2948: function(arg0, arg1) {
3163
+ getObject(arg0).onclose = getObject(arg1);
3164
+ },
3165
+ __wbg_set_oncomplete_14cd563f5d15546c: function(arg0, arg1) {
3166
+ getObject(arg0).oncomplete = getObject(arg1);
3167
+ },
3168
+ __wbg_set_ondatachannel_790664cc7b5b1a77: function(arg0, arg1) {
3169
+ getObject(arg0).ondatachannel = getObject(arg1);
3170
+ },
3171
+ __wbg_set_onerror_00facdd255f06ed6: function(arg0, arg1) {
3172
+ getObject(arg0).onerror = getObject(arg1);
3173
+ },
3174
+ __wbg_set_onerror_24dddc0e8dc54601: function(arg0, arg1) {
3175
+ getObject(arg0).onerror = getObject(arg1);
3176
+ },
3177
+ __wbg_set_onicecandidate_d5e1ae20949a49ef: function(arg0, arg1) {
3178
+ getObject(arg0).onicecandidate = getObject(arg1);
3179
+ },
3180
+ __wbg_set_oniceconnectionstatechange_2b99e504c1f51e83: function(arg0, arg1) {
3181
+ getObject(arg0).oniceconnectionstatechange = getObject(arg1);
3182
+ },
3183
+ __wbg_set_onmessage_b1a84cbc1fe48890: function(arg0, arg1) {
3184
+ getObject(arg0).onmessage = getObject(arg1);
3185
+ },
3186
+ __wbg_set_onmessage_cb6f77d2d8e0402a: function(arg0, arg1) {
3187
+ getObject(arg0).onmessage = getObject(arg1);
3188
+ },
3189
+ __wbg_set_onmessage_d83a0d6439238156: function(arg0, arg1) {
3190
+ getObject(arg0).onmessage = getObject(arg1);
3191
+ },
3192
+ __wbg_set_onopen_c914147e8a2db4b0: function(arg0, arg1) {
3193
+ getObject(arg0).onopen = getObject(arg1);
3194
+ },
3195
+ __wbg_set_onsuccess_e970bffc8d0e7520: function(arg0, arg1) {
3196
+ getObject(arg0).onsuccess = getObject(arg1);
3197
+ },
3198
+ __wbg_set_onupgradeneeded_f9d42df70899331b: function(arg0, arg1) {
3199
+ getObject(arg0).onupgradeneeded = getObject(arg1);
3200
+ },
3201
+ __wbg_set_ordered_c53f7b89fc9fb3b8: function(arg0, arg1) {
3202
+ getObject(arg0).ordered = arg1 !== 0;
3203
+ },
3204
+ __wbg_set_sdp_efdff02bfd21fa09: function(arg0, arg1, arg2) {
3205
+ getObject(arg0).sdp = getStringFromWasm0(arg1, arg2);
3206
+ },
3207
+ __wbg_set_sdp_m_line_index_90d020b194b40483: function(arg0, arg1) {
3208
+ getObject(arg0).sdpMLineIndex = arg1 === 0xFFFFFF ? undefined : arg1;
3209
+ },
3210
+ __wbg_set_sdp_mid_629236bd379fcb1e: function(arg0, arg1, arg2) {
3211
+ getObject(arg0).sdpMid = arg1 === 0 ? undefined : getStringFromWasm0(arg1, arg2);
3212
+ },
3213
+ __wbg_set_type_6507077b45f3a9a5: function(arg0, arg1) {
3214
+ getObject(arg0).type = __wbindgen_enum_RtcSdpType[arg1];
3215
+ },
3216
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
3217
+ const ret = typeof global === 'undefined' ? null : global;
3218
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
3219
+ },
3220
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
3221
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
3222
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
3223
+ },
3224
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
3225
+ const ret = typeof self === 'undefined' ? null : self;
3226
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
3227
+ },
3228
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
3229
+ const ret = typeof window === 'undefined' ? null : window;
3230
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
3231
+ },
3232
+ __wbg_status_ce0a98d3c57125f3: function(arg0) {
3233
+ const ret = getObject(arg0).status;
3234
+ return ret;
3235
+ },
3236
+ __wbg_subtle_fd9b8e4f931c4961: function(arg0) {
3237
+ const ret = getObject(arg0).subtle;
3238
+ return addHeapObject(ret);
3239
+ },
3240
+ __wbg_text_ff3f476b3d6b1246: function() { return handleError(function (arg0) {
3241
+ const ret = getObject(arg0).text();
3242
+ return addHeapObject(ret);
3243
+ }, arguments); },
3244
+ __wbg_then_c949d5a25a4e78f8: function(arg0, arg1, arg2) {
3245
+ const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
3246
+ return addHeapObject(ret);
3247
+ },
3248
+ __wbg_then_e71170d78fcf8954: function(arg0, arg1) {
3249
+ const ret = getObject(arg0).then(getObject(arg1));
3250
+ return addHeapObject(ret);
3251
+ },
3252
+ __wbg_transaction_397c4619233ad8f5: function() { return handleError(function (arg0, arg1, arg2) {
3253
+ const ret = getObject(arg0).transaction(getStringFromWasm0(arg1, arg2));
3254
+ return addHeapObject(ret);
3255
+ }, arguments); },
3256
+ __wbg_transaction_55a3a4e0134a0fd6: function() { return handleError(function (arg0, arg1, arg2, arg3) {
3257
+ const ret = getObject(arg0).transaction(getStringFromWasm0(arg1, arg2), __wbindgen_enum_IdbTransactionMode[arg3]);
3258
+ return addHeapObject(ret);
3259
+ }, arguments); },
3260
+ __wbg_warn_13abc63e0d4b3527: function(arg0) {
3261
+ console.warn(getObject(arg0));
3262
+ },
3263
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
3264
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 33, ret: Externref, inner_ret: Some(Externref) }, mutable: true }) -> Externref`.
3265
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2355);
3266
+ return addHeapObject(ret);
3267
+ },
3268
+ __wbindgen_generic_0000000000000002: function(arg0, arg1) {
3269
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 34, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3270
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2356);
3271
+ return addHeapObject(ret);
3272
+ },
3273
+ __wbindgen_generic_0000000000000003: function(arg0, arg1) {
3274
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 896, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
3275
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_6504);
3276
+ return addHeapObject(ret);
3277
+ },
3278
+ __wbindgen_generic_0000000000000004: function(arg0, arg1) {
3279
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("CloseEvent")], shim_idx: 34, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3280
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2356_112);
3281
+ return addHeapObject(ret);
3282
+ },
3283
+ __wbindgen_generic_0000000000000005: function(arg0, arg1) {
3284
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 34, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3285
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2356_113);
3286
+ return addHeapObject(ret);
3287
+ },
3288
+ __wbindgen_generic_0000000000000006: function(arg0, arg1) {
3289
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 34, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3290
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2356_114);
3291
+ return addHeapObject(ret);
3292
+ },
3293
+ __wbindgen_generic_0000000000000007: function(arg0, arg1) {
3294
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("RTCDataChannelEvent")], shim_idx: 34, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3295
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2356_115);
3296
+ return addHeapObject(ret);
3297
+ },
3298
+ __wbindgen_generic_0000000000000008: function(arg0, arg1) {
3299
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("RTCPeerConnectionIceEvent")], shim_idx: 34, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3300
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2356_116);
3301
+ return addHeapObject(ret);
3302
+ },
3303
+ __wbindgen_generic_0000000000000009: function(arg0) {
3304
+ // Cast intrinsic for `F64 -> Externref`.
3305
+ const ret = arg0;
3306
+ return addHeapObject(ret);
3307
+ },
3308
+ __wbindgen_generic_000000000000000a: function(arg0, arg1) {
3309
+ // Cast intrinsic for `Ref(String) -> Externref`.
3310
+ const ret = getStringFromWasm0(arg0, arg1);
3311
+ return addHeapObject(ret);
3312
+ },
3313
+ __wbindgen_object_clone_ref: function(arg0) {
3314
+ const ret = getObject(arg0);
3315
+ return addHeapObject(ret);
3316
+ },
3317
+ __wbindgen_object_drop_ref: function(arg0) {
3318
+ takeObject(arg0);
3319
+ },
3320
+ };
3321
+ return {
3322
+ __proto__: null,
3323
+ "./net_leaf_bg.js": import0,
3324
+ };
3325
+ }
3326
+
3327
+ function __wasm_bindgen_func_elem_2356(arg0, arg1, arg2) {
3328
+ wasm.__wasm_bindgen_func_elem_2356(arg0, arg1, addHeapObject(arg2));
3329
+ }
3330
+
3331
+ function __wasm_bindgen_func_elem_2356_112(arg0, arg1, arg2) {
3332
+ wasm.__wasm_bindgen_func_elem_2356_112(arg0, arg1, addHeapObject(arg2));
3333
+ }
3334
+
3335
+ function __wasm_bindgen_func_elem_2356_113(arg0, arg1, arg2) {
3336
+ wasm.__wasm_bindgen_func_elem_2356_113(arg0, arg1, addHeapObject(arg2));
3337
+ }
3338
+
3339
+ function __wasm_bindgen_func_elem_2356_114(arg0, arg1, arg2) {
3340
+ wasm.__wasm_bindgen_func_elem_2356_114(arg0, arg1, addHeapObject(arg2));
3341
+ }
3342
+
3343
+ function __wasm_bindgen_func_elem_2356_115(arg0, arg1, arg2) {
3344
+ wasm.__wasm_bindgen_func_elem_2356_115(arg0, arg1, addHeapObject(arg2));
3345
+ }
3346
+
3347
+ function __wasm_bindgen_func_elem_2356_116(arg0, arg1, arg2) {
3348
+ wasm.__wasm_bindgen_func_elem_2356_116(arg0, arg1, addHeapObject(arg2));
3349
+ }
3350
+
3351
+ function __wasm_bindgen_func_elem_2355(arg0, arg1, arg2) {
3352
+ const ret = wasm.__wasm_bindgen_func_elem_2355(arg0, arg1, addHeapObject(arg2));
3353
+ return takeObject(ret);
3354
+ }
3355
+
3356
+ function __wasm_bindgen_func_elem_6506(arg0, arg1, arg2, arg3) {
3357
+ wasm.__wasm_bindgen_func_elem_6506(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
3358
+ }
3359
+
3360
+ function __wasm_bindgen_func_elem_6504(arg0, arg1, arg2) {
3361
+ try {
3362
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
3363
+ wasm.__wasm_bindgen_func_elem_6504(retptr, arg0, arg1, addHeapObject(arg2));
3364
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
3365
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
3366
+ if (r1) {
3367
+ throw takeObject(r0);
3368
+ }
3369
+ } finally {
3370
+ wasm.__wbindgen_add_to_stack_pointer(16);
3371
+ }
3372
+ }
3373
+
3374
+
3375
+ const __wbindgen_enum_IdbTransactionMode = ["readonly", "readwrite", "versionchange", "readwriteflush", "cleanup"];
3376
+
3377
+
3378
+ const __wbindgen_enum_RtcDataChannelState = ["connecting", "open", "closing", "closed"];
3379
+
3380
+
3381
+ const __wbindgen_enum_RtcDataChannelType = ["arraybuffer", "blob"];
3382
+
3383
+
3384
+ const __wbindgen_enum_RtcIceConnectionState = ["new", "checking", "connected", "completed", "failed", "disconnected", "closed"];
3385
+
3386
+
3387
+ const __wbindgen_enum_RtcSdpType = ["offer", "pranswer", "answer", "rollback"];
3388
+ const LeafNodeFinalization = (typeof FinalizationRegistry === 'undefined')
3389
+ ? { register: () => {}, unregister: () => {} }
3390
+ : new FinalizationRegistry(ptr => wasm.__wbg_leafnode_free(ptr, 1));
3391
+ const LeafStreamFinalization = (typeof FinalizationRegistry === 'undefined')
3392
+ ? { register: () => {}, unregister: () => {} }
3393
+ : new FinalizationRegistry(ptr => wasm.__wbg_leafstream_free(ptr, 1));
3394
+ const MeshSessionFinalization = (typeof FinalizationRegistry === 'undefined')
3395
+ ? { register: () => {}, unregister: () => {} }
3396
+ : new FinalizationRegistry(ptr => wasm.__wbg_meshsession_free(ptr, 1));
3397
+ const OrgByteStreamHandleFinalization = (typeof FinalizationRegistry === 'undefined')
3398
+ ? { register: () => {}, unregister: () => {} }
3399
+ : new FinalizationRegistry(ptr => wasm.__wbg_orgbytestreamhandle_free(ptr, 1));
3400
+ const OrgDuplexCallHandleFinalization = (typeof FinalizationRegistry === 'undefined')
3401
+ ? { register: () => {}, unregister: () => {} }
3402
+ : new FinalizationRegistry(ptr => wasm.__wbg_orgduplexcallhandle_free(ptr, 1));
3403
+ const OrgRequestStreamHandleFinalization = (typeof FinalizationRegistry === 'undefined')
3404
+ ? { register: () => {}, unregister: () => {} }
3405
+ : new FinalizationRegistry(ptr => wasm.__wbg_orgrequeststreamhandle_free(ptr, 1));
3406
+ const OrgResponseSinkHandleFinalization = (typeof FinalizationRegistry === 'undefined')
3407
+ ? { register: () => {}, unregister: () => {} }
3408
+ : new FinalizationRegistry(ptr => wasm.__wbg_orgresponsesinkhandle_free(ptr, 1));
3409
+ const OrgServeHandleFinalization = (typeof FinalizationRegistry === 'undefined')
3410
+ ? { register: () => {}, unregister: () => {} }
3411
+ : new FinalizationRegistry(ptr => wasm.__wbg_orgservehandle_free(ptr, 1));
3412
+ const OrgUploadCallHandleFinalization = (typeof FinalizationRegistry === 'undefined')
3413
+ ? { register: () => {}, unregister: () => {} }
3414
+ : new FinalizationRegistry(ptr => wasm.__wbg_orguploadcallhandle_free(ptr, 1));
3415
+ const ProxyStreamFinalization = (typeof FinalizationRegistry === 'undefined')
3416
+ ? { register: () => {}, unregister: () => {} }
3417
+ : new FinalizationRegistry(ptr => wasm.__wbg_proxystream_free(ptr, 1));
3418
+
3419
+ function addHeapObject(obj) {
3420
+ if (heap_next === heap.length) heap.push(heap.length + 1);
3421
+ const idx = heap_next;
3422
+ heap_next = heap[idx];
3423
+
3424
+ heap[idx] = obj;
3425
+ return idx;
3426
+ }
3427
+
3428
+ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
3429
+ ? { register: () => {}, unregister: () => {} }
3430
+ : new FinalizationRegistry(state => wasm.__wbindgen_export4(state.a, state.b));
3431
+
3432
+ function debugString(val) {
3433
+ // primitive types
3434
+ const type = typeof val;
3435
+ if (type == 'number' || type == 'boolean' || val == null) {
3436
+ return `${val}`;
3437
+ }
3438
+ if (type == 'string') {
3439
+ return `"${val}"`;
3440
+ }
3441
+ if (type == 'symbol') {
3442
+ const description = val.description;
3443
+ if (description == null) {
3444
+ return 'Symbol';
3445
+ } else {
3446
+ return `Symbol(${description})`;
3447
+ }
3448
+ }
3449
+ if (type == 'function') {
3450
+ const name = val.name;
3451
+ if (typeof name == 'string' && name.length > 0) {
3452
+ return `Function(${name})`;
3453
+ } else {
3454
+ return 'Function';
3455
+ }
3456
+ }
3457
+ // objects
3458
+ if (Array.isArray(val)) {
3459
+ const length = val.length;
3460
+ let debug = '[';
3461
+ if (length > 0) {
3462
+ debug += debugString(val[0]);
3463
+ }
3464
+ for(let i = 1; i < length; i++) {
3465
+ debug += ', ' + debugString(val[i]);
3466
+ }
3467
+ debug += ']';
3468
+ return debug;
3469
+ }
3470
+ // Test for built-in
3471
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
3472
+ let className;
3473
+ if (builtInMatches && builtInMatches.length > 1) {
3474
+ className = builtInMatches[1];
3475
+ } else {
3476
+ // Failed to match the standard '[object ClassName]'
3477
+ return toString.call(val);
3478
+ }
3479
+ if (className == 'Object') {
3480
+ // we're a user defined class or Object
3481
+ // JSON.stringify avoids problems with cycles, and is generally much
3482
+ // easier than looping through ownProperties of `val`.
3483
+ try {
3484
+ return 'Object(' + JSON.stringify(val) + ')';
3485
+ } catch (_) {
3486
+ return 'Object';
3487
+ }
3488
+ }
3489
+ // errors
3490
+ if (val instanceof Error) {
3491
+ return `${val.name}: ${val.message}\n${val.stack}`;
3492
+ }
3493
+ // TODO we could test for more things here, like `Set`s and `Map`s.
3494
+ return className;
3495
+ }
3496
+
3497
+ function dropObject(idx) {
3498
+ if (idx < 1028) return;
3499
+ heap[idx] = heap_next;
3500
+ heap_next = idx;
3501
+ }
3502
+
3503
+ function getArrayU8FromWasm0(ptr, len) {
3504
+ ptr = ptr >>> 0;
3505
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
3506
+ }
3507
+
3508
+ let cachedDataViewMemory0 = null;
3509
+ function getDataViewMemory0() {
3510
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
3511
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
3512
+ }
3513
+ return cachedDataViewMemory0;
3514
+ }
3515
+
3516
+ function getStringFromWasm0(ptr, len) {
3517
+ return decodeText(ptr >>> 0, len);
3518
+ }
3519
+
3520
+ let cachedUint8ArrayMemory0 = null;
3521
+ function getUint8ArrayMemory0() {
3522
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
3523
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
3524
+ }
3525
+ return cachedUint8ArrayMemory0;
3526
+ }
3527
+
3528
+ function getObject(idx) { return heap[idx]; }
3529
+
3530
+ function handleError(f, args) {
3531
+ try {
3532
+ return f.apply(this, args);
3533
+ } catch (e) {
3534
+ wasm.__wbindgen_export3(addHeapObject(e));
3535
+ }
3536
+ }
3537
+
3538
+ let heap = new Array(1024).fill(undefined);
3539
+ heap.push(undefined, null, true, false);
3540
+
3541
+ let heap_next = heap.length;
3542
+
3543
+ function isLikeNone(x) {
3544
+ return x === undefined || x === null;
3545
+ }
3546
+
3547
+ function makeMutClosure(arg0, arg1, f) {
3548
+ const state = { a: arg0, b: arg1, cnt: 1 };
3549
+ const real = (...args) => {
3550
+
3551
+ // First up with a closure we increment the internal reference
3552
+ // count. This ensures that the Rust closure environment won't
3553
+ // be deallocated while we're invoking it.
3554
+ state.cnt++;
3555
+ const a = state.a;
3556
+ state.a = 0;
3557
+ try {
3558
+ return f(a, state.b, ...args);
3559
+ } finally {
3560
+ state.a = a;
3561
+ real._wbg_cb_unref();
3562
+ }
3563
+ };
3564
+ real._wbg_cb_unref = () => {
3565
+ if (--state.cnt === 0) {
3566
+ wasm.__wbindgen_export4(state.a, state.b);
3567
+ state.a = 0;
3568
+ CLOSURE_DTORS.unregister(state);
3569
+ }
3570
+ };
3571
+ CLOSURE_DTORS.register(real, state, state);
3572
+ return real;
3573
+ }
3574
+
3575
+ function passArrayJsValueToWasm0(array, malloc) {
3576
+ const ptr = malloc(array.length * 4, 4) >>> 0;
3577
+ const mem = getDataViewMemory0();
3578
+ for (let i = 0; i < array.length; i++) {
3579
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
3580
+ }
3581
+ WASM_VECTOR_LEN = array.length;
3582
+ return ptr;
3583
+ }
3584
+
3585
+ function passStringToWasm0(arg, malloc, realloc) {
3586
+ if (realloc === undefined) {
3587
+ const buf = cachedTextEncoder.encode(arg);
3588
+ const ptr = malloc(buf.length, 1) >>> 0;
3589
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
3590
+ WASM_VECTOR_LEN = buf.length;
3591
+ return ptr;
3592
+ }
3593
+
3594
+ let len = arg.length;
3595
+ let ptr = malloc(len, 1) >>> 0;
3596
+
3597
+ const mem = getUint8ArrayMemory0();
3598
+
3599
+ let offset = 0;
3600
+
3601
+ for (; offset < len; offset++) {
3602
+ const code = arg.charCodeAt(offset);
3603
+ if (code > 0x7F) break;
3604
+ mem[ptr + offset] = code;
3605
+ }
3606
+ if (offset !== len) {
3607
+ if (offset !== 0) {
3608
+ arg = arg.slice(offset);
3609
+ }
3610
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
3611
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
3612
+ const ret = cachedTextEncoder.encodeInto(arg, view);
3613
+
3614
+ offset += ret.written;
3615
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
3616
+ }
3617
+
3618
+ WASM_VECTOR_LEN = offset;
3619
+ return ptr;
3620
+ }
3621
+
3622
+ function takeObject(idx) {
3623
+ const ret = getObject(idx);
3624
+ dropObject(idx);
3625
+ return ret;
3626
+ }
3627
+
3628
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
3629
+ cachedTextDecoder.decode();
3630
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
3631
+ let numBytesDecoded = 0;
3632
+ function decodeText(ptr, len) {
3633
+ numBytesDecoded += len;
3634
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
3635
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
3636
+ cachedTextDecoder.decode();
3637
+ numBytesDecoded = len;
3638
+ }
3639
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
3640
+ }
3641
+
3642
+ const cachedTextEncoder = new TextEncoder();
3643
+
3644
+ if (!('encodeInto' in cachedTextEncoder)) {
3645
+ cachedTextEncoder.encodeInto = function (arg, view) {
3646
+ const buf = cachedTextEncoder.encode(arg);
3647
+ view.set(buf);
3648
+ return {
3649
+ read: arg.length,
3650
+ written: buf.length
3651
+ };
3652
+ };
3653
+ }
3654
+
3655
+ let WASM_VECTOR_LEN = 0;
3656
+
3657
+ let wasmModule, wasmInstance, wasm;
3658
+ function __wbg_finalize_init(instance, module) {
3659
+ wasmInstance = instance;
3660
+ wasm = instance.exports;
3661
+ wasmModule = module;
3662
+ cachedDataViewMemory0 = null;
3663
+ cachedUint8ArrayMemory0 = null;
3664
+ wasm.__wbindgen_start();
3665
+ return wasm;
3666
+ }
3667
+
3668
+ async function __wbg_load(module, imports) {
3669
+ if (typeof Response === 'function' && module instanceof Response) {
3670
+ if (!module.ok) {
3671
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
3672
+ }
3673
+
3674
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
3675
+ try {
3676
+ return await WebAssembly.instantiateStreaming(module, imports);
3677
+ } catch (e) {
3678
+ const validResponse = expectedResponseType(module.type);
3679
+
3680
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
3681
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
3682
+
3683
+ } else { throw e; }
3684
+ }
3685
+ }
3686
+
3687
+ const bytes = await module.arrayBuffer();
3688
+ return await WebAssembly.instantiate(bytes, imports);
3689
+ } else {
3690
+ const instance = await WebAssembly.instantiate(module, imports);
3691
+
3692
+ if (instance instanceof WebAssembly.Instance) {
3693
+ return { instance, module };
3694
+ } else {
3695
+ return instance;
3696
+ }
3697
+ }
3698
+
3699
+ function expectedResponseType(type) {
3700
+ switch (type) {
3701
+ case 'basic': case 'cors': case 'default': return true;
3702
+ }
3703
+ return false;
3704
+ }
3705
+ }
3706
+
3707
+ function initSync(module) {
3708
+ if (wasm !== undefined) return wasm;
3709
+
3710
+
3711
+ if (module !== undefined) {
3712
+ if (Object.getPrototypeOf(module) === Object.prototype) {
3713
+ ({module} = module)
3714
+ } else {
3715
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
3716
+ }
3717
+ }
3718
+
3719
+ const imports = __wbg_get_imports();
3720
+ if (!(module instanceof WebAssembly.Module)) {
3721
+ module = new WebAssembly.Module(module);
3722
+ }
3723
+ const instance = new WebAssembly.Instance(module, imports);
3724
+ return __wbg_finalize_init(instance, module);
3725
+ }
3726
+
3727
+ async function __wbg_init(module_or_path) {
3728
+ if (wasm !== undefined) return wasm;
3729
+
3730
+
3731
+ if (module_or_path !== undefined) {
3732
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
3733
+ ({module_or_path} = module_or_path)
3734
+ } else {
3735
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
3736
+ }
3737
+ }
3738
+
3739
+ if (module_or_path === undefined) {
3740
+ module_or_path = new URL('net_leaf_bg.wasm', import.meta.url);
3741
+ }
3742
+ const imports = __wbg_get_imports();
3743
+
3744
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
3745
+ module_or_path = fetch(module_or_path);
3746
+ }
3747
+
3748
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
3749
+
3750
+ return __wbg_finalize_init(instance, module);
3751
+ }
3752
+
3753
+ export { initSync, __wbg_init as default };