@rapidmx/meet-plugin 0.14.1 → 0.16.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 +35 -55
- package/apps/meet/[token].tsx +341 -341
- package/apps/meet/_CallControls.tsx +508 -463
- package/apps/meet/_CallView.tsx +1060 -891
- package/apps/meet/_ChatPanel.tsx +194 -0
- package/apps/meet/_ColorWheel.tsx +136 -0
- package/apps/meet/_DiagnosticsPanel.tsx +65 -7
- package/apps/meet/_MeetLobby.tsx +224 -224
- package/apps/meet/_ParticipantTile.tsx +243 -169
- package/apps/meet/_ParticipantsDrawer.tsx +10 -7
- package/apps/meet/_Whiteboard.tsx +577 -0
- package/apps/meet/_icons.tsx +135 -80
- package/apps/meet/_meetApi.ts +213 -212
- package/apps/shared/collab/CollabSession.ts +675 -0
- package/apps/shared/collab/WhiteboardModel.ts +216 -0
- package/apps/shared/collab/chatMarkdown.tsx +375 -0
- package/apps/shared/collab/color.ts +67 -0
- package/apps/shared/collab/protocol.ts +321 -0
- package/apps/shared/collab/whiteboardRender.ts +311 -0
- package/apps/shared/media/filters/VideoFilterProcessor.ts +408 -408
- package/apps/shared/media/filters/mlModels.ts +174 -174
- package/apps/shared/relay/AudioPlayer.ts +29 -0
- package/apps/shared/relay/AudioSender.ts +23 -0
- package/apps/shared/relay/RelayClient.ts +54 -2
- package/apps/shared/relay/RelayReceiver.ts +43 -2
- package/apps/shared/relay/RelaySender.ts +23 -1
- package/apps/shared/relay/RelayTransport.ts +21 -1
- package/apps/shared/relay/SilenceMeter.ts +59 -0
- package/apps/shared/relay/relayEnv.ts +1 -1
- package/apps/shared/signaling/SignalingClient.ts +335 -0
- package/apps/shared/webrtc/MeshConnectionManager.ts +971 -949
- package/apps/shared/webrtc/types.ts +335 -247
- package/dist/apps/meet/[token].js +1 -1
- package/dist/apps/meet/_CallControls.d.ts +21 -6
- package/dist/apps/meet/_CallControls.js +14 -8
- package/dist/apps/meet/_CallView.d.ts +36 -7
- package/dist/apps/meet/_CallView.js +132 -16
- package/dist/apps/meet/_ChatPanel.d.ts +24 -0
- package/dist/apps/meet/_ChatPanel.js +116 -0
- package/dist/apps/meet/_ColorWheel.d.ts +14 -0
- package/dist/apps/meet/_ColorWheel.js +82 -0
- package/dist/apps/meet/_DiagnosticsPanel.d.ts +5 -3
- package/dist/apps/meet/_DiagnosticsPanel.js +17 -1
- package/dist/apps/meet/_ParticipantTile.d.ts +11 -3
- package/dist/apps/meet/_ParticipantTile.js +36 -5
- package/dist/apps/meet/_ParticipantsDrawer.js +3 -3
- package/dist/apps/meet/_Whiteboard.d.ts +64 -0
- package/dist/apps/meet/_Whiteboard.js +312 -0
- package/dist/apps/meet/_icons.d.ts +16 -0
- package/dist/apps/meet/_icons.js +16 -0
- package/dist/apps/meet/_meetApi.d.ts +8 -7
- package/dist/apps/meet/_meetApi.js +2 -2
- package/dist/apps/shared/collab/CollabSession.d.ts +208 -0
- package/dist/apps/shared/collab/CollabSession.js +559 -0
- package/dist/apps/shared/collab/WhiteboardModel.d.ts +54 -0
- package/dist/apps/shared/collab/WhiteboardModel.js +197 -0
- package/dist/apps/shared/collab/chatMarkdown.d.ts +65 -0
- package/dist/apps/shared/collab/chatMarkdown.js +311 -0
- package/dist/apps/shared/collab/color.d.ts +18 -0
- package/dist/apps/shared/collab/color.js +59 -0
- package/dist/apps/shared/collab/protocol.d.ts +157 -0
- package/dist/apps/shared/collab/protocol.js +222 -0
- package/dist/apps/shared/collab/whiteboardRender.d.ts +31 -0
- package/dist/apps/shared/collab/whiteboardRender.js +268 -0
- package/dist/apps/shared/relay/AudioPlayer.d.ts +9 -0
- package/dist/apps/shared/relay/AudioPlayer.js +24 -4
- package/dist/apps/shared/relay/AudioSender.d.ts +8 -0
- package/dist/apps/shared/relay/AudioSender.js +20 -4
- package/dist/apps/shared/relay/RelayClient.d.ts +16 -0
- package/dist/apps/shared/relay/RelayClient.js +46 -2
- package/dist/apps/shared/relay/RelayReceiver.d.ts +5 -0
- package/dist/apps/shared/relay/RelayReceiver.js +38 -6
- package/dist/apps/shared/relay/RelaySender.d.ts +7 -0
- package/dist/apps/shared/relay/RelaySender.js +20 -5
- package/dist/apps/shared/relay/RelayTransport.d.ts +6 -1
- package/dist/apps/shared/relay/RelayTransport.js +16 -1
- package/dist/apps/shared/relay/SilenceMeter.d.ts +25 -0
- package/dist/apps/shared/relay/SilenceMeter.js +55 -0
- package/dist/apps/shared/relay/relayEnv.d.ts +1 -1
- package/dist/apps/shared/signaling/SignalingClient.d.ts +95 -0
- package/dist/apps/shared/signaling/SignalingClient.js +278 -0
- package/dist/apps/shared/webrtc/MeshConnectionManager.d.ts +7 -7
- package/dist/apps/shared/webrtc/MeshConnectionManager.js +28 -9
- package/dist/apps/shared/webrtc/types.d.ts +104 -26
- package/dist/apps/shared/webrtc/types.js +3 -4
- package/dist/lib/routes/BaseVideoMeetingRoute.js +171 -69
- package/dist/lib/routes/BaseVideoMeetingRoute.js.map +1 -1
- package/dist/lib/util/RelayHub.js +15 -2
- package/dist/lib/util/RelayHub.js.map +1 -1
- package/dist/lib/util/SignalingHub.js +339 -0
- package/dist/lib/util/SignalingHub.js.map +1 -0
- package/dist/types/routes/BaseVideoMeetingRoute.d.ts +68 -46
- package/dist/types/util/RelayHub.d.ts +5 -2
- package/dist/types/util/SignalingHub.d.ts +112 -0
- package/package.json +208 -208
- package/apps/shared/push/GuestSignalingClient.ts +0 -359
- package/dist/apps/shared/push/GuestSignalingClient.d.ts +0 -98
- package/dist/apps/shared/push/GuestSignalingClient.js +0 -312
|
@@ -1,247 +1,335 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
|
|
3
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
/** Shared types for `MeshConnectionManager.ts` and its signaling transport (`apps/shared/
|
|
6
|
-
* kept in their own module so a test can depend on the shapes alone. `
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* - `"
|
|
28
|
-
*
|
|
29
|
-
* `"
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
* and
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* `hello`/`bye`/`presenter-claim`/`presenter-release`/`state`/`reaction`/`talking-stick` are broadcast (`to` left
|
|
47
|
-
* unset - every participant
|
|
48
|
-
* point-to-point (`to` is the intended peer's
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* (
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
| "
|
|
71
|
-
| "
|
|
72
|
-
| "
|
|
73
|
-
| "
|
|
74
|
-
| "
|
|
75
|
-
| "
|
|
76
|
-
| "
|
|
77
|
-
| "
|
|
78
|
-
| "
|
|
79
|
-
| "
|
|
80
|
-
| "
|
|
81
|
-
| "
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
/** `
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
*
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
/** The
|
|
162
|
-
*
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
export interface
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
/** One
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
*
|
|
247
|
-
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
/** Shared types for `MeshConnectionManager.ts` and its signaling transport (`apps/shared/signaling/SignalingClient.ts`) -
|
|
6
|
+
* kept in their own module so a test can depend on the shapes alone. `SignalingClient` serves both a guest and an
|
|
7
|
+
* already-authenticated real caller (`VideoMeetingJoinResult.authenticated`) - see its own doc comment. */
|
|
8
|
+
|
|
9
|
+
/** What a participant is sending, and whether their hand is up. Announced in `hello` and re-sent as a `state`
|
|
10
|
+
* message on every change, so a tile can show a muted microphone, an avatar for a camera that is off, and a raised
|
|
11
|
+
* hand without inspecting the media itself (the far end of a `replaceTrack(null)` gives no dependable signal that
|
|
12
|
+
* the track stopped). */
|
|
13
|
+
export interface ParticipantState {
|
|
14
|
+
audioOn: boolean;
|
|
15
|
+
videoOn: boolean;
|
|
16
|
+
handRaised: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The emoji a participant can send during a call. A received `reaction` outside this list is ignored, so an
|
|
20
|
+
* arbitrary string from another participant is never rendered. */
|
|
21
|
+
export const REACTION_EMOJIS = ["👍", "👏", "❤️", "🎉", "😂", "😮", "😢", "👋"] as const;
|
|
22
|
+
|
|
23
|
+
/** Which media path this participant's own tab currently insists on, for every peer - see
|
|
24
|
+
* `MeshConnectionManager.setTransportMode()`'s doc comment for what each one actually does:
|
|
25
|
+
*
|
|
26
|
+
* - `"auto"`: the default waterfall (direct, then TURN, then the server's own WebSocket relay) - unchanged behavior.
|
|
27
|
+
* - `"p2p"`: direct connections only - no TURN server offered to ICE, and a pair that can't connect directly stays
|
|
28
|
+
* `"failed"` rather than falling back to the WebSocket relay.
|
|
29
|
+
* - `"relay"`: TURN-relayed WebRTC only (`RTCPeerConnection`'s own `iceTransportPolicy: "relay"`) - still real
|
|
30
|
+
* WebRTC, just never direct; a pair with no reachable TURN server stays `"failed"`, same "no further fallback" rule
|
|
31
|
+
* as `"p2p"`.
|
|
32
|
+
* - `"websocket"`: skips WebRTC negotiation entirely for every pair and goes straight to the server's own relay.
|
|
33
|
+
*
|
|
34
|
+
* A purely personal, per-tab troubleshooting choice - never transmitted as a setting, and independent of whatever
|
|
35
|
+
* every other participant has chosen for their own tab. */
|
|
36
|
+
export type TransportMode = "auto" | "p2p" | "relay" | "websocket";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* One WebRTC signaling message, sent as the `data` of a `{"op":"signal"}` frame over the meeting's own signaling
|
|
40
|
+
* WebSocket (`apps/shared/signaling/SignalingClient.ts`, served by `BaseVideoMeetingRoute.signal()` and the backend's
|
|
41
|
+
* `SignalingHub`) and delivered to the other participants the same way. `type` is a fixed literal so a listener can
|
|
42
|
+
* cheaply recognize and skip anything that isn't one of these.
|
|
43
|
+
*
|
|
44
|
+
* `chat`/`whiteboard` (see `../collab/CollabSession.ts`) are broadcast like `reaction`.
|
|
45
|
+
*
|
|
46
|
+
* `hello`/`bye`/`presenter-claim`/`presenter-release`/`state`/`reaction`/`talking-stick` are broadcast (`to` left
|
|
47
|
+
* unset - every other participant receives it); `offer`/`answer`/`ice-candidate`/`mute-request`/`kicked` are
|
|
48
|
+
* point-to-point (`to` is the intended peer's id) - the server delivers one only to the socket of that peer, so
|
|
49
|
+
* nobody else ever sees it. The sender never receives its own messages back either. (A recipient still ignores a
|
|
50
|
+
* message whose `to` isn't itself, and its own messages - harmless with this transport, and kept so
|
|
51
|
+
* `MeshConnectionManager` does not depend on how its transport routes.)
|
|
52
|
+
*
|
|
53
|
+
* `mute-request`/`kicked`/`talking-stick` are host moderation signals (see `MeshConnectionManager`'s doc comment) -
|
|
54
|
+
* purely cooperative, like every other message here: the recipient's own client decides whether to honor one, and
|
|
55
|
+
* nothing on the wire distinguishes a genuine host's message from any other participant's, since this client
|
|
56
|
+
* protocol has no host identity of its own to check against server-side. `kicked` is paired with the sender also
|
|
57
|
+
* revoking the recipient's server-side channel grant (`BaseVideoMeetingRoute.revokeChannelGrant()`), which is
|
|
58
|
+
* enforced and does not depend on the recipient's client cooperating; `talking-stick` has no server-side
|
|
59
|
+
* counterpart at all (see this module's doc comment on why it is purely an in-call runtime signal).
|
|
60
|
+
*
|
|
61
|
+
* `restart-connection` is broadcast whenever a participant changes their own `TransportMode`
|
|
62
|
+
* (`MeshConnectionManager.setTransportMode()`): every connection of theirs needs rebuilding under the new policy,
|
|
63
|
+
* and a recipient can't rebuild its own half of a pair unilaterally without the other side doing the same at
|
|
64
|
+
* (almost) the same moment, or the two sides end up negotiating against two different `RTCPeerConnection`s. No
|
|
65
|
+
* payload beyond the envelope - `from` already says whose connection to rebuild.
|
|
66
|
+
*/
|
|
67
|
+
export interface SignalMessage {
|
|
68
|
+
type: "video-meeting-signal";
|
|
69
|
+
kind:
|
|
70
|
+
| "hello"
|
|
71
|
+
| "bye"
|
|
72
|
+
| "offer"
|
|
73
|
+
| "answer"
|
|
74
|
+
| "ice-candidate"
|
|
75
|
+
| "presenter-claim"
|
|
76
|
+
| "presenter-release"
|
|
77
|
+
| "state"
|
|
78
|
+
| "reaction"
|
|
79
|
+
| "relay-fallback"
|
|
80
|
+
| "mute-request"
|
|
81
|
+
| "kicked"
|
|
82
|
+
| "talking-stick"
|
|
83
|
+
| "restart-connection"
|
|
84
|
+
| "chat"
|
|
85
|
+
| "whiteboard"
|
|
86
|
+
| "collab-sync-request"
|
|
87
|
+
| "collab-sync"
|
|
88
|
+
| "whiteboard-cursor";
|
|
89
|
+
/** The sender's authenticated uid - the real caller's own uid when `join()` returned `authenticated: true`, else
|
|
90
|
+
* the `guest:<random>` uid `BaseVideoMeetingRoute.join()` minted. The server overwrites whatever the sender put
|
|
91
|
+
* here with the uid its signaling socket authenticated as (it stops one participant speaking as another), so a
|
|
92
|
+
* received message's `from` is always that uid. */
|
|
93
|
+
from: string;
|
|
94
|
+
/** Which of the sender's tabs or devices this is: `<from>~<random>`. The same account joining from two devices is
|
|
95
|
+
* two participants, not one that ignores its own messages. The server overwrites it with the peer id the sender's
|
|
96
|
+
* socket announced in its `hello` (which must be `<from>` or start with `<from>~`), so every received message
|
|
97
|
+
* carries one; a received `peer` that is neither is still ignored, so it can't name someone else's tab, and one
|
|
98
|
+
* that is absent identifies the participant by `from`. */
|
|
99
|
+
peer?: string;
|
|
100
|
+
/** Set only on a point-to-point message (`offer`/`answer`/`ice-candidate`/`relay-fallback`). */
|
|
101
|
+
to?: string;
|
|
102
|
+
/** `hello` only - the display name the sender chose in the lobby. */
|
|
103
|
+
name?: string;
|
|
104
|
+
/** `hello` and `state` - what the sender is currently sending and whether their hand is up. */
|
|
105
|
+
state?: ParticipantState;
|
|
106
|
+
/** `reaction` only - one of `REACTION_EMOJIS`. */
|
|
107
|
+
emoji?: string;
|
|
108
|
+
/** `talking-stick` only - whether talking-stick mode is currently on. */
|
|
109
|
+
active?: boolean;
|
|
110
|
+
/** `talking-stick` only - the peer id (`MeshParticipant.uid`/this tab's own id) currently holding the stick.
|
|
111
|
+
* Absent when `active` is `false`, or when nobody holds it yet. */
|
|
112
|
+
holder?: string;
|
|
113
|
+
/** `offer`/`answer` only. */
|
|
114
|
+
sdp?: RTCSessionDescriptionInit;
|
|
115
|
+
/** `ice-candidate` only. */
|
|
116
|
+
candidate?: RTCIceCandidateInit;
|
|
117
|
+
/** `chat` only - a `ChatPayload` (`../collab/protocol.ts`), validated by `parseChat()` before use. Typed `unknown`
|
|
118
|
+
* since it is another participant's input until then; the same goes for the next two. */
|
|
119
|
+
chat?: unknown;
|
|
120
|
+
/** `whiteboard` only - a `WhiteboardOp`, validated by `parseWhiteboardOp()`. */
|
|
121
|
+
whiteboard?: unknown;
|
|
122
|
+
/** `collab-sync` only - one `SyncPayload` part of a newcomer's catch-up, validated by `parseSync()`. `collab-sync`
|
|
123
|
+
* and `collab-sync-request` are point-to-point (`to` set) - see `CollabSession`'s doc comment. */
|
|
124
|
+
sync?: unknown;
|
|
125
|
+
/** `whiteboard-cursor` only - a `CursorPayload`, validated by `parseCursor()`; broadcast, never stored. */
|
|
126
|
+
cursor?: unknown;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** What `MeshConnectionManager` needs from a signaling transport - implemented by
|
|
130
|
+
* `apps/shared/signaling/SignalingClient.ts` for a real call, and by an in-memory fake for `MeshConnectionManager`'s own
|
|
131
|
+
* tests (see `test/apps/shared/webrtc/MeshConnectionManager.test.ts`), which never opens a real network connection. */
|
|
132
|
+
export interface SignalingChannel {
|
|
133
|
+
send(message: SignalMessage): void;
|
|
134
|
+
/** Calls `handler` with every message received on the channel. `SignalingClient` never delivers this client's own
|
|
135
|
+
* sends, nor a `to`-addressed message meant for another peer, but `MeshConnectionManager` filters both out itself
|
|
136
|
+
* rather than relying on the transport to (its tests' fake echoes everything to everyone). Returns the function
|
|
137
|
+
* that stops listening. */
|
|
138
|
+
onMessage(handler: (message: SignalMessage) => void): () => void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** One kind's RTP stream stats, as of one sample - cumulative counters (`bytesSent`/`bytesReceived`), not a rate,
|
|
142
|
+
* since a single `getStats()` snapshot has no "since when" to divide by; a caller wanting a bitrate keeps the
|
|
143
|
+
* previous sample itself and divides the difference by the elapsed time (see `MeshConnectionManager`'s poller).
|
|
144
|
+
* `undefined` for anything this browser (or this stream's direction - an audio-only connection reports nothing for
|
|
145
|
+
* video, and vice versa) doesn't report. */
|
|
146
|
+
export interface RtpStreamDiagnostics {
|
|
147
|
+
packetsLost?: number;
|
|
148
|
+
/** Seconds. */
|
|
149
|
+
jitter?: number;
|
|
150
|
+
bytesSent?: number;
|
|
151
|
+
bytesReceived?: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** One point-in-time sample of a connection's own quality stats, for the diagnostics panel. */
|
|
155
|
+
export interface ConnectionDiagnostics {
|
|
156
|
+
/** Seconds - the selected candidate pair's own current round-trip time. `undefined` when this browser doesn't
|
|
157
|
+
* report one (a connection still connecting, or simply not supported). */
|
|
158
|
+
roundTripTimeSeconds?: number;
|
|
159
|
+
audio: RtpStreamDiagnostics;
|
|
160
|
+
video: RtpStreamDiagnostics;
|
|
161
|
+
/** The WebSocket relay's own counters, present only for a `"websocket"` pair - `audio`/`video` then carry the
|
|
162
|
+
* subset of them that maps onto RTP stats (frames lost, bytes each way). */
|
|
163
|
+
relay?: RelayDiagnostics;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** What the relay's sending half did with one kind of frame, cumulative since the relay transport was created. */
|
|
167
|
+
export interface RelaySendStats {
|
|
168
|
+
framesSent: number;
|
|
169
|
+
/** Frames encoded but not sent: the socket was not ready, backed up, or refused a fragment. */
|
|
170
|
+
framesDropped: number;
|
|
171
|
+
bytesSent: number;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** What the relay's sending half has done, cumulative since the relay transport was created. It is per browser, not
|
|
175
|
+
* per peer: every relayed peer receives the same stream. */
|
|
176
|
+
export interface RelaySendDiagnostics {
|
|
177
|
+
/** Milliseconds of microphone audio the capture path delivered, against `audioCaptureWallMs` - the wall-clock time
|
|
178
|
+
* it was capturing for. Well short of it means capture is losing whole blocks. */
|
|
179
|
+
audioCapturedMs: number;
|
|
180
|
+
audioCaptureWallMs: number;
|
|
181
|
+
/** How much of `audioCapturedMs` was digital silence (see `SilenceMeter`) - a live microphone always has some
|
|
182
|
+
* noise, so a large share means the capture path is handing the encoder zero-filled blocks. */
|
|
183
|
+
audioSilentMs: number;
|
|
184
|
+
/** Milliseconds of captured audio not encoded because the encoder was too far behind. */
|
|
185
|
+
audioEncoderSkippedMs: number;
|
|
186
|
+
audio: RelaySendStats;
|
|
187
|
+
video: RelaySendStats;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** What the relay's receiving half got of one kind of frame from one peer, cumulative. */
|
|
191
|
+
export interface RelayReceiveStats {
|
|
192
|
+
framesReceived: number;
|
|
193
|
+
/** Frames the sequence numbers say never arrived complete - dropped by the sender, the server or in transit. */
|
|
194
|
+
framesLost: number;
|
|
195
|
+
bytesReceived: number;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** What the relay's receiving half has done with one peer's media, cumulative since it started receiving from them. */
|
|
199
|
+
export interface RelayReceiveDiagnostics {
|
|
200
|
+
audio: RelayReceiveStats & {
|
|
201
|
+
/** Milliseconds of decoded audio scheduled for playback. */
|
|
202
|
+
playedMs: number;
|
|
203
|
+
/** How much of `playedMs` was digital silence - silence that arrived inside the packets, i.e. the sender sent
|
|
204
|
+
* it, as opposed to `gapMs`. */
|
|
205
|
+
silentMs: number;
|
|
206
|
+
/** Times playback ran dry and restarted, and the total silence that inserted. */
|
|
207
|
+
gaps: number;
|
|
208
|
+
gapMs: number;
|
|
209
|
+
/** Packets dropped on arrival because the decoder was backed up or playback was already too far ahead. */
|
|
210
|
+
droppedLate: number;
|
|
211
|
+
/** How far ahead of the clock audio is scheduled right now - the receive buffer's current depth. */
|
|
212
|
+
bufferedMs: number;
|
|
213
|
+
};
|
|
214
|
+
video: RelayReceiveStats;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** One sample of the relay's counters for one peer. */
|
|
218
|
+
export interface RelayDiagnostics {
|
|
219
|
+
/** The latest round trip from this browser to the relay server, in milliseconds - not to the peer: the relay has
|
|
220
|
+
* no direct path between the two, and each end only knows its own leg. `undefined` before the first pong, or for
|
|
221
|
+
* a server too old to answer pings. */
|
|
222
|
+
roundTripMs?: number;
|
|
223
|
+
send: RelaySendDiagnostics;
|
|
224
|
+
/** `undefined` when nothing is being received from this peer. */
|
|
225
|
+
receive?: RelayReceiveDiagnostics;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The subset of `RTCRtpSender` `MeshConnectionManager.setLocalTrack()` uses. Every connection carries one audio and
|
|
229
|
+
* one video sender for its whole life (see `MeshConnectionManager`'s doc comment), so turning a camera on or off,
|
|
230
|
+
* switching a device or sharing a screen only ever replaces the track a sender sends - no renegotiation. A real
|
|
231
|
+
* `RTCRtpSender` already satisfies this shape. */
|
|
232
|
+
export interface RTCRtpSenderLike {
|
|
233
|
+
track: MediaStreamTrack | null;
|
|
234
|
+
replaceTrack(track: MediaStreamTrack | null): Promise<void>;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The subset of `RTCPeerConnection` `MeshConnectionManager` uses - what a test's fake implements, and what
|
|
238
|
+
* `apps/shared/webrtc/realPeerConnection.ts` adapts the real browser constructor to. Event handlers are plain settable
|
|
239
|
+
* properties (`RTCPeerConnection`'s own `on*` style) rather than `addEventListener`, matching the browser API
|
|
240
|
+
* this stands in for and keeping a test fake to the bare minimum. */
|
|
241
|
+
export interface RTCPeerConnectionLike {
|
|
242
|
+
/** The offerer's side: adds a send-and-receive transceiver for `kind`, sending `track` when there is one and
|
|
243
|
+
* nothing until `replaceTrack()` supplies it otherwise. */
|
|
244
|
+
addTransceiver(kind: "audio" | "video", track: MediaStreamTrack | null): { sender: RTCRtpSenderLike };
|
|
245
|
+
/** The answerer's side: once the remote offer is applied, turns the transceivers that offer created into
|
|
246
|
+
* send-and-receive ones and returns their senders by kind. (A browser only matches an offer's m-lines to
|
|
247
|
+
* transceivers it created for the offer itself - one the answerer added up front with `addTransceiver()` is left
|
|
248
|
+
* unused, and everything the answerer sends is silently lost.) */
|
|
249
|
+
claimTransceivers(): Partial<Record<"audio" | "video", RTCRtpSenderLike>>;
|
|
250
|
+
createOffer(): Promise<RTCSessionDescriptionInit>;
|
|
251
|
+
createAnswer(): Promise<RTCSessionDescriptionInit>;
|
|
252
|
+
setLocalDescription(description: RTCSessionDescriptionInit): Promise<void>;
|
|
253
|
+
setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void>;
|
|
254
|
+
addIceCandidate(candidate: RTCIceCandidateInit): Promise<void>;
|
|
255
|
+
close(): void;
|
|
256
|
+
onicecandidate: ((event: { candidate: RTCIceCandidateInit | null }) => void) | null;
|
|
257
|
+
ontrack: ((event: { track: MediaStreamTrack }) => void) | null;
|
|
258
|
+
onconnectionstatechange: (() => void) | null;
|
|
259
|
+
connectionState: string;
|
|
260
|
+
/** Which path the connected pair is using - read from the selected candidate pair once `connectionState` is
|
|
261
|
+
* `connected`. `"unknown"` when the browser does not report one (treated as direct by the caller). */
|
|
262
|
+
connectionType(): Promise<"p2p" | "turn" | "turn-tcp" | "unknown">;
|
|
263
|
+
/** One point-in-time sample of this connection's own quality stats, for the diagnostics panel - polled
|
|
264
|
+
* periodically and independently of `connectionType()` (see `MeshConnectionManager`'s doc comment). */
|
|
265
|
+
collectDiagnostics(): Promise<ConnectionDiagnostics>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Which of the three media paths a participant's audio and video currently take, in the order they are tried:
|
|
269
|
+
*
|
|
270
|
+
* - `"p2p"`: a direct peer-to-peer WebRTC connection, the preferred path.
|
|
271
|
+
* - `"turn"`: still WebRTC, but relayed through the TURN server, for a participant a direct path cannot reach.
|
|
272
|
+
* - `"turn-tcp"`: the same, but the relay hop itself is TCP (or `turns:`, TLS being TCP-based too) rather than UDP -
|
|
273
|
+
* a network that blocks UDP outright. TCP's reliable, ordered delivery means one lost or delayed packet stalls
|
|
274
|
+
* everything queued behind it instead of just being dropped, so this can sound like pauses rather than the clicks
|
|
275
|
+
* plain packet loss would - worth telling apart from ordinary `"turn"` for exactly that reason.
|
|
276
|
+
* - `"websocket"`: not WebRTC at all - encoded frames proxied by this server over a WebSocket (see
|
|
277
|
+
* `apps/shared/relay/`), the last resort when neither of the above connects.
|
|
278
|
+
* - `"connecting"`: no path established yet. `"failed"`: every path this browser can try has failed. */
|
|
279
|
+
export type MediaTransport = "connecting" | "p2p" | "turn" | "turn-tcp" | "websocket" | "failed";
|
|
280
|
+
|
|
281
|
+
/** What `MeshConnectionManager` needs from the WebSocket media relay (`apps/shared/relay/RelayTransport.ts` implements
|
|
282
|
+
* it) - declared here so the mesh, and its tests, depend on the shape alone. */
|
|
283
|
+
export interface RelayTransportLike {
|
|
284
|
+
/** `false` when this browser cannot do it (no WebSocket, no WebCodecs) - the mesh then never falls back to it. */
|
|
285
|
+
readonly supported: boolean;
|
|
286
|
+
/** Starts receiving `peerId`'s media. `onStream` is given the `MediaStream` that plays it. */
|
|
287
|
+
receiveFrom(peerId: string, onStream: (stream: MediaStream) => void): void;
|
|
288
|
+
stopReceivingFrom(peerId: string): void;
|
|
289
|
+
/** Starts or stops publishing the local tracks to the relay. */
|
|
290
|
+
setSending(active: boolean): void;
|
|
291
|
+
/** Same as `MeshConnectionManager.setLocalTrack()` - `null` sends nothing for that kind. */
|
|
292
|
+
setLocalTrack(kind: "audio" | "video", track: MediaStreamTrack | null): void;
|
|
293
|
+
/** The relay's counters as they stand for `peerId`, for the diagnostics panel. Optional so a test's fake relay
|
|
294
|
+
* needn't provide it; the mesh then shows nothing for a relayed pair. */
|
|
295
|
+
diagnostics?(peerId: string): RelayDiagnostics;
|
|
296
|
+
close(): void;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** `iceTransportPolicy` mirrors the real `RTCConfiguration` field of the same name - `"relay"` forces ICE to use
|
|
300
|
+
* only a TURN relay candidate, never a direct one (`TransportMode.relay`); omitted (or `"all"`) is the ordinary,
|
|
301
|
+
* unconstrained default. */
|
|
302
|
+
export type RTCPeerConnectionFactory = (config: { iceServers: RTCIceServer[]; iceTransportPolicy?: "all" | "relay" }) => RTCPeerConnectionLike;
|
|
303
|
+
|
|
304
|
+
/** One other participant currently known to be in the call - `MeshConnectionManager.participants` never includes
|
|
305
|
+
* the local participant themselves (the UI already knows its own name/uid without asking the manager). */
|
|
306
|
+
export interface MeshParticipant extends ParticipantState {
|
|
307
|
+
uid: string;
|
|
308
|
+
name: string;
|
|
309
|
+
/** How this participant's media currently reaches the local one - see `MediaTransport`. */
|
|
310
|
+
transport: MediaTransport;
|
|
311
|
+
/** This connection's most recently polled quality stats, for the diagnostics panel - `undefined` until the
|
|
312
|
+
* first poll completes (shortly after `transport` first leaves `"connecting"`, or the pair moves to the relay).
|
|
313
|
+
* For a `"websocket"`-relayed participant they come from the relay's own counters (`relay`) rather than an
|
|
314
|
+
* `RTCPeerConnection`. */
|
|
315
|
+
diagnostics?: ConnectionDiagnostics;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export type MeshEvent =
|
|
319
|
+
| { type: "participant-joined"; participant: MeshParticipant }
|
|
320
|
+
| { type: "participant-updated"; participant: MeshParticipant }
|
|
321
|
+
| { type: "participant-left"; uid: string }
|
|
322
|
+
| { type: "remote-stream"; uid: string; stream: MediaStream }
|
|
323
|
+
| { type: "hand-raised"; uid: string; name: string }
|
|
324
|
+
| { type: "reaction"; uid: string; name: string; emoji: string }
|
|
325
|
+
| { type: "presenter-changed"; uid: string | undefined }
|
|
326
|
+
/** Someone (implicitly the host, on the client's own say-so - see `SignalMessage`'s doc comment) asked the local
|
|
327
|
+
* participant to mute. The caller (`_CallView.tsx`) mutes only if currently unmuted; this never unmutes anyone. */
|
|
328
|
+
| { type: "mute-requested" }
|
|
329
|
+
/** The local participant was removed from the call. The caller tears down the mesh and shows a distinct
|
|
330
|
+
* "removed by the host" state rather than the ordinary "you left" one. */
|
|
331
|
+
| { type: "kicked" }
|
|
332
|
+
/** Talking-stick mode turned on or off, or the stick changed hands - see this module's doc comment and
|
|
333
|
+
* `MeshConnectionManager.setTalkingStick()`. `holder` is the peer id now holding it; absent while `active` is
|
|
334
|
+
* `false`, or (transiently) if whoever held it has since left the call. */
|
|
335
|
+
| { type: "talking-stick-changed"; active: boolean; holder?: string };
|