@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.
- package/README.md +9 -9
- package/package.json +19 -7
- package/src/build/index.js +6 -1
- package/src/build/schemas.js +25 -0
- package/src/extensions/calls.js +911 -0
- package/src/extensions/index.js +3 -1
- package/src/extensions/pulse.js +33 -0
- package/src/handle/index.js +24 -16
- package/src/index.js +15 -13
- package/src/lib/line.js +28 -0
- package/src/lib/media.js +285 -0
- package/src/lib/operators.js +109 -8
- package/src/lib/pulse-ui.js +5 -0
- package/src/lib/pulse.js +505 -0
- package/src/lib/refs.js +3 -3
- package/src/push/firebase.js +1 -1
- package/src/push/index.js +25 -19
- package/src/rpc/client.js +214 -2
- package/src/rpc/server.js +30 -3
- package/types/build/schemas.d.ts +22 -0
- package/types/extensions/calls.d.ts +218 -0
- package/types/extensions/index.d.ts +15 -4
- package/types/extensions/pulse.d.ts +11 -0
- package/types/handle/index.d.ts +9 -0
- package/types/index.d.ts +9 -8
- package/types/lib/line.d.ts +20 -0
- package/types/lib/media.d.ts +156 -0
- package/types/lib/operators.d.ts +65 -8
- package/types/lib/pulse-ui.d.ts +1 -0
- package/types/lib/pulse.d.ts +11 -0
- package/types/lib/refs.d.ts +5 -5
- package/types/push/firebase.d.ts +1 -1
- package/types/push/index.d.ts +8 -6
- package/types/rpc/client.d.ts +20 -3
- package/types/rpc/server.d.ts +6 -0
package/src/push/firebase.js
CHANGED
|
@@ -2,7 +2,7 @@ import b4a from 'b4a'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* `@react-native-firebase/messaging` as the messaging service `connect` takes for push: pass `messaging()`. Pushes to the app in
|
|
5
|
-
* front; the push
|
|
5
|
+
* front; the push worker answers the ones the OS delivers while it is not.
|
|
6
6
|
*
|
|
7
7
|
* @param {{ subscribeToTopic: (topic: string) => Promise<void>, unsubscribeFromTopic: (topic: string) => Promise<void>, onMessage: (fn: (message: object) => void) => () => void }} messaging
|
|
8
8
|
* @returns {import('../rpc/push.js').Messaging}
|
package/src/push/index.js
CHANGED
|
@@ -67,6 +67,8 @@ async function rowOf(storage, spec, hit, { encryptionKey, epochs }) {
|
|
|
67
67
|
* @returns {Promise<{ id: string, type: string, name: string | null, newer: boolean, ref: string | null, row: object | null } | null>}
|
|
68
68
|
*/
|
|
69
69
|
export async function receive(dir, spec, payload, { storageKey } = {}) {
|
|
70
|
+
// no directory named: nothing to verify against
|
|
71
|
+
if (typeof dir !== 'string' || !dir) return null
|
|
70
72
|
let held = null
|
|
71
73
|
let storage = null
|
|
72
74
|
let store = null
|
|
@@ -91,29 +93,33 @@ export async function receive(dir, spec, payload, { storageKey } = {}) {
|
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
|
-
* The bare-kit push
|
|
95
|
-
* new data on a handle this device holds,
|
|
96
|
-
*
|
|
97
|
-
*
|
|
96
|
+
* The bare-kit push worker, a module's default export: for each push the OS hands it, one JSON
|
|
97
|
+
* message, it verifies the push and, for one about new data on a handle this device holds, answers
|
|
98
|
+
* with what the show handler returns, the notification `{ title, body }`, or `{}` for none. The
|
|
99
|
+
* message carries `payload` (base64) as the notification brings it, and what the app's notification
|
|
100
|
+
* extension adds: `storage`, the directory `cero()` opened, and `storageKey` (base64) when the app
|
|
101
|
+
* encrypts its local store.
|
|
98
102
|
*
|
|
99
103
|
* @param {import('../lib/spec.js').Spec} spec
|
|
100
104
|
* @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.
|
|
101
|
-
* @returns {void}
|
|
105
|
+
* @returns {(ipc: import('streamx').Duplex) => void} The worker's `start`.
|
|
102
106
|
*/
|
|
103
107
|
export function push(spec, show) {
|
|
104
108
|
if (typeof show !== 'function') throw CeroError.INVALID('push: a show handler says what to show')
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
109
|
+
return (ipc) => {
|
|
110
|
+
ipc.on('data', async (message) => {
|
|
111
|
+
let shown = null
|
|
112
|
+
try {
|
|
113
|
+
const { storage, storageKey, payload } = JSON.parse(b4a.toString(message))
|
|
114
|
+
const hit = await receive(storage, spec, b4a.from(payload, 'base64'), {
|
|
115
|
+
storageKey: storageKey ? b4a.from(storageKey, 'base64') : undefined
|
|
116
|
+
})
|
|
117
|
+
if (hit?.newer) shown = await show(hit)
|
|
118
|
+
} catch {
|
|
119
|
+
// the OS waits for an answer: whatever went wrong, no notification
|
|
120
|
+
shown = null
|
|
121
|
+
}
|
|
122
|
+
ipc.write(b4a.from(JSON.stringify(shown || {})))
|
|
123
|
+
})
|
|
124
|
+
}
|
|
119
125
|
}
|
package/src/rpc/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'streamx'
|
|
2
2
|
import b4a from 'b4a'
|
|
3
|
+
import AbortController from 'bare-abort-controller'
|
|
3
4
|
import { RPCClient, bindCodec } from '@cero-base/core/rpc'
|
|
4
5
|
import { CeroError } from '@cero-base/core/errors'
|
|
5
6
|
import { checkFields, checkRequired } from '@cero-base/core/utils'
|
|
@@ -8,6 +9,8 @@ import z32 from 'z32'
|
|
|
8
9
|
import { decodeId, servedType } from '@cero-base/core/blobs/codec'
|
|
9
10
|
|
|
10
11
|
import { Ref } from '../lib/refs.js'
|
|
12
|
+
import { wire } from '../lib/line.js'
|
|
13
|
+
import { Media, bindings } from '../lib/media.js'
|
|
11
14
|
import { follow } from './push.js'
|
|
12
15
|
import * as verbs from '../lib/operators.js'
|
|
13
16
|
import { t, schema } from '../lib/spec.js'
|
|
@@ -38,7 +41,13 @@ export const {
|
|
|
38
41
|
activate,
|
|
39
42
|
deactivate,
|
|
40
43
|
phrase,
|
|
41
|
-
nearby
|
|
44
|
+
nearby,
|
|
45
|
+
dial,
|
|
46
|
+
end,
|
|
47
|
+
mute,
|
|
48
|
+
unmute,
|
|
49
|
+
share,
|
|
50
|
+
unshare
|
|
42
51
|
} = remote
|
|
43
52
|
export { t, schema }
|
|
44
53
|
|
|
@@ -64,6 +73,7 @@ export { t, schema }
|
|
|
64
73
|
* @property {string} [phrase] On a worker whose store is new, it recovers the identity of this phrase, as `cero(dir, spec, { phrase })`.
|
|
65
74
|
* @property {string} [invite] On a worker whose store is new, it links to the identity of this device invite, as `cero(dir, spec, { invite })`.
|
|
66
75
|
* @property {(id: string) => void} [onrequest] With `invite`: the request's id as it is sent.
|
|
76
|
+
* @property {import('../lib/media.js').Bindings} [webrtc] The WebRTC a line's media runs on, `react-native-webrtc`; a window's own without it.
|
|
67
77
|
*/
|
|
68
78
|
|
|
69
79
|
const blobIdEnc = {
|
|
@@ -425,6 +435,20 @@ const operators = {
|
|
|
425
435
|
throw CeroError.INVALID('inbox runs where cero runs, not over RPC')
|
|
426
436
|
},
|
|
427
437
|
|
|
438
|
+
// the worker joins the call; the stream stays with the UI, which holds the media
|
|
439
|
+
/** @private */
|
|
440
|
+
async _dial({ stream = null, ...opts }) {
|
|
441
|
+
const { id } = await this._verb('dial', opts)
|
|
442
|
+
const root = this.parent || this
|
|
443
|
+
// the worker answers with the room's open line: this side keeps the one it has, and its media
|
|
444
|
+
const open = root._lines.get(id)
|
|
445
|
+
if (open) return open
|
|
446
|
+
const line = new Line(root, id, stream, this.spec)
|
|
447
|
+
root._lines.set(id, line)
|
|
448
|
+
line.signal.addEventListener('abort', () => root._lines.delete(id))
|
|
449
|
+
return line
|
|
450
|
+
},
|
|
451
|
+
|
|
428
452
|
/** @private */
|
|
429
453
|
async _verb(verb, ...args) {
|
|
430
454
|
const { data } = await this.rpc.verb({
|
|
@@ -514,12 +538,17 @@ export class Client extends RPCClient {
|
|
|
514
538
|
* @param {Spec} spec Compiled cero spec (schema + rpc + handles).
|
|
515
539
|
* @param {ClientOpts} [opts]
|
|
516
540
|
*/
|
|
517
|
-
constructor(ipc, spec, { onerror, push, phrase, invite, onrequest } = {}) {
|
|
541
|
+
constructor(ipc, spec, { onerror, push, phrase, invite, onrequest, webrtc } = {}) {
|
|
518
542
|
super(ipc, spec)
|
|
519
543
|
/** @private */
|
|
520
544
|
this._how = { phrase, invite, onrequest }
|
|
521
545
|
/** @private */
|
|
546
|
+
this._webrtc = bindings(webrtc)
|
|
547
|
+
/** @private */
|
|
522
548
|
this._push = push || null
|
|
549
|
+
// the lines open in this UI, by id
|
|
550
|
+
/** @private @type {Map<string, Line>} */
|
|
551
|
+
this._lines = new Map()
|
|
523
552
|
if (spec.local?.schema && !spec.local.codec) bindCodec(spec.local)
|
|
524
553
|
Object.assign(this, operators)
|
|
525
554
|
/** @private */
|
|
@@ -662,6 +691,189 @@ class Handle {
|
|
|
662
691
|
}
|
|
663
692
|
}
|
|
664
693
|
|
|
694
|
+
/**
|
|
695
|
+
* Client-side proxy for a line the worker dialed: its refs reach the worker's line by its id, and its
|
|
696
|
+
* signal fires once the worker ends the line's peers. With WebRTC in the UI, the media runs here,
|
|
697
|
+
* through the ports the worker holds to the other devices.
|
|
698
|
+
*/
|
|
699
|
+
class Line {
|
|
700
|
+
/**
|
|
701
|
+
* @param {Client} parent
|
|
702
|
+
* @param {string} id
|
|
703
|
+
* @param {MediaStream | null} stream
|
|
704
|
+
* @param {import('../lib/spec.js').Spec} spec The room's.
|
|
705
|
+
*/
|
|
706
|
+
constructor(parent, id, stream, spec) {
|
|
707
|
+
Object.assign(this, operators)
|
|
708
|
+
this.parent = parent
|
|
709
|
+
this.id = id
|
|
710
|
+
this.spec = wire(spec)
|
|
711
|
+
this.store = this
|
|
712
|
+
const { refs } = this.spec.meta
|
|
713
|
+
this.audio = new Ref(this, 'audio', 'lane')
|
|
714
|
+
this.video = new Ref(this, 'video', 'lane')
|
|
715
|
+
this.screen = new Ref(this, 'screen', 'lane')
|
|
716
|
+
this.peers = new Ref(this, 'peers', 'collection', refs.peers.schema)
|
|
717
|
+
/** @private */
|
|
718
|
+
this._stream = stream
|
|
719
|
+
/** @private */
|
|
720
|
+
this._ac = new AbortController()
|
|
721
|
+
/** @private */
|
|
722
|
+
this._owned = new Set()
|
|
723
|
+
/** @private */
|
|
724
|
+
this._fns = new Set()
|
|
725
|
+
/** @private @type {import('streamx').Readable[]} */
|
|
726
|
+
this._feeds = []
|
|
727
|
+
/** @private @type {Promise<unknown> | null} */
|
|
728
|
+
this._released = null
|
|
729
|
+
/** @private */
|
|
730
|
+
const lane = (name) => ({ get: () => this._on(name), watch: (fn) => this._onPeers(fn) })
|
|
731
|
+
/** @private */
|
|
732
|
+
this._live = {
|
|
733
|
+
peers: { get: () => this._peers(), watch: (fn) => this._onPeers(fn) },
|
|
734
|
+
audio: lane('audio'),
|
|
735
|
+
video: lane('video'),
|
|
736
|
+
screen: lane('screen')
|
|
737
|
+
}
|
|
738
|
+
// what the worker's side is now, for the WebRTC here
|
|
739
|
+
/** @private @type {import('../lib/media.js').Bridge} */
|
|
740
|
+
this._bridge = { self: null, peers: [] }
|
|
741
|
+
const webrtc = parent._webrtc
|
|
742
|
+
const report = (err) => this.signal.aborted || parent._onerror(err)
|
|
743
|
+
/** @private */
|
|
744
|
+
this._media = webrtc
|
|
745
|
+
? new Media(webrtc, {
|
|
746
|
+
send: (peer, port, data) => this._verb('signal', peer, port, data).catch(report),
|
|
747
|
+
onchange: () => this._changed(),
|
|
748
|
+
onerror: report
|
|
749
|
+
})
|
|
750
|
+
: null
|
|
751
|
+
const peers = this.watch('peers')
|
|
752
|
+
peers.on('data', () => this._changed())
|
|
753
|
+
peers.on('error', () => {})
|
|
754
|
+
peers.on('close', () => this._shut())
|
|
755
|
+
// this device's lanes: what a lane reads as, and where the WebRTC here starts from
|
|
756
|
+
this._follow('_lanes', (self) => {
|
|
757
|
+
this._bridge.self = self ?? null
|
|
758
|
+
this._changed()
|
|
759
|
+
})
|
|
760
|
+
if (!this._media) return
|
|
761
|
+
this._media.share(stream)
|
|
762
|
+
this._follow('_ports', (ports) => (this._bridge.peers = ports))
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/** @private */
|
|
766
|
+
_follow(name, take) {
|
|
767
|
+
const feed = this.watch(name)
|
|
768
|
+
feed.on('data', ({ data }) => {
|
|
769
|
+
take(data)
|
|
770
|
+
this._media?.update(this._bridge)
|
|
771
|
+
})
|
|
772
|
+
feed.on('error', () => {})
|
|
773
|
+
this._feeds.push(feed)
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Tie a watch to the line: it ends when the line closes.
|
|
778
|
+
*
|
|
779
|
+
* @template {import('streamx').Readable} T
|
|
780
|
+
* @param {T} stream
|
|
781
|
+
* @returns {T}
|
|
782
|
+
*/
|
|
783
|
+
own(stream) {
|
|
784
|
+
if (this.signal.aborted) {
|
|
785
|
+
stream.push(null)
|
|
786
|
+
return stream
|
|
787
|
+
}
|
|
788
|
+
this._owned.add(stream)
|
|
789
|
+
stream.once('close', () => this._owned.delete(stream))
|
|
790
|
+
return stream
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/** Underlying RPC channel borrowed from the parent. */
|
|
794
|
+
get rpc() {
|
|
795
|
+
return this.parent.rpc
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/** @returns {AbortSignal} fires when the line closes */
|
|
799
|
+
get signal() {
|
|
800
|
+
return this._ac.signal
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
close() {
|
|
804
|
+
this._media?.close()
|
|
805
|
+
return this._release()
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// once: the worker keeps a line that closed until this side lets it go
|
|
809
|
+
/** @private */
|
|
810
|
+
_release() {
|
|
811
|
+
return (this._released ??= this.rpc.closeHandle({ handle: this.id }))
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/** @private */
|
|
815
|
+
async _finish() {
|
|
816
|
+
if (this.signal.aborted) throw CeroError.CLOSED('Line')
|
|
817
|
+
await this._verb('end')
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// the local tracks at once, then the flag every device sees
|
|
821
|
+
/** @private */
|
|
822
|
+
async _lane(lane, on) {
|
|
823
|
+
if (this.signal.aborted) throw CeroError.CLOSED('Line')
|
|
824
|
+
this._media?.lane(lane, on)
|
|
825
|
+
await this._verb('lane', lane, on)
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// a stream never crosses: it stays with the WebRTC here
|
|
829
|
+
/** @private */
|
|
830
|
+
async _share(kind, stream) {
|
|
831
|
+
if (this.signal.aborted) throw CeroError.CLOSED('Line')
|
|
832
|
+
if (kind !== 'screen') return this._media?.share(stream)
|
|
833
|
+
// with no WebRTC here there is no screen to show; taking one down is for any side to say
|
|
834
|
+
if (!this._media && stream) return
|
|
835
|
+
this._media?.present(stream)
|
|
836
|
+
await this._verb('lane', 'screen', !!stream)
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** @private */
|
|
840
|
+
async _peers() {
|
|
841
|
+
if (this.signal.aborted) return { data: [], total: 0, size: 0 }
|
|
842
|
+
const res = await this.get('peers')
|
|
843
|
+
// a stream never crosses: with no WebRTC here there is none
|
|
844
|
+
const media = (row) => this._media?.entry(row.id, row.sharing) ?? { stream: null, screen: null }
|
|
845
|
+
return { ...res, data: res.data.map((row) => ({ ...row, ...media(row) })) }
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// a lane reads as on or off, as this device's row shows it in the worker
|
|
849
|
+
/** @private */
|
|
850
|
+
async _on(name) {
|
|
851
|
+
if (this.signal.aborted) return { data: null }
|
|
852
|
+
return { data: (await this.get('_lanes')).data?.[name] ?? null }
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/** @private */
|
|
856
|
+
_onPeers(fn) {
|
|
857
|
+
this._fns.add(fn)
|
|
858
|
+
return () => this._fns.delete(fn)
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/** @private */
|
|
862
|
+
_changed() {
|
|
863
|
+
for (const fn of this._fns) fn()
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** @private */
|
|
867
|
+
_shut() {
|
|
868
|
+
this._media?.close()
|
|
869
|
+
for (const feed of this._feeds) feed.destroy()
|
|
870
|
+
this._fns.clear()
|
|
871
|
+
for (const stream of [...this._owned]) stream.push(null)
|
|
872
|
+
this._ac.abort()
|
|
873
|
+
this._release().catch(() => {})
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
665
877
|
/**
|
|
666
878
|
* Construct a `Client`, wait for `init` to complete, and return it.
|
|
667
879
|
*
|
package/src/rpc/server.js
CHANGED
|
@@ -29,8 +29,11 @@ import {
|
|
|
29
29
|
phrase,
|
|
30
30
|
nearby,
|
|
31
31
|
receive,
|
|
32
|
-
send
|
|
32
|
+
send,
|
|
33
|
+
dial,
|
|
34
|
+
end
|
|
33
35
|
} from '../lib/operators.js'
|
|
36
|
+
import { Line } from '../extensions/calls.js'
|
|
34
37
|
|
|
35
38
|
// what a UI reaches by name: these operators, never close or a handle's privates
|
|
36
39
|
const VERBS = new Map(
|
|
@@ -49,10 +52,21 @@ const VERBS = new Map(
|
|
|
49
52
|
phrase,
|
|
50
53
|
nearby,
|
|
51
54
|
receive,
|
|
52
|
-
send
|
|
55
|
+
send,
|
|
56
|
+
dial,
|
|
57
|
+
end,
|
|
58
|
+
// the UI's microphone, camera or screen, on or off: the worker's line writes the flag
|
|
59
|
+
lane: (line, name, on) => lined(line)._lane(name, on),
|
|
60
|
+
// the UI's WebRTC reaches the other devices through the worker's line
|
|
61
|
+
signal: (line, id, port, data) => lined(line)._signal(id, port, data)
|
|
53
62
|
})
|
|
54
63
|
)
|
|
55
64
|
|
|
65
|
+
function lined(line) {
|
|
66
|
+
if (!(line instanceof Line)) throw CeroError.INVALID('a line verb takes a line')
|
|
67
|
+
return line
|
|
68
|
+
}
|
|
69
|
+
|
|
56
70
|
/**
|
|
57
71
|
* @typedef {import('@cero-base/core/rpc').RPCServer} BaseRPCServer
|
|
58
72
|
*
|
|
@@ -118,6 +132,8 @@ export class Server extends RPCServer {
|
|
|
118
132
|
this._wireInit()
|
|
119
133
|
this._wireRestore()
|
|
120
134
|
this._wireLink()
|
|
135
|
+
// a UI that goes away closes nothing: what it held is let go for it, its calls left
|
|
136
|
+
this.framed.once('close', () => this.closing || this._letGo().catch(safetyCatch))
|
|
121
137
|
}
|
|
122
138
|
|
|
123
139
|
/**
|
|
@@ -491,11 +507,22 @@ export class Server extends RPCServer {
|
|
|
491
507
|
this._on('onVerb', async ({ handle, verb, args }) => {
|
|
492
508
|
const run = VERBS.get(verb)
|
|
493
509
|
if (!run) throw CeroError.UNKNOWN('verb', verb)
|
|
494
|
-
const
|
|
510
|
+
const out = await run(this._resolve(handle), ...c.decode(c.any, args))
|
|
511
|
+
const data = out instanceof Line ? this._line(out) : out
|
|
495
512
|
return { data: data === undefined ? null : c.encode(c.any, data) }
|
|
496
513
|
})
|
|
497
514
|
}
|
|
498
515
|
|
|
516
|
+
/**
|
|
517
|
+
* A line the UI dialed is reached by its id, as a handle is, until the UI lets it go: one that
|
|
518
|
+
* closed answers as closed in between.
|
|
519
|
+
* @private
|
|
520
|
+
*/
|
|
521
|
+
_line(line) {
|
|
522
|
+
if (this.handles.get(line.id) !== line) this._hold(line.id, line)
|
|
523
|
+
return { id: line.id }
|
|
524
|
+
}
|
|
525
|
+
|
|
499
526
|
/**
|
|
500
527
|
* Register a request handler whose error fails only its call.
|
|
501
528
|
* @private
|
package/types/build/schemas.d.ts
CHANGED
|
@@ -175,6 +175,28 @@ export declare const main: {
|
|
|
175
175
|
pass: import("@cero-base/core").Prim;
|
|
176
176
|
createdAt: import("@cero-base/core").Prim;
|
|
177
177
|
};
|
|
178
|
+
'line-peer': {
|
|
179
|
+
id: import("@cero-base/core").Prim;
|
|
180
|
+
member: import("@cero-base/core").Prim;
|
|
181
|
+
audio: import("@cero-base/core").Prim;
|
|
182
|
+
video: import("@cero-base/core").Prim;
|
|
183
|
+
sharing: import("@cero-base/core").Prim;
|
|
184
|
+
connected: import("@cero-base/core").Prim;
|
|
185
|
+
reconnecting: import("@cero-base/core").Prim;
|
|
186
|
+
};
|
|
187
|
+
'line-lanes': {
|
|
188
|
+
id: import("@cero-base/core").Prim;
|
|
189
|
+
audio: import("@cero-base/core").Prim;
|
|
190
|
+
video: import("@cero-base/core").Prim;
|
|
191
|
+
screen: import("@cero-base/core").Prim;
|
|
192
|
+
};
|
|
193
|
+
'line-port': {
|
|
194
|
+
id: import("@cero-base/core").Prim;
|
|
195
|
+
port: import("@cero-base/core").Prim;
|
|
196
|
+
seq: import("@cero-base/core").Prim;
|
|
197
|
+
type: import("@cero-base/core").Prim;
|
|
198
|
+
sdp: import("@cero-base/core").Prim;
|
|
199
|
+
};
|
|
178
200
|
};
|
|
179
201
|
export declare const local: {
|
|
180
202
|
master: {
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Ref } from '../lib/refs.js';
|
|
2
|
+
/**
|
|
3
|
+
* How often a device on a call beats, how long one stays silent before it is a ghost, how long a
|
|
4
|
+
* call rings once a device sees it, and how old a ring may be when a device first sees it. A test
|
|
5
|
+
* shortens them.
|
|
6
|
+
*/
|
|
7
|
+
export declare const durations: {
|
|
8
|
+
beat: number;
|
|
9
|
+
ghost: number;
|
|
10
|
+
ring: number;
|
|
11
|
+
fresh: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Calls in the app's handles: who is on one, ringing the members it names, the media between them,
|
|
15
|
+
* and the verbs `dial`, `end`, `mute`, `unmute`, `share`, `unshare`, and `deny` on a ring. Every handle type has them, or the `types` named.
|
|
16
|
+
* The rows change only through the actions it declares, under rules every device runs at apply.
|
|
17
|
+
*
|
|
18
|
+
* @param {{ types?: string[] }} [opts]
|
|
19
|
+
* @returns {import('./index.js').Extension}
|
|
20
|
+
*/
|
|
21
|
+
export declare function calls({ types }?: {
|
|
22
|
+
types?: string[];
|
|
23
|
+
}): import('./index.js').Extension;
|
|
24
|
+
/**
|
|
25
|
+
* This device's calls: one line per room, and the rings of the rooms open here.
|
|
26
|
+
*/
|
|
27
|
+
export declare class Calls {
|
|
28
|
+
me: import("../handle/index.js").Context;
|
|
29
|
+
types: Set<string>;
|
|
30
|
+
now: () => number;
|
|
31
|
+
/** @type {Map<string, Promise<Line>>} */
|
|
32
|
+
lines: Map<string, Promise<Line>>;
|
|
33
|
+
/** @private */
|
|
34
|
+
_closed;
|
|
35
|
+
/** @private */
|
|
36
|
+
_timer;
|
|
37
|
+
/** @private */
|
|
38
|
+
_rings;
|
|
39
|
+
/** @private @type {Map<string, { key: string, until: number }>} */
|
|
40
|
+
_seen;
|
|
41
|
+
/** @private @type {Map<string, Promise<void>>} */
|
|
42
|
+
_hangups;
|
|
43
|
+
/** @private @type {Map<string, import('../handle/index.js').Context>} */
|
|
44
|
+
_kept;
|
|
45
|
+
/** @private */
|
|
46
|
+
_onhandle;
|
|
47
|
+
/**
|
|
48
|
+
* @param {import('../handle/index.js').Context} me
|
|
49
|
+
* @param {string[]} types The handle types with calls.
|
|
50
|
+
*/
|
|
51
|
+
constructor(me: import('../handle/index.js').Context, types: string[]);
|
|
52
|
+
/** @private */
|
|
53
|
+
private _resume;
|
|
54
|
+
/** @private */
|
|
55
|
+
private _mark;
|
|
56
|
+
/** @private */
|
|
57
|
+
private _unlist;
|
|
58
|
+
/**
|
|
59
|
+
* @param {import('../handle/index.js').Context} room
|
|
60
|
+
* @param {{ to?: string[] | null, stream?: MediaStream | null }} [opts]
|
|
61
|
+
* @returns {Promise<Line>}
|
|
62
|
+
*/
|
|
63
|
+
dial(room: import('../handle/index.js').Context, { to, stream }?: {
|
|
64
|
+
to?: string[] | null;
|
|
65
|
+
stream?: MediaStream | null;
|
|
66
|
+
}): Promise<Line>;
|
|
67
|
+
/** @param {import('../handle/index.js').Context} room @param {string} reason */
|
|
68
|
+
deny(room: import('../handle/index.js').Context, reason: string): Promise<void>;
|
|
69
|
+
/** @param {import('../handle/index.js').Context} ctx */
|
|
70
|
+
hangup(ctx: import('../handle/index.js').Context): Promise<void>;
|
|
71
|
+
close(): void;
|
|
72
|
+
/** @private */
|
|
73
|
+
private _gone;
|
|
74
|
+
/** @private */
|
|
75
|
+
private _open;
|
|
76
|
+
/** @private */
|
|
77
|
+
private _follow;
|
|
78
|
+
/** @private */
|
|
79
|
+
private _queue;
|
|
80
|
+
/** @private */
|
|
81
|
+
private _ring;
|
|
82
|
+
/** @private */
|
|
83
|
+
private _expire;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* This device on a room's call. Its state is the room's rows; it closes when its own row goes. It
|
|
87
|
+
* holds a connection to each other device on the call, and with WebRTC here, the media over them.
|
|
88
|
+
*/
|
|
89
|
+
export declare class Line {
|
|
90
|
+
id: string;
|
|
91
|
+
audio: Ref;
|
|
92
|
+
video: Ref;
|
|
93
|
+
screen: Ref;
|
|
94
|
+
spec: import("../lib/line.js").Wire;
|
|
95
|
+
peers: Ref;
|
|
96
|
+
closed: boolean;
|
|
97
|
+
/** @private */
|
|
98
|
+
_calls;
|
|
99
|
+
/** @private */
|
|
100
|
+
_room;
|
|
101
|
+
/** @private */
|
|
102
|
+
_device;
|
|
103
|
+
/** @private */
|
|
104
|
+
_stream;
|
|
105
|
+
/** @private */
|
|
106
|
+
_ac;
|
|
107
|
+
/** @private */
|
|
108
|
+
_owned;
|
|
109
|
+
/** @private */
|
|
110
|
+
_fns;
|
|
111
|
+
/** @private */
|
|
112
|
+
_feeds;
|
|
113
|
+
/** @private */
|
|
114
|
+
_lanes;
|
|
115
|
+
/** @private */
|
|
116
|
+
_ports;
|
|
117
|
+
/** @private */
|
|
118
|
+
_live;
|
|
119
|
+
/** @private */
|
|
120
|
+
_key;
|
|
121
|
+
/** @private @type {Map<string, string>} */
|
|
122
|
+
_keys;
|
|
123
|
+
/** @private @type {Set<string>} */
|
|
124
|
+
_met;
|
|
125
|
+
/** @private @type {Map<string, { port: number, sent: { seq: number } & import('../lib/media.js').Signal }>} */
|
|
126
|
+
_signals;
|
|
127
|
+
/** @private */
|
|
128
|
+
_seq;
|
|
129
|
+
/** @private @type {import('../lib/media.js').Bridge['self']} */
|
|
130
|
+
_mine;
|
|
131
|
+
/** @private */
|
|
132
|
+
_call;
|
|
133
|
+
/** @private */
|
|
134
|
+
_media;
|
|
135
|
+
/** @private */
|
|
136
|
+
_sleeping;
|
|
137
|
+
/** @private @type {Promise<void> | null} */
|
|
138
|
+
_closing;
|
|
139
|
+
/** @private */
|
|
140
|
+
_updating;
|
|
141
|
+
/** @private */
|
|
142
|
+
_beat;
|
|
143
|
+
/** @private */
|
|
144
|
+
_beating;
|
|
145
|
+
/** @private */
|
|
146
|
+
_ghost;
|
|
147
|
+
/** @private */
|
|
148
|
+
_offs;
|
|
149
|
+
/**
|
|
150
|
+
* @param {Calls} calls
|
|
151
|
+
* @param {import('../handle/index.js').Context} room
|
|
152
|
+
* @param {string} device This device's id in the room, its `participants` row.
|
|
153
|
+
* @param {MediaStream | null} stream
|
|
154
|
+
* @param {{ publicKey: Uint8Array, secretKey: Uint8Array }} keyPair This device's key pair on the room's calls.
|
|
155
|
+
*/
|
|
156
|
+
constructor(calls: Calls, room: import('../handle/index.js').Context, device: string, stream: MediaStream | null, keyPair: {
|
|
157
|
+
publicKey: Uint8Array;
|
|
158
|
+
secretKey: Uint8Array;
|
|
159
|
+
});
|
|
160
|
+
/** @returns {AbortSignal} fires when the line closes */
|
|
161
|
+
get signal(): AbortSignal;
|
|
162
|
+
/**
|
|
163
|
+
* Tie a watch to the line: it ends when the line closes.
|
|
164
|
+
*
|
|
165
|
+
* @template {import('streamx').Readable} T
|
|
166
|
+
* @param {T} stream
|
|
167
|
+
* @returns {T}
|
|
168
|
+
*/
|
|
169
|
+
own<T extends import('streamx').Readable>(stream: T): T;
|
|
170
|
+
/** Leave the call: it goes on for the others, and ends with the last device on it. */
|
|
171
|
+
close(): Promise<void>;
|
|
172
|
+
/** @private */
|
|
173
|
+
private _finish;
|
|
174
|
+
/** @private */
|
|
175
|
+
private _add;
|
|
176
|
+
/** @private */
|
|
177
|
+
private _lane;
|
|
178
|
+
/** @private */
|
|
179
|
+
private _share;
|
|
180
|
+
/** @private */
|
|
181
|
+
private _signal;
|
|
182
|
+
/** @private */
|
|
183
|
+
private _at;
|
|
184
|
+
/** @private */
|
|
185
|
+
private _drop;
|
|
186
|
+
/** @private */
|
|
187
|
+
private _shut;
|
|
188
|
+
/** @private */
|
|
189
|
+
private _rows;
|
|
190
|
+
/** @private */
|
|
191
|
+
private _peers;
|
|
192
|
+
/** @private */
|
|
193
|
+
private _own;
|
|
194
|
+
/** @private */
|
|
195
|
+
private _entry;
|
|
196
|
+
/** @private */
|
|
197
|
+
private _onPeers;
|
|
198
|
+
/** @private */
|
|
199
|
+
private _onFeed;
|
|
200
|
+
/** @private */
|
|
201
|
+
private _changed;
|
|
202
|
+
/** @private */
|
|
203
|
+
private _feed;
|
|
204
|
+
/** @private */
|
|
205
|
+
private _tell;
|
|
206
|
+
/** @private */
|
|
207
|
+
private _moved;
|
|
208
|
+
/** @private */
|
|
209
|
+
private _heard;
|
|
210
|
+
/** @private */
|
|
211
|
+
private _update;
|
|
212
|
+
/** @private */
|
|
213
|
+
private _schedule;
|
|
214
|
+
/** @private */
|
|
215
|
+
private _pulse;
|
|
216
|
+
/** @private */
|
|
217
|
+
private _report;
|
|
218
|
+
}
|