@cero-base/cero 3.4.1 → 3.6.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.
@@ -2,6 +2,8 @@ import { t, schema } from '../lib/spec.js';
2
2
  import * as operators from '../lib/operators.js';
3
3
  export * from './profile-sync.js';
4
4
  export * from './handle-sync.js';
5
+ export * from './pulse.js';
6
+ export { calls } from './calls.js';
5
7
  export { t, schema };
6
8
  export * from '../lib/operators.js';
7
9
  export declare const cero: {
@@ -47,7 +49,16 @@ export declare const cero: {
47
49
  }, reason?: string): Promise<void>;
48
50
  removed(ctx: operators.Context, id: string): Promise<'removed' | 'left' | null>;
49
51
  leave(ctx: operators.Context): Promise<void>;
50
- close(ctx: operators.Context): Promise<void>;
52
+ close(ctx: operators.Context | operators.Line): Promise<void>;
53
+ dial(room: operators.Context, opts?: {
54
+ to?: string[];
55
+ stream?: MediaStream;
56
+ }): Promise<operators.Line>;
57
+ share(target: operators.Line | operators.Ref, stream: MediaStream): Promise<void>;
58
+ unshare(target: operators.Line | operators.Ref): Promise<void>;
59
+ end(line: operators.Line): Promise<void>;
60
+ mute(lane: operators.Ref): Promise<void>;
61
+ unmute(lane: operators.Ref): Promise<void>;
51
62
  cancel(me: operators.Context, code: string): Promise<boolean>;
52
63
  suspend(me: operators.Context): Promise<void>;
53
64
  resume(me: operators.Context): Promise<void>;
@@ -108,9 +119,9 @@ export declare const cero: {
108
119
  export type Extension = {
109
120
  name?: string;
110
121
  /**
111
- * Refs to add, or `t.extend` on a builtin, nested by handle type like the app schema.
122
+ * Refs to add, or `t.extend` on a builtin, nested by handle type like the app schema; a function gets the app's handle types and returns them.
112
123
  */
113
- schema?: Record<string, object>;
124
+ schema?: Record<string, object> | ((types: string[]) => Record<string, object>);
114
125
  /**
115
126
  * Runs before the root opens; a returned function runs on close.
116
127
  */
@@ -119,7 +130,7 @@ export type Extension = {
119
130
  /**
120
131
  * @typedef {object} Extension
121
132
  * @property {string} [name]
122
- * @property {Record<string, object>} [schema] Refs to add, or `t.extend` on a builtin, nested by handle type like the app schema.
133
+ * @property {Record<string, object> | ((types: string[]) => Record<string, object>)} [schema] Refs to add, or `t.extend` on a builtin, nested by handle type like the app schema; a function gets the app's handle types and returns them.
123
134
  * @property {(me: import('../handle/index.js').Context) => void | (() => void) | Promise<void | (() => void)>} [setup] Runs before the root opens; a returned function runs on close.
124
135
  */
125
136
  /** The two every app gets unless its build names a list. */
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Hear through a pulse service when another device writes in a handle you are in, closed here too,
3
+ * and wake that handle so it syncs, without the app opening it. A best effort: a notice may come
4
+ * late or twice. Declares `local.pulses`, a row per handle id: `heard`, the local time a write from
5
+ * another device last landed here, 0 before the first; and what pulse keeps for itself: `told`,
6
+ * `owed`, `since` and `epoch`.
7
+ *
8
+ * @param {string | Uint8Array} [key] The service's public key, as it prints it. The build needs none.
9
+ * @returns {import('./index.js').Extension}
10
+ */
11
+ export declare function pulse(key?: string | Uint8Array): import('./index.js').Extension;
@@ -34,6 +34,10 @@ export type HandleOpts = {
34
34
  * Root only, and required there: the device store for handle keypairs and mail.
35
35
  */
36
36
  local?: Local;
37
+ /**
38
+ * Root only: the device's mailbox, its boxes in `local`, open before the network.
39
+ */
40
+ mailbox?: Mailbox;
37
41
  /**
38
42
  * Owned HypercoreStorage to close on shutdown.
39
43
  */
@@ -124,6 +128,7 @@ export type Context = Handle & Record<string, import('../lib/refs.js').Ref>;
124
128
  * @property {import('corestore')} [store] Pre-existing Corestore. Falls back to `parent.store.store`.
125
129
  * @property {Spec} [spec] Built cero spec.
126
130
  * @property {Local} [local] Root only, and required there: the device store for handle keypairs and mail.
131
+ * @property {Mailbox} [mailbox] Root only: the device's mailbox, its boxes in `local`, open before the network.
127
132
  * @property {import('hypercore-storage')} [storage] Owned HypercoreStorage to close on shutdown.
128
133
  * @property {{ destroy(): Promise<void> }} [discovery] Owned identity discovery to destroy on shutdown.
129
134
  * @property {string} [dir] Data directory (root handles only).
@@ -232,6 +237,8 @@ export declare class Handle extends ReadyResource {
232
237
  _tellers;
233
238
  /** @private */
234
239
  _retell;
240
+ /** @private @type {import('../extensions/calls.js').Calls | null} */
241
+ _calls;
235
242
  store: Database;
236
243
  /** @private */
237
244
  _pair;
@@ -322,6 +329,8 @@ export declare class Handle extends ReadyResource {
322
329
  /** @private */
323
330
  private _rotate;
324
331
  /** @private */
332
+ private _dial;
333
+ /** @private */
325
334
  private _removed;
326
335
  /** @private */
327
336
  private _seat;
package/types/index.d.ts CHANGED
@@ -49,10 +49,6 @@ export type CeroOpts = {
49
49
  * Incoming-connection filter: `true` refuses the connection.
50
50
  */
51
51
  firewall?: (remotePublicKey: Uint8Array, payload: unknown) => boolean;
52
- /**
53
- * Swarm reconnect backoff tiers in ms (testing/tuning).
54
- */
55
- backoffs?: number[];
56
52
  /**
57
53
  * Optional network-isolation label; only same-channel peers connect.
58
54
  */
@@ -62,12 +58,13 @@ export type CeroOpts = {
62
58
  */
63
59
  mirrors?: Array<string | Uint8Array>;
64
60
  /**
65
- * How many handles search, how many only announce, and the idle ms before the rest leave the swarm.
61
+ * How many handles search and announce at once besides the ones in use, the ms one stays on after its last use, how many devices a handle keeps to dial by their keys, and how many connections the device keeps at once.
66
62
  */
67
63
  presence?: {
68
64
  active?: number;
69
- announced?: number;
70
65
  idle?: number;
66
+ known?: number;
67
+ connections?: number;
71
68
  };
72
69
  /**
73
70
  * Where background errors go; the console without one.
@@ -100,6 +97,10 @@ export type CeroOpts = {
100
97
  maxInbound?: number;
101
98
  pipe?: 'l2cap' | 'gatt';
102
99
  };
100
+ /**
101
+ * The WebRTC calls run their media on where Cero runs in the UI itself; a window's own without it, none in a worker.
102
+ */
103
+ webrtc?: import('./lib/media.js').Bindings;
103
104
  };
104
105
  /**
105
106
  * @typedef {import('./handle/index.js').Context} Context
@@ -115,16 +116,16 @@ export type CeroOpts = {
115
116
  * @property {Array<{ host: string, port: number }>} [bootstrap] Custom DHT bootstrap nodes.
116
117
  * @property {Array<string | Uint8Array>} [relayThrough] Blind relay public keys. Two devices that cannot connect direct, as on mobile carriers, connect through one; the relay forwards encrypted bytes and reads nothing. Direct connections stay direct.
117
118
  * @property {(remotePublicKey: Uint8Array, payload: unknown) => boolean} [firewall] Incoming-connection filter: `true` refuses the connection.
118
- * @property {number[]} [backoffs] Swarm reconnect backoff tiers in ms (testing/tuning).
119
119
  * @property {string} [channel] Optional network-isolation label; only same-channel peers connect.
120
120
  * @property {Array<string | Uint8Array>} [mirrors] Blind-peer public keys. Handles and files are mirrored through them so peers sync even when never online at the same time. Mirrors hold only encrypted blocks — they never read your data.
121
- * @property {{ active?: number, announced?: number, idle?: number }} [presence] How many handles search, how many only announce, and the idle ms before the rest leave the swarm.
121
+ * @property {{ active?: number, idle?: number, known?: number, connections?: number }} [presence] How many handles search and announce at once besides the ones in use, the ms one stays on after its last use, how many devices a handle keeps to dial by their keys, and how many connections the device keeps at once.
122
122
  * @property {(err: Error) => void} [onerror] Where background errors go; the console without one.
123
123
  * @property {number} [keepOpen] How many handles stay open after their last close, for a reopen; one more closes the least recently used, 0 closes at once. Defaults to 16.
124
124
  * @property {number} [recoveryTimeout] Max wait to find another device and be admitted, in ms. Defaults to 30000.
125
125
  * @property {Uint8Array} [storageKey] 32-byte key encrypting local key material (master seed, device keypairs) at rest. Source it from the OS keychain — cero never stores it.
126
126
  * @property {import('./extensions/index.js').Extension[]} [extensions] The extensions this instance runs, instead of the ones the spec carries. Build with the same list.
127
127
  * @property {{ on?: boolean, topic?: string, backend?: object | null, maxOutbound?: number, maxInbound?: number, pipe?: 'l2cap' | 'gatt' }} [bluetooth] Bluetooth at start: `on` (off by default) and `topic` (the default one, else the channel's own); the app turns the radio on and off with `cero.nearby`, and nothing is stored. `maxOutbound`/`maxInbound` cap concurrent outbound links and inbound sessions. `pipe` picks the data pipe, `'l2cap'` (default, faster) or `'gatt'`; both peers must match. `backend` injects a bare-bluetooth-shaped backend (tests); with none on the host, `status.nearby` reads `'unsupported'`.
128
+ * @property {import('./lib/media.js').Bindings} [webrtc] The WebRTC calls run their media on where Cero runs in the UI itself; a window's own without it, none in a worker.
128
129
  */
129
130
  /**
130
131
  * Open (or create) a cero handle at `dir`.
@@ -0,0 +1,20 @@
1
+ /** The lanes a mute names. */
2
+ export declare const LANES: string[];
3
+ export type Spec = import('./spec.js').Spec;
4
+ export type Wire = Pick<Spec, 'schema' | 'codec'> & {
5
+ meta: {
6
+ refs: Record<string, import('./spec.js').RefInfo>;
7
+ };
8
+ };
9
+ /**
10
+ * @typedef {import('./spec.js').Spec} Spec
11
+ * @typedef {Pick<Spec, 'schema' | 'codec'> & { meta: { refs: Record<string, import('./spec.js').RefInfo> } }} Wire
12
+ */
13
+ /**
14
+ * What a line carries across RPC: its refs are computed on the device, and cross in the encodings
15
+ * of its room's spec, through the same get and watch a handle's refs use.
16
+ *
17
+ * @param {Spec} spec The room's.
18
+ * @returns {Wire}
19
+ */
20
+ export declare function wire({ meta, schema, codec }: Spec): Wire;
@@ -0,0 +1,156 @@
1
+ export type Bindings = {
2
+ RTCPeerConnection: typeof RTCPeerConnection;
3
+ MediaStream: typeof MediaStream;
4
+ };
5
+ export type Bridge = {
6
+ self: {
7
+ id: string;
8
+ audio: boolean;
9
+ video: boolean;
10
+ screen: boolean;
11
+ } | null;
12
+ peers: Array<{
13
+ id: string;
14
+ port: number;
15
+ seq?: number;
16
+ type?: Signal['type'];
17
+ sdp?: string;
18
+ }>;
19
+ };
20
+ export type Signal = {
21
+ type: 'offer' | 'answer';
22
+ sdp: string;
23
+ };
24
+ export type Conn = {
25
+ id: string;
26
+ port: number;
27
+ pc: RTCPeerConnection;
28
+ offerer: boolean;
29
+ lanes: RTCRtpTransceiver[] | null;
30
+ /**
31
+ * A description from the other side reached it.
32
+ */
33
+ heard: boolean;
34
+ streams: {
35
+ stream: MediaStream;
36
+ screen: MediaStream;
37
+ } | null;
38
+ closed: boolean;
39
+ turn: Promise<void> | null;
40
+ };
41
+ /**
42
+ * @typedef {object} Bindings The WebRTC a line's media runs on: `react-native-webrtc`, or a window's own.
43
+ * @property {typeof RTCPeerConnection} RTCPeerConnection
44
+ * @property {typeof MediaStream} MediaStream
45
+ *
46
+ * @typedef {object} Bridge The worker's side of a line: this device's lanes once its row is read, and the local port of each other device with the description it sent last.
47
+ * @property {{ id: string, audio: boolean, video: boolean, screen: boolean } | null} self
48
+ * @property {Array<{ id: string, port: number, seq?: number, type?: Signal['type'], sdp?: string }>} peers
49
+ *
50
+ * @typedef {{ type: 'offer' | 'answer', sdp: string }} Signal A WebRTC description.
51
+ *
52
+ * @typedef {object} Conn
53
+ * @property {string} id
54
+ * @property {number} port
55
+ * @property {RTCPeerConnection} pc
56
+ * @property {boolean} offerer
57
+ * @property {RTCRtpTransceiver[] | null} lanes
58
+ * @property {boolean} heard A description from the other side reached it.
59
+ * @property {{ stream: MediaStream, screen: MediaStream } | null} streams
60
+ * @property {boolean} closed
61
+ * @property {Promise<void> | null} turn
62
+ */
63
+ /**
64
+ * The bindings to run on: the ones given, else the window's.
65
+ *
66
+ * @param {Bindings | null} [webrtc]
67
+ * @returns {Bindings | null}
68
+ */
69
+ export declare function bindings(webrtc?: Bindings | null): Bindings | null;
70
+ /**
71
+ * A line's WebRTC: one connection per device on the call, its media through the worker's local port
72
+ * for that device, so no ICE server is needed.
73
+ */
74
+ export declare class Media {
75
+ webrtc: Bindings;
76
+ /** @type {MediaStream | null} The camera and microphone. */
77
+ camera: MediaStream | null;
78
+ /** @type {MediaStream | null} */
79
+ screen: MediaStream | null;
80
+ muted: {
81
+ audio: boolean;
82
+ video: boolean;
83
+ };
84
+ closed: boolean;
85
+ /** @private */
86
+ _send;
87
+ /** @private */
88
+ _onchange;
89
+ /** @private */
90
+ _onerror;
91
+ /** @private */
92
+ _self;
93
+ /** @private @type {Map<string, number>} */
94
+ _taken;
95
+ /** @private @type {Bridge['self']} */
96
+ _row;
97
+ /** @private @type {Map<string, Conn>} */
98
+ _conns;
99
+ /**
100
+ * @param {Bindings} webrtc
101
+ * @param {{ send: (id: string, port: number, data: Signal) => void, onchange: () => void, onerror: (err: Error) => void }} opts `send` a signal to the device on `port`.
102
+ */
103
+ constructor(webrtc: Bindings, { send, onchange, onerror }: {
104
+ send: (id: string, port: number, data: Signal) => void;
105
+ onchange: () => void;
106
+ onerror: (err: Error) => void;
107
+ });
108
+ /**
109
+ * Take the worker's side as it is now: a new port rebuilds that device's connection, and the
110
+ * description a device sent last is applied once.
111
+ *
112
+ * @param {Bridge} bridge
113
+ * @returns {void}
114
+ */
115
+ update({ self, peers }: Bridge): void;
116
+ /**
117
+ * What a device shows: its media only while connected, its screen only while its row shares one.
118
+ *
119
+ * @param {string} id
120
+ * @param {boolean} sharing
121
+ * @returns {{ stream: MediaStream | null, screen: MediaStream | null, connected: boolean }}
122
+ */
123
+ entry(id: string, sharing: boolean): {
124
+ stream: MediaStream | null;
125
+ screen: MediaStream | null;
126
+ connected: boolean;
127
+ };
128
+ /** @param {MediaStream | null} stream The camera and microphone, or none. */
129
+ share(stream: MediaStream | null): void;
130
+ /** @param {MediaStream | null} stream A screen, or none. */
131
+ present(stream: MediaStream | null): void;
132
+ /**
133
+ * @param {'audio' | 'video'} lane
134
+ * @param {boolean} on
135
+ */
136
+ lane(lane: 'audio' | 'video', on: boolean): void;
137
+ close(): void;
138
+ /** @private */
139
+ private _open;
140
+ /** @private */
141
+ private _route;
142
+ /** @private */
143
+ private _take;
144
+ /** @private */
145
+ private _describe;
146
+ /** @private */
147
+ private _attach;
148
+ /** @private */
149
+ private _track;
150
+ /** @private */
151
+ private _state;
152
+ /** @private */
153
+ private _turn;
154
+ /** @private */
155
+ private _drop;
156
+ }
@@ -1,4 +1,5 @@
1
1
  export type Ref = import('./refs.js').Ref;
2
+ export type Line = import('../extensions/calls.js').Line;
2
3
  export type HookContext = import('@cero-base/core/database').HookContext;
3
4
  export type Context = import('../handle/index.js').Context | import('../rpc/client.js').Context;
4
5
  export type Row = import('@cero-base/core/database').Row;
@@ -42,8 +43,9 @@ export declare function call(ref: Ref, d?: Row): Promise<void>;
42
43
  /**
43
44
  * Rule that runs before a write to `ref` lands, or before an action does: at apply, on every
44
45
  * peer, inside the op's transaction. Return `false` to refuse it: the writer's own call rejects
45
- * with `REFUSED`. `ctx` is `{ op, name, row, existing, id, memberId, role, get, put, set, del }`;
46
- * mutate `ctx.row` to rewrite what is stored. `op` is the op as it applies, so an upsert on a
46
+ * with `REFUSED`. `ctx` is
47
+ * `{ op, name, row, existing, id, memberId, role, device, ts, get, put, set, del }`; mutate
48
+ * `ctx.row` to rewrite what is stored. `op` is the op as it applies, so an upsert on a
47
49
  * collection is a `put`. The four operators on `ctx` read and write the handle as it stands at this
48
50
  * op, inside the transaction. Must be deterministic: read only `ctx`, never a clock or local
49
51
  * state. On a type ref (`me.room.notes`) it reaches every handle of the type before the handle
@@ -183,10 +185,12 @@ export declare function accept(ctx: Context, request: {
183
185
  role?: string;
184
186
  }): Promise<void>;
185
187
  /**
186
- * Turn away a join waiting on a `confirm` invite. The joiner's `open` rejects with `DENIED`.
188
+ * Turn away a join waiting on a `confirm` invite. The joiner's `open` rejects with `DENIED`. On a
189
+ * ring of `me.local.rings`, turn down the room's call: it stops ringing your devices, and goes on
190
+ * for the others unless every member it rang turned it down before anyone answered.
187
191
  *
188
192
  * @param {Context} ctx
189
- * @param {{ id: string }} request A row of `ctx.requests`.
193
+ * @param {{ id: string }} request A row of `ctx.requests`, or the room's ring.
190
194
  * @param {string} [reason]
191
195
  * @returns {Promise<void>}
192
196
  */
@@ -211,12 +215,65 @@ export declare function removed(ctx: Context, id: string): Promise<'removed' | '
211
215
  */
212
216
  export declare function leave(ctx: Context): Promise<void>;
213
217
  /**
214
- * Stop using a context on this device; everything stays. Closing the root closes it all.
218
+ * Stop using a context on this device; everything stays. Closing the root closes it all. On a line,
219
+ * this device leaves the call: it goes on for the others, and ends with the last device on it.
215
220
  *
216
- * @param {Context} ctx
221
+ * @param {Context | Line} ctx
222
+ * @returns {Promise<void>}
223
+ */
224
+ export declare function close(ctx: Context | Line): Promise<void>;
225
+ /**
226
+ * Start a call in a room, ringing the members `to` names, every other member without it, or join
227
+ * the call going there. The same room gives the same line until it closes. Needs the `calls()`
228
+ * extension in the build: without it `INVALID`. `stream`, the camera and microphone, goes to every
229
+ * device on the call where WebRTC runs, the UI.
230
+ *
231
+ * @param {Context} room
232
+ * @param {{ to?: string[], stream?: MediaStream }} [opts]
233
+ * @returns {Promise<Line>}
234
+ */
235
+ export declare function dial(room: Context, opts?: {
236
+ to?: string[];
237
+ stream?: MediaStream;
238
+ }): Promise<Line>;
239
+ /**
240
+ * Send a stream on a line where WebRTC runs: on `line` the camera and microphone, in place of the
241
+ * ones before; on `line.screen` a screen, beside them. In a worker with no UI it does nothing.
242
+ *
243
+ * @param {Line | Ref} target A line, or its `screen`.
244
+ * @param {MediaStream} stream
245
+ * @returns {Promise<void>}
246
+ */
247
+ export declare function share(target: Line | Ref, stream: MediaStream): Promise<void>;
248
+ /**
249
+ * Stop the stream `share` or `dial` sent on `line`, or the screen on `line.screen`. The app's tracks
250
+ * stay as they are.
251
+ *
252
+ * @param {Line | Ref} target
253
+ * @returns {Promise<void>}
254
+ */
255
+ export declare function unshare(target: Line | Ref): Promise<void>;
256
+ /**
257
+ * End a call for everyone on it: every line of it closes.
258
+ *
259
+ * @param {Line} line
260
+ * @returns {Promise<void>}
261
+ */
262
+ export declare function end(line: Line): Promise<void>;
263
+ /**
264
+ * Pause a lane of a line, `line.audio` or `line.video`: every device on the call sees it.
265
+ *
266
+ * @param {Ref} lane
267
+ * @returns {Promise<void>}
268
+ */
269
+ export declare function mute(lane: Ref): Promise<void>;
270
+ /**
271
+ * Turn a lane paused with `mute` back on.
272
+ *
273
+ * @param {Ref} lane
217
274
  * @returns {Promise<void>}
218
275
  */
219
- export declare function close(ctx: Context): Promise<void>;
276
+ export declare function unmute(lane: Ref): Promise<void>;
220
277
  /**
221
278
  * Give up a join still waiting for an answer, for good: it is not resumed on the next boot.
222
279
  *
@@ -249,7 +306,7 @@ export declare function resume(me: Context): Promise<void>;
249
306
  */
250
307
  export declare function activate(ctx: Context): Promise<void>;
251
308
  /**
252
- * Take a handle off the swarm until something lands in it.
309
+ * Rank a handle last: it is on the swarm only while a slot is spare, until something lands in it.
253
310
  *
254
311
  * @param {Context} ctx
255
312
  * @returns {Promise<void>}
@@ -0,0 +1 @@
1
+ export declare function follow(): void;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Follow every handle this device is in on the service at `key`: tell it of this device's writes,
3
+ * and wake a handle when another device tells of one. A best effort: a notice may come late or
4
+ * twice, and the data is Cero's sync's. `me` emits `'pulse'` with the handle's id and the local
5
+ * time a write from another device landed in it.
6
+ *
7
+ * @param {import('../handle/index.js').Context} me
8
+ * @param {string | Uint8Array} key The service's public key.
9
+ * @returns {() => void} Stops following.
10
+ */
11
+ export declare function follow(me: import('../handle/index.js').Context, key: string | Uint8Array): () => void;
@@ -1,12 +1,12 @@
1
- export type RefKind = 'collection' | 'single' | 'action' | 'handle';
1
+ export type RefKind = 'collection' | 'single' | 'action' | 'handle' | 'lane';
2
2
  export type RefInfo = import('./spec.js').RefInfo;
3
3
  export type Spec = import('./spec.js').Spec;
4
- export type Owner = import('../handle/index.js').Context | import('../local/index.js').Local;
4
+ export type Owner = import('../handle/index.js').Context | import('../local/index.js').Local | import('../extensions/calls.js').Line;
5
5
  /**
6
- * @typedef {'collection' | 'single' | 'action' | 'handle'} RefKind
6
+ * @typedef {'collection' | 'single' | 'action' | 'handle' | 'lane'} RefKind
7
7
  * @typedef {import('./spec.js').RefInfo} RefInfo
8
8
  * @typedef {import('./spec.js').Spec} Spec
9
- * @typedef {import('../handle/index.js').Context | import('../local/index.js').Local} Owner
9
+ * @typedef {import('../handle/index.js').Context | import('../local/index.js').Local | import('../extensions/calls.js').Line} Owner
10
10
  */
11
11
  /**
12
12
  * Typed pointer to a single ref (table or handle slot) on a `Handle` or `Local`.
@@ -20,7 +20,7 @@ export declare class Ref {
20
20
  /**
21
21
  * @param {Owner} handle The root, a handle or the local store the ref lives on.
22
22
  * @param {string} name Ref name as declared in the schema.
23
- * @param {string} kind Ref kind: `'collection'`, `'single'`, `'action'`, or `'handle'`.
23
+ * @param {string} kind Ref kind: `'collection'`, `'single'`, `'action'`, `'handle'`, or a line's `'lane'`.
24
24
  * @param {string | null} [schema] Fully-qualified schema id, if any.
25
25
  * @param {string | null} [type] On a ref under a handle type (`me.room.notes`), that type.
26
26
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * `@react-native-firebase/messaging` as the messaging service `connect` takes for push: pass `messaging()`. Pushes to the app in
3
- * front; the push worklet answers the ones the OS delivers while it is not.
3
+ * front; the push worker answers the ones the OS delivers while it is not.
4
4
  *
5
5
  * @param {{ subscribeToTopic: (topic: string) => Promise<void>, unsubscribeFromTopic: (topic: string) => Promise<void>, onMessage: (fn: (message: object) => void) => () => void }} messaging
6
6
  * @returns {import('../rpc/push.js').Messaging}
@@ -38,14 +38,16 @@ export declare function receive(dir: string, spec: import('../lib/spec.js').Spec
38
38
  row: object | null;
39
39
  } | null>;
40
40
  /**
41
- * The bare-kit push entry: on each push the OS hands this worklet, verify it and, for one about
42
- * new data on a handle this device holds, answer with what the show handler returns: the
43
- * notification, `{ title, body }`, or nothing. The request carries `storage`, `payload` (base64) and, when the
44
- * app encrypts its local store, `storageKey` (base64).
41
+ * The bare-kit push worker, a module's default export: for each push the OS hands it, one JSON
42
+ * message, it verifies the push and, for one about new data on a handle this device holds, answers
43
+ * with what the show handler returns, the notification `{ title, body }`, or `{}` for none. The
44
+ * message carries `payload` (base64) as the notification brings it, and what the app's notification
45
+ * extension adds: `storage`, the directory `cero()` opened, and `storageKey` (base64) when the app
46
+ * encrypts its local store.
45
47
  *
46
48
  * @param {import('../lib/spec.js').Spec} spec
47
49
  * @param {(push: { id: string, type: string, name: string | null, newer: boolean, ref: string | null, row: object | null }) => { title: string, body: string } | null | undefined | Promise<{ title: string, body: string } | null | undefined>} show The show handler: what to show for a verified push, as `cero.receive` would give it to the app.
48
- * @returns {void}
50
+ * @returns {(ipc: import('streamx').Duplex) => void} The worker's `start`.
49
51
  */
50
52
  export declare function push(spec: import('../lib/spec.js').Spec, show: (push: {
51
53
  id: string;
@@ -60,4 +62,4 @@ export declare function push(spec: import('../lib/spec.js').Spec, show: (push: {
60
62
  } | null | undefined | Promise<{
61
63
  title: string;
62
64
  body: string;
63
- } | null | undefined>): void;
65
+ } | null | undefined>): (ipc: import('streamx').Duplex) => void;
@@ -39,7 +39,16 @@ declare const remote: {
39
39
  }, reason?: string): Promise<void>;
40
40
  removed(ctx: verbs.Context, id: string): Promise<'removed' | 'left' | null>;
41
41
  leave(ctx: verbs.Context): Promise<void>;
42
- close(ctx: verbs.Context): Promise<void>;
42
+ close(ctx: verbs.Context | verbs.Line): Promise<void>;
43
+ dial(room: verbs.Context, opts?: {
44
+ to?: string[];
45
+ stream?: MediaStream;
46
+ }): Promise<verbs.Line>;
47
+ share(target: verbs.Line | verbs.Ref, stream: MediaStream): Promise<void>;
48
+ unshare(target: verbs.Line | verbs.Ref): Promise<void>;
49
+ end(line: verbs.Line): Promise<void>;
50
+ mute(lane: verbs.Ref): Promise<void>;
51
+ unmute(lane: verbs.Ref): Promise<void>;
43
52
  cancel(me: verbs.Context, code: string): Promise<boolean>;
44
53
  suspend(me: verbs.Context): Promise<void>;
45
54
  resume(me: verbs.Context): Promise<void>;
@@ -68,7 +77,7 @@ declare const remote: {
68
77
  topic?: string;
69
78
  }): Promise<void>;
70
79
  };
71
- export declare const put: typeof verbs.put, set: typeof verbs.set, get: typeof verbs.get, del: typeof verbs.del, watch: typeof verbs.watch, call: typeof verbs.call, supports: typeof verbs.supports, open: typeof verbs.open, invite: typeof verbs.invite, revoke: typeof verbs.revoke, rotate: typeof verbs.rotate, accept: typeof verbs.accept, deny: typeof verbs.deny, leave: typeof verbs.leave, removed: typeof verbs.removed, close: typeof verbs.close, cancel: typeof verbs.cancel, suspend: typeof verbs.suspend, resume: typeof verbs.resume, activate: typeof verbs.activate, deactivate: typeof verbs.deactivate, phrase: typeof verbs.phrase, nearby: typeof verbs.nearby;
80
+ export declare const put: typeof verbs.put, set: typeof verbs.set, get: typeof verbs.get, del: typeof verbs.del, watch: typeof verbs.watch, call: typeof verbs.call, supports: typeof verbs.supports, open: typeof verbs.open, invite: typeof verbs.invite, revoke: typeof verbs.revoke, rotate: typeof verbs.rotate, accept: typeof verbs.accept, deny: typeof verbs.deny, leave: typeof verbs.leave, removed: typeof verbs.removed, close: typeof verbs.close, cancel: typeof verbs.cancel, suspend: typeof verbs.suspend, resume: typeof verbs.resume, activate: typeof verbs.activate, deactivate: typeof verbs.deactivate, phrase: typeof verbs.phrase, nearby: typeof verbs.nearby, dial: typeof verbs.dial, end: typeof verbs.end, mute: typeof verbs.mute, unmute: typeof verbs.unmute, share: typeof verbs.share, unshare: typeof verbs.unshare;
72
81
  export { t, schema };
73
82
  export type BaseRPCClient = import('@cero-base/core/rpc').RPCClient;
74
83
  export type RefInfo = import('../lib/spec.js').RefInfo;
@@ -103,6 +112,10 @@ export type ClientOpts = {
103
112
  * With `invite`: the request's id as it is sent.
104
113
  */
105
114
  onrequest?: (id: string) => void;
115
+ /**
116
+ * The WebRTC a line's media runs on, `react-native-webrtc`; a window's own without it.
117
+ */
118
+ webrtc?: import('../lib/media.js').Bindings;
106
119
  };
107
120
  /**
108
121
  * Switch the app to the identity of a recovery phrase, as `cero.restore` does in the worker: the
@@ -154,7 +167,11 @@ export declare class Client extends RPCClient {
154
167
  /** @private */
155
168
  _how;
156
169
  /** @private */
170
+ _webrtc;
171
+ /** @private */
157
172
  _push;
173
+ /** @private @type {Map<string, Line>} */
174
+ _lines;
158
175
  /** @private */
159
176
  _onerror;
160
177
  /** @type {string | null} */
@@ -176,7 +193,7 @@ export declare class Client extends RPCClient {
176
193
  * @param {Spec} spec Compiled cero spec (schema + rpc + handles).
177
194
  * @param {ClientOpts} [opts]
178
195
  */
179
- constructor(ipc: import('streamx').Duplex, spec: Spec, { onerror, push, phrase, invite, onrequest }?: ClientOpts);
196
+ constructor(ipc: import('streamx').Duplex, spec: Spec, { onerror, push, phrase, invite, onrequest, webrtc }?: ClientOpts);
180
197
  /** @private */
181
198
  private _pumpErrors;
182
199
  /** @private */
@@ -175,6 +175,12 @@ export declare class Server extends RPCServer {
175
175
  * @private
176
176
  */
177
177
  private _wireVerbs;
178
+ /**
179
+ * A line the UI dialed is reached by its id, as a handle is, until the UI lets it go: one that
180
+ * closed answers as closed in between.
181
+ * @private
182
+ */
183
+ private _line;
178
184
  /**
179
185
  * Register a request handler whose error fails only its call.
180
186
  * @private