@rapidmx/meet-plugin 0.15.0 → 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.
Files changed (74) hide show
  1. package/README.md +35 -55
  2. package/apps/meet/[token].tsx +341 -341
  3. package/apps/meet/_CallControls.tsx +508 -483
  4. package/apps/meet/_CallView.tsx +1060 -924
  5. package/apps/meet/_ChatPanel.tsx +194 -0
  6. package/apps/meet/_ColorWheel.tsx +136 -0
  7. package/apps/meet/_MeetLobby.tsx +224 -224
  8. package/apps/meet/_ParticipantTile.tsx +243 -242
  9. package/apps/meet/_Whiteboard.tsx +577 -0
  10. package/apps/meet/_icons.tsx +135 -90
  11. package/apps/meet/_meetApi.ts +213 -212
  12. package/apps/shared/collab/CollabSession.ts +675 -0
  13. package/apps/shared/collab/WhiteboardModel.ts +216 -0
  14. package/apps/shared/collab/chatMarkdown.tsx +375 -0
  15. package/apps/shared/collab/color.ts +67 -0
  16. package/apps/shared/collab/protocol.ts +321 -0
  17. package/apps/shared/collab/whiteboardRender.ts +311 -0
  18. package/apps/shared/media/filters/VideoFilterProcessor.ts +408 -408
  19. package/apps/shared/media/filters/mlModels.ts +174 -174
  20. package/apps/shared/relay/RelayClient.ts +2 -1
  21. package/apps/shared/relay/RelayTransport.ts +2 -1
  22. package/apps/shared/relay/relayEnv.ts +1 -1
  23. package/apps/shared/signaling/SignalingClient.ts +335 -0
  24. package/apps/shared/webrtc/MeshConnectionManager.ts +971 -971
  25. package/apps/shared/webrtc/types.ts +335 -316
  26. package/dist/apps/meet/[token].js +1 -1
  27. package/dist/apps/meet/_CallControls.d.ts +12 -4
  28. package/dist/apps/meet/_CallControls.js +5 -5
  29. package/dist/apps/meet/_CallView.d.ts +19 -4
  30. package/dist/apps/meet/_CallView.js +100 -11
  31. package/dist/apps/meet/_ChatPanel.d.ts +24 -0
  32. package/dist/apps/meet/_ChatPanel.js +116 -0
  33. package/dist/apps/meet/_ColorWheel.d.ts +14 -0
  34. package/dist/apps/meet/_ColorWheel.js +82 -0
  35. package/dist/apps/meet/_ParticipantTile.d.ts +2 -1
  36. package/dist/apps/meet/_ParticipantTile.js +1 -1
  37. package/dist/apps/meet/_Whiteboard.d.ts +64 -0
  38. package/dist/apps/meet/_Whiteboard.js +312 -0
  39. package/dist/apps/meet/_icons.d.ts +12 -0
  40. package/dist/apps/meet/_icons.js +12 -0
  41. package/dist/apps/meet/_meetApi.d.ts +8 -7
  42. package/dist/apps/meet/_meetApi.js +2 -2
  43. package/dist/apps/shared/collab/CollabSession.d.ts +208 -0
  44. package/dist/apps/shared/collab/CollabSession.js +559 -0
  45. package/dist/apps/shared/collab/WhiteboardModel.d.ts +54 -0
  46. package/dist/apps/shared/collab/WhiteboardModel.js +197 -0
  47. package/dist/apps/shared/collab/chatMarkdown.d.ts +65 -0
  48. package/dist/apps/shared/collab/chatMarkdown.js +311 -0
  49. package/dist/apps/shared/collab/color.d.ts +18 -0
  50. package/dist/apps/shared/collab/color.js +59 -0
  51. package/dist/apps/shared/collab/protocol.d.ts +157 -0
  52. package/dist/apps/shared/collab/protocol.js +222 -0
  53. package/dist/apps/shared/collab/whiteboardRender.d.ts +31 -0
  54. package/dist/apps/shared/collab/whiteboardRender.js +268 -0
  55. package/dist/apps/shared/relay/RelayClient.js +2 -1
  56. package/dist/apps/shared/relay/RelayTransport.d.ts +2 -1
  57. package/dist/apps/shared/relay/RelayTransport.js +2 -1
  58. package/dist/apps/shared/relay/relayEnv.d.ts +1 -1
  59. package/dist/apps/shared/signaling/SignalingClient.d.ts +95 -0
  60. package/dist/apps/shared/signaling/SignalingClient.js +278 -0
  61. package/dist/apps/shared/webrtc/MeshConnectionManager.d.ts +7 -7
  62. package/dist/apps/shared/webrtc/MeshConnectionManager.js +8 -8
  63. package/dist/apps/shared/webrtc/types.d.ts +38 -24
  64. package/dist/apps/shared/webrtc/types.js +3 -4
  65. package/dist/lib/routes/BaseVideoMeetingRoute.js +171 -69
  66. package/dist/lib/routes/BaseVideoMeetingRoute.js.map +1 -1
  67. package/dist/lib/util/SignalingHub.js +339 -0
  68. package/dist/lib/util/SignalingHub.js.map +1 -0
  69. package/dist/types/routes/BaseVideoMeetingRoute.d.ts +68 -46
  70. package/dist/types/util/SignalingHub.d.ts +112 -0
  71. package/package.json +208 -208
  72. package/apps/shared/push/GuestSignalingClient.ts +0 -359
  73. package/dist/apps/shared/push/GuestSignalingClient.d.ts +0 -98
  74. package/dist/apps/shared/push/GuestSignalingClient.js +0 -312
@@ -0,0 +1,208 @@
1
+ /**
2
+ * The call's text chat and shared whiteboard, over the same signaling channel the mesh uses (`../webrtc/types.ts`'s
3
+ * `chat`, `whiteboard`, `collab-sync-request` and `collab-sync` messages). Like everything else in a call they live
4
+ * only as long as the call does - there is no server-side copy; each participant's tab holds them.
5
+ *
6
+ * ## Chat
7
+ *
8
+ * `sendChat()` broadcasts one `chat` message and shows it locally at once (the server never echoes a sender's own
9
+ * messages). A received one is shown under the name its sender announced in their `hello`. At most
10
+ * `MAX_CHAT_HISTORY` messages are kept.
11
+ *
12
+ * ## Whiteboard
13
+ *
14
+ * Every drawing action becomes a `WhiteboardOp`, applied to this tab's own `WhiteboardModel` at once and broadcast. A
15
+ * stroke being drawn sends its points in batches every `POINT_FLUSH_MS` rather than one message per pointer move, so
16
+ * the others watch it being drawn without a message per pixel. `undo()` erases this participant's own most recent
17
+ * element still on the board.
18
+ *
19
+ * ## Pointers
20
+ *
21
+ * While a participant's pointer is over the board, `moveCursor()` tells everyone where it is and as which tool and
22
+ * color, at most every `CURSOR_INTERVAL_MS`; `hideCursor()` says it left. While they are drawing a stroke, no pointer
23
+ * messages are sent at all - everyone else moves their pointer along the stroke's own points instead. Pointers are
24
+ * never stored or caught up on; one not heard from for `CURSOR_IDLE_MS` is dropped, as is a participant's on `bye`.
25
+ *
26
+ * ## Who may draw
27
+ *
28
+ * `setDrawPolicy()` limits who may change the board (talking-stick mode: only whoever holds the stick). This
29
+ * participant's own drawing calls then do nothing unless it is allowed, and a received change from a participant who
30
+ * isn't is ignored - as cooperative as every other moderation signal in the call (see `../webrtc/types.ts`): each
31
+ * participant's own tab decides. A change in flight when the stick moves may land on some boards and not others.
32
+ * Pointers still show for everyone - pointing at something isn't drawing it.
33
+ *
34
+ * ## Catching up
35
+ *
36
+ * Someone joining a call already under way asks one participant for what they missed: on the first `hello` it hears
37
+ * within `SYNC_WINDOW_MS` of starting (an existing participant answering its own `hello`), it sends that participant a
38
+ * `collab-sync-request`; the answer is the chat history and the board as ops, split into `collab-sync` parts that
39
+ * each fit the server's message limit and paced `SYNC_PACE_MS` apart to stay inside its rate limit. When nothing has
40
+ * arrived from that participant for `SYNC_TIMEOUT_MS` (first part or next), the next one is asked - as it is when the
41
+ * whole answer was empty, which is what another newcomer who arrived moments earlier would send. Only the participant
42
+ * asked is listened to, and a participant answers the same requester at most once per `SYNC_ANSWER_COOLDOWN_MS`. A catch-up is that one participant's account of the call, which this tab cannot check - the chat history it
43
+ * carries names who said what, and the server stamps only the catch-up's own sender - so it is merged under the same
44
+ * validation as live messages, and live messages win wherever the two overlap.
45
+ */
46
+ import { type CursorTool, type PenType, type Stamp, type StencilShape } from "./protocol.js";
47
+ import { WhiteboardModel } from "./WhiteboardModel.js";
48
+ import type { SignalingChannel } from "../webrtc/types.js";
49
+ /** How often the points of a stroke being drawn are sent. */
50
+ export declare const POINT_FLUSH_MS = 60;
51
+ /** How long after starting a `hello` still counts as an existing participant answering ours - see this module's doc. */
52
+ export declare const SYNC_WINDOW_MS = 15000;
53
+ /** How long to wait for a catch-up to start arriving before asking someone else. */
54
+ export declare const SYNC_TIMEOUT_MS = 5000;
55
+ /** The gap between two parts of a catch-up this participant sends. */
56
+ export declare const SYNC_PACE_MS = 250;
57
+ /** Room left in each catch-up part for the message's own envelope. */
58
+ export declare const SYNC_ENVELOPE_BYTES = 1024;
59
+ /** The most stroke points one catch-up op carries, so one op always fits the server's smallest message limit. */
60
+ export declare const SYNC_POINTS_PER_OP = 600;
61
+ /** The least time between two pointer messages this participant sends. */
62
+ export declare const CURSOR_INTERVAL_MS = 80;
63
+ /** How long a participant's pointer stays on the board without news of it. */
64
+ export declare const CURSOR_IDLE_MS = 30000;
65
+ /** How long a participant waits before answering the same requester's catch-up request again. */
66
+ export declare const SYNC_ANSWER_COOLDOWN_MS = 10000;
67
+ /** One chat message as shown. */
68
+ export interface ChatEntry {
69
+ /** Unique within the call: the sender's peer id and their own message id. */
70
+ key: string;
71
+ id: string;
72
+ peer: string;
73
+ name: string;
74
+ text: string;
75
+ sentAt: number;
76
+ self: boolean;
77
+ }
78
+ /** Another participant's pointer on the board. */
79
+ export interface RemoteCursor {
80
+ peer: string;
81
+ name: string;
82
+ x: number;
83
+ y: number;
84
+ tool: CursorTool;
85
+ color: string;
86
+ stamp?: Stamp;
87
+ /** When it last moved, by this tab's clock. */
88
+ at: number;
89
+ }
90
+ /** A `chat` event with `history` set is a message from a catch-up - said before this participant arrived; one with
91
+ * `renamed` set is a message already shown, now under its sender's name. Neither is news. */
92
+ export type CollabEvent = {
93
+ type: "chat";
94
+ entry: ChatEntry;
95
+ history?: boolean;
96
+ renamed?: boolean;
97
+ } | {
98
+ type: "board";
99
+ } | {
100
+ type: "cursors";
101
+ };
102
+ /** What `CollabSession` needs from the signaling channel - `SignalingClient` is one. */
103
+ export interface CollabChannel extends SignalingChannel {
104
+ /** The server's per-message limit, in bytes - `SignalingClient.maxMessageBytes`. */
105
+ readonly maxMessageBytes?: number;
106
+ }
107
+ export interface CollabSessionOptions {
108
+ channel: CollabChannel;
109
+ /** The authenticated uid every message is sent `from`. */
110
+ selfUid: string;
111
+ /** This tab's peer id - the author of its chat messages and the prefix of its board elements' ids. */
112
+ peerId: string;
113
+ selfName: string;
114
+ now?: () => number;
115
+ }
116
+ export declare class CollabSession {
117
+ private readonly options;
118
+ readonly board: WhiteboardModel;
119
+ private chatEntries;
120
+ /** How many of `chatEntries`, from the front, came from a catch-up - the next part's history goes after them. */
121
+ private historyCount;
122
+ private readonly chatKeys;
123
+ private readonly names;
124
+ private readonly listeners;
125
+ private readonly ownIds;
126
+ private readonly outgoingPoints;
127
+ private readonly timers;
128
+ private flushTimer;
129
+ private syncTimer;
130
+ private syncTarget;
131
+ private readonly syncTried;
132
+ private readonly knownPeers;
133
+ private unsubscribe;
134
+ private startedAt;
135
+ private seq;
136
+ private stopped;
137
+ private readonly remoteCursors;
138
+ private cursorPending;
139
+ private cursorTimer;
140
+ private cursorShown;
141
+ private lastCursorSent;
142
+ private pruneTimer;
143
+ /** The stroke this participant is drawing, between `beginStroke()` and `endStroke()`. */
144
+ private activeStroke;
145
+ private drawPolicy;
146
+ private readonly syncAnswered;
147
+ private syncReceivedAnything;
148
+ constructor(options: CollabSessionOptions);
149
+ /** Every chat message, oldest first. */
150
+ get chat(): readonly ChatEntry[];
151
+ /** Everyone else's pointers currently on the board. */
152
+ get cursors(): RemoteCursor[];
153
+ /** Whether this participant may change the board now - see this module's doc comment on who may draw. */
154
+ get canDraw(): boolean;
155
+ /** Limits who may change the board to the peers `policy` accepts; `undefined` lets everyone. */
156
+ setDrawPolicy(policy: ((peer: string) => boolean) | undefined): void;
157
+ onEvent(listener: (event: CollabEvent) => void): () => void;
158
+ start(): void;
159
+ stop(): void;
160
+ /** Sends `text` as a chat message. Returns `false`, sending nothing, for blank or overlong text. */
161
+ sendChat(text: string): boolean;
162
+ /** Starts a stroke at (`x`, `y`); returns its id, or `undefined` when the board is full. */
163
+ beginStroke(pen: PenType, color: string, size: number, x: number, y: number): string | undefined;
164
+ /** Adds a point to this participant's own stroke `id` - sent with the next batch. */
165
+ extendStroke(id: string, x: number, y: number): void;
166
+ /** Finishes a stroke: whatever points are still waiting go out now. */
167
+ endStroke(): void;
168
+ addShape(shape: StencilShape, color: string, size: number, x1: number, y1: number, x2: number, y2: number): string | undefined;
169
+ addStamp(stamp: Stamp, size: number, x: number, y: number): string | undefined;
170
+ /** Erases `ids` - anyone's elements, see `protocol.ts`. */
171
+ erase(ids: string[]): void;
172
+ /** Erases this participant's own most recent element still on the board; `false` when there is none. */
173
+ undo(): boolean;
174
+ /** Clears the board for everyone. */
175
+ clear(): void;
176
+ /** Says this participant's pointer is at (`x`, `y`) on the board, as `tool` in `color` (with `stamp` for the stamp
177
+ * tool) - sent now, or with the latest position once `CURSOR_INTERVAL_MS` has passed since the last one. */
178
+ moveCursor(x: number, y: number, tool: CursorTool, color: string, stamp?: Stamp): void;
179
+ /** Says this participant's pointer has left the board. */
180
+ hideCursor(): void;
181
+ private flushCursor;
182
+ private handleCursor;
183
+ /** Moves `sender`'s pointer to where their stroke just got to - see this module's doc comment on pointers. */
184
+ private followStroke;
185
+ private pruneCursors;
186
+ private mayDraw;
187
+ private addElement;
188
+ private applyAndSend;
189
+ private flushPoints;
190
+ private handleMessage;
191
+ private handleHello;
192
+ private requestSync;
193
+ /** Asks the next participant not yet asked, if any - after a silence or an empty answer. */
194
+ private askNext;
195
+ private armSyncTimeout;
196
+ private receiveSync;
197
+ /** Sends `peer` everything said and drawn so far - see this module's doc comment. */
198
+ private sendSync;
199
+ private mergeHistory;
200
+ private addChat;
201
+ /** Keeps the latest `MAX_CHAT_HISTORY` of `entries`. */
202
+ private setChat;
203
+ private send;
204
+ private emit;
205
+ private nextId;
206
+ private nextElementId;
207
+ private now;
208
+ }