mediascale-sdk 1.0.7 → 1.0.8
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/docs/integration.md +47 -3
- package/package.json +1 -1
- package/src/client.js +174 -2
- package/src/record.js +113 -32
package/docs/integration.md
CHANGED
|
@@ -59,7 +59,7 @@ export async function POST(request) {
|
|
|
59
59
|
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
`role` is `host` or `audience
|
|
62
|
+
`role` is `host` or `audience` for the SDK/portal token. Only the host should drive recording in the UI.
|
|
63
63
|
|
|
64
64
|
Token claims the SDK reads:
|
|
65
65
|
|
|
@@ -71,16 +71,55 @@ Token claims the SDK reads:
|
|
|
71
71
|
| `recording` | When `true` on a **host** token, auto-start recording on `connect()` unless `createClient({ recording: false })` |
|
|
72
72
|
| `exp` | Expiry as a Unix timestamp in **milliseconds** |
|
|
73
73
|
|
|
74
|
+
### Sample stage roles (meet UI)
|
|
75
|
+
|
|
76
|
+
The sample room keeps JWT `host` / `audience` for auth, and adds a **stage role** in the demo UI: `host`, `co-host`, `speaker`, `participant`.
|
|
77
|
+
|
|
78
|
+
- **Host** (and co-host) see every participant and can **Make Speaker**, **Make co-host**, or **Block**.
|
|
79
|
+
- **Participants** see only people on stage (speakers / host / co-host).
|
|
80
|
+
- Only host, co-host, and speaker may publish camera, mic, screen, or whiteboard.
|
|
81
|
+
|
|
82
|
+
Webinar / product apps usually already manage join, leave, and stage membership on their side. You do **not** need the SDK roster callbacks (`onUserJoined`, `onUserLeft`, etc.) for that. What you **do** need for recording parity is below.
|
|
83
|
+
|
|
84
|
+
### Recording must match the live stage
|
|
85
|
+
|
|
86
|
+
The recorder only knows about **published media** unless you tell it who is on stage. If a speaker is on stage without a camera, participants see their avatar — the recording must show that same avatar until video starts.
|
|
87
|
+
|
|
88
|
+
Whenever your stage layout changes (someone promoted, demoted, or leaves stage), push the same people you show in the live UI:
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
// Same order / membership as the participant stage tiles.
|
|
92
|
+
client.setRecordingStage([
|
|
93
|
+
{ id: hostPeerId, name: "Alex", local: true },
|
|
94
|
+
{ id: speakerPeerId, name: "Rakesh", local: false },
|
|
95
|
+
]);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
| Field | Meaning |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| `id` | Stable peer id for that person (use the same id you already use in your app; when they publish webcam, the SDK matches the tile by this id / publisher id) |
|
|
101
|
+
| `name` | Display name on the avatar tile |
|
|
102
|
+
| `local` | `true` for this browser’s own tile |
|
|
103
|
+
|
|
104
|
+
Rules:
|
|
105
|
+
|
|
106
|
+
- Call `setRecordingStage` on **add to stage**, **remove from stage**, and when names change — keep it identical to what participants see.
|
|
107
|
+
- Everyone in the list gets an **avatar** until their webcam is published; then that tile becomes **video**.
|
|
108
|
+
- Pass `[]` to clear the stage list; you normally keep at least the people currently on stage.
|
|
109
|
+
- `onStageChanged(people)` is optional if you only care about driving the recorder from your own stage state.
|
|
110
|
+
|
|
111
|
+
Without `setRecordingStage`, recording falls back to live tracks only (plus a single host placeholder when nobody is publishing) — so off-stage speakers without video will be **missing** from the file.
|
|
112
|
+
|
|
74
113
|
## 2. Copy the room page
|
|
75
114
|
|
|
76
115
|
Copy `sdk/react-sdk/sample/app/room.js` into your app. The comments in that file are the steps.
|
|
77
116
|
|
|
78
117
|
1. **Join** asks your server for a token, then calls `connect()` and `subscribe()`. The camera, microphone, and screen stay off.
|
|
79
|
-
2. **Camera** calls `startCamera()` or `stopCamera()
|
|
118
|
+
2. **Camera** calls `startCamera()` or `stopCamera()` (sample: only when on stage as host/co-host/speaker). Optionally pass your own live video track, or call `replaceCameraTrack(track)` to hot-swap devices without unpublishing.
|
|
80
119
|
3. **Mic** calls `startMicrophone()` or `stopMicrophone()` (and `replaceMicrophoneTrack` to switch devices smoothly).
|
|
81
120
|
4. **Screen** calls `startScreenShare()` or `stopScreenShare()`.
|
|
82
121
|
5. **Custom stream** (optional) — see [Custom streams](#custom-streams) (`startCustomStream` / `stopCustomStream`), for example a whiteboard tab capture.
|
|
83
|
-
6. **Record** (host) starts automatically when enabled on the token / `createClient`, or from the toolbar via `startRecording()` / `stopRecording()`. You can toggle any time; the final file includes every segment.
|
|
122
|
+
6. **Record** (host) starts automatically when enabled on the token / `createClient`, or from the toolbar via `startRecording()` / `stopRecording()`. You can toggle any time; the final file includes every segment and mirrors the live stage layout.
|
|
84
123
|
7. **End** leaves the session and saves the recording if this person was recording.
|
|
85
124
|
|
|
86
125
|
`recording` defaults to **false**. Set `createClient({ recording: true })` **or** put `recording: true` on the host JWT when the host should already be recording when they join (Stream Control “Enable recording” does this). Chunks start **immediately** on connect / `startRecording()` — mic and camera are not required. Until video is live, the recording canvas shows the same host placeholder as the live stage (magenta background, avatar letter, name).
|
|
@@ -174,6 +213,9 @@ await client.end(); // combines every segment into one file
|
|
|
174
213
|
| `startRecording()` | Starts recording for this person (or resumes after `stopRecording()`). Chunks upload immediately — mic/camera not required. Empty stage uses the host placeholder tile until real video is published. Also used when the host left and a cohost should continue the same file. |
|
|
175
214
|
| `stopRecording()` | Pauses recording without saving. Call `startRecording()` again to continue; `end()` still combines all segments into one file. |
|
|
176
215
|
| `setRecordingCrop(source, crop)` | Crops a video source in the recording layout. `crop` is `{ x, y, w, h }` in 0..1 (same as subscriber whiteboard crop). Pass `null` to clear. |
|
|
216
|
+
| `setRecordingStage(people)` | **Required for stage-accurate recording.** Who appears on the recording stage: `[{ id, name, local? }]`. Avatars until that peer’s webcam arrives. See [Recording must match the live stage](#recording-must-match-the-live-stage). |
|
|
217
|
+
| `getPeerId()` | Socket peer id for this browser after `connect()`. |
|
|
218
|
+
| `getUserList()` / `updateSelf(...)` / `stageAction(...)` | Optional portal roster helpers used by the sample meet UI. Skip these if your app already manages users and stage on its own. |
|
|
177
219
|
| `end()` | Leaves the session. If this person is the one recording, every segment is combined and saved. |
|
|
178
220
|
| `listDevices()` | Returns `{ cameras, microphones }`. Each item is `{ id, label }`. |
|
|
179
221
|
|
|
@@ -191,6 +233,8 @@ Pass these to `createClient`.
|
|
|
191
233
|
| `onError(error)` | A call failed. `error.message` is the reason. The same call also throws, so `await` can use `try/catch`. |
|
|
192
234
|
| `onRecording(state)` | `armed` briefly while capture is preparing. `recording` while chunks are uploading. `stopped` after `stopRecording()`, handoff, or `end()`. |
|
|
193
235
|
| `onActiveSpeaker({ peerId, displayName, producerId, local })` | Fires when the loudest mic in the room changes. `peerId` is `null` when nobody is speaking. `local` is true when it is this browser. Requires `ACTIVE_SPEAKER_DETECTION=true` on the origin SFU and portal. |
|
|
236
|
+
| `onStageChanged(people)` | Optional. Fires when the recording stage list changes after `setRecordingStage` (or sample roster updates). |
|
|
237
|
+
| `onUserList` / `onUserJoined` / `onUserLeft` / `onUserUpdated` / `onUserBlocked` | Optional portal roster events for the sample meet UI. Not required if your webinar app manages join/leave/stage itself — use `setRecordingStage` instead. |
|
|
194
238
|
|
|
195
239
|
## Active speaker
|
|
196
240
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -65,6 +65,12 @@ export function createClient(options = {}) {
|
|
|
65
65
|
const onError = options.onError || (() => {});
|
|
66
66
|
const onRecording = options.onRecording || (() => {});
|
|
67
67
|
const onActiveSpeaker = options.onActiveSpeaker || (() => {});
|
|
68
|
+
const onUserJoined = options.onUserJoined || (() => {});
|
|
69
|
+
const onUserLeft = options.onUserLeft || (() => {});
|
|
70
|
+
const onUserUpdated = options.onUserUpdated || (() => {});
|
|
71
|
+
const onUserList = options.onUserList || (() => {});
|
|
72
|
+
const onUserBlocked = options.onUserBlocked || (() => {});
|
|
73
|
+
const onStageChanged = options.onStageChanged || (() => {});
|
|
68
74
|
|
|
69
75
|
if (!sessionId) throw new Error("sessionId is required");
|
|
70
76
|
if (!token) throw new Error("token is required");
|
|
@@ -89,10 +95,80 @@ export function createClient(options = {}) {
|
|
|
89
95
|
const tiles = new Map();
|
|
90
96
|
/** source id → normalized crop for recording compositor (e.g. whiteboard). */
|
|
91
97
|
const recordingCrops = new Map();
|
|
98
|
+
/** peerId → { id, name, local } for people currently on stage (from roster or setRecordingStage). */
|
|
99
|
+
const stageById = new Map();
|
|
100
|
+
/** When set, parent-provided stage list wins over roster-derived stageById. */
|
|
101
|
+
let stageOverride = null;
|
|
102
|
+
let lastStageSig = "";
|
|
92
103
|
const pending = [];
|
|
93
104
|
let readyPromise = null;
|
|
94
105
|
let settleReady = null;
|
|
95
106
|
|
|
107
|
+
function userOnStage(user) {
|
|
108
|
+
if (!user) return false;
|
|
109
|
+
if (user.onStage != null) return Boolean(user.onStage);
|
|
110
|
+
const role = String(user.stageRole || "").trim().toLowerCase();
|
|
111
|
+
return role === "host" || role === "co-host" || role === "speaker";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function normalizeStagePerson(person) {
|
|
115
|
+
if (!person) return null;
|
|
116
|
+
const id = String(person.id || "").trim();
|
|
117
|
+
const name = String(person.name || "Guest").trim().slice(0, 40) || "Guest";
|
|
118
|
+
if (!id && !name) return null;
|
|
119
|
+
return {
|
|
120
|
+
id,
|
|
121
|
+
name,
|
|
122
|
+
local: Boolean(person.local) || Boolean(id && selfPeerId && id === selfPeerId),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function stagePeopleForRecording() {
|
|
127
|
+
if (stageOverride) return stageOverride;
|
|
128
|
+
return [...stageById.values()];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function emitStageChanged() {
|
|
132
|
+
const people = stagePeopleForRecording();
|
|
133
|
+
const sig = people.map((p) => `${p.id}|${p.name}|${p.local ? 1 : 0}`).join(";");
|
|
134
|
+
if (sig === lastStageSig) return;
|
|
135
|
+
lastStageSig = sig;
|
|
136
|
+
onStageChanged(people);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function ingestRosterUsers(users) {
|
|
140
|
+
if (!Array.isArray(users)) return;
|
|
141
|
+
stageById.clear();
|
|
142
|
+
for (const user of users) {
|
|
143
|
+
if (!userOnStage(user)) continue;
|
|
144
|
+
const person = normalizeStagePerson(user);
|
|
145
|
+
if (!person?.id) continue;
|
|
146
|
+
stageById.set(person.id, person);
|
|
147
|
+
}
|
|
148
|
+
emitStageChanged();
|
|
149
|
+
syncRecording();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function ingestRosterUser(user) {
|
|
153
|
+
if (!user?.id) return;
|
|
154
|
+
if (userOnStage(user)) {
|
|
155
|
+
const person = normalizeStagePerson(user);
|
|
156
|
+
if (person?.id) stageById.set(person.id, person);
|
|
157
|
+
} else {
|
|
158
|
+
stageById.delete(String(user.id));
|
|
159
|
+
}
|
|
160
|
+
emitStageChanged();
|
|
161
|
+
syncRecording();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function removeRosterUser(user) {
|
|
165
|
+
const id = String(user?.id || "").trim();
|
|
166
|
+
if (!id) return;
|
|
167
|
+
if (!stageById.delete(id)) return;
|
|
168
|
+
emitStageChanged();
|
|
169
|
+
syncRecording();
|
|
170
|
+
}
|
|
171
|
+
|
|
96
172
|
function clientHints() {
|
|
97
173
|
if (typeof navigator === "undefined") return {};
|
|
98
174
|
const ua = String(navigator.userAgent || "");
|
|
@@ -113,7 +189,32 @@ export function createClient(options = {}) {
|
|
|
113
189
|
}
|
|
114
190
|
|
|
115
191
|
function syncRecording() {
|
|
116
|
-
recorder?.sync(tracksForRecording());
|
|
192
|
+
recorder?.sync(tracksForRecording(), stagePeopleForRecording());
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Tell the recorder who belongs on stage (same tiles participants see).
|
|
197
|
+
* Each person is `{ id, name, local? }`. When they publish webcam, that tile becomes video.
|
|
198
|
+
* Pass `null` to fall back to the socket roster; pass `[]` for an empty stage.
|
|
199
|
+
*/
|
|
200
|
+
function setRecordingStage(people) {
|
|
201
|
+
if (people == null) {
|
|
202
|
+
stageOverride = null;
|
|
203
|
+
} else {
|
|
204
|
+
const next = [];
|
|
205
|
+
const seen = new Set();
|
|
206
|
+
for (const raw of Array.isArray(people) ? people : []) {
|
|
207
|
+
const person = normalizeStagePerson(raw);
|
|
208
|
+
if (!person) continue;
|
|
209
|
+
const key = person.id || `name:${person.name.toLowerCase()}`;
|
|
210
|
+
if (seen.has(key)) continue;
|
|
211
|
+
seen.add(key);
|
|
212
|
+
next.push(person);
|
|
213
|
+
}
|
|
214
|
+
stageOverride = next;
|
|
215
|
+
}
|
|
216
|
+
emitStageChanged();
|
|
217
|
+
syncRecording();
|
|
117
218
|
}
|
|
118
219
|
|
|
119
220
|
/**
|
|
@@ -305,6 +406,24 @@ export function createClient(options = {}) {
|
|
|
305
406
|
local: Boolean(peerId && selfPeerId && peerId === selfPeerId),
|
|
306
407
|
});
|
|
307
408
|
});
|
|
409
|
+
socket.on("userJoined", (user) => {
|
|
410
|
+
if (closed) return;
|
|
411
|
+
ingestRosterUser(user);
|
|
412
|
+
onUserJoined(user);
|
|
413
|
+
});
|
|
414
|
+
socket.on("userLeft", (user) => {
|
|
415
|
+
if (closed) return;
|
|
416
|
+
removeRosterUser(user);
|
|
417
|
+
onUserLeft(user);
|
|
418
|
+
});
|
|
419
|
+
socket.on("userUpdated", (user) => {
|
|
420
|
+
if (closed) return;
|
|
421
|
+
ingestRosterUser(user);
|
|
422
|
+
onUserUpdated(user);
|
|
423
|
+
});
|
|
424
|
+
socket.on("userBlocked", (payload) => {
|
|
425
|
+
if (!closed) onUserBlocked(payload || {});
|
|
426
|
+
});
|
|
308
427
|
socket.on("connect", async () => {
|
|
309
428
|
try {
|
|
310
429
|
if (closed) return;
|
|
@@ -317,6 +436,10 @@ export function createClient(options = {}) {
|
|
|
317
436
|
});
|
|
318
437
|
selfPeerId = joined.peerId || null;
|
|
319
438
|
iceServers = iceOverride || joined.iceServers || [];
|
|
439
|
+
if (Array.isArray(joined.users)) {
|
|
440
|
+
ingestRosterUsers(joined.users);
|
|
441
|
+
onUserList(joined.users);
|
|
442
|
+
}
|
|
320
443
|
device = new Device();
|
|
321
444
|
await device.load({ routerRtpCapabilities: joined.rtpCapabilities });
|
|
322
445
|
|
|
@@ -355,6 +478,16 @@ export function createClient(options = {}) {
|
|
|
355
478
|
});
|
|
356
479
|
const started = await emit(socket, "ready", { rtpCapabilities: device.rtpCapabilities });
|
|
357
480
|
for (const params of started.consumers || []) await play(params);
|
|
481
|
+
// Fresh roster after ready (covers anyone who joined during transport setup).
|
|
482
|
+
try {
|
|
483
|
+
const list = await emit(socket, "getUserList", {});
|
|
484
|
+
if (Array.isArray(list?.users)) {
|
|
485
|
+
ingestRosterUsers(list.users);
|
|
486
|
+
onUserList(list.users);
|
|
487
|
+
}
|
|
488
|
+
} catch {
|
|
489
|
+
/* roster optional if portal is older */
|
|
490
|
+
}
|
|
358
491
|
if (joined.waiting) onStatus("Please wait, we will connect you soon");
|
|
359
492
|
else onStatus("Ready");
|
|
360
493
|
if (closed) return;
|
|
@@ -374,6 +507,40 @@ export function createClient(options = {}) {
|
|
|
374
507
|
return readyPromise;
|
|
375
508
|
}
|
|
376
509
|
|
|
510
|
+
async function getUserList() {
|
|
511
|
+
await connect();
|
|
512
|
+
if (!socket?.connected) throw new Error("Not connected");
|
|
513
|
+
const result = await emit(socket, "getUserList", {});
|
|
514
|
+
if (result?.error) throw new Error(result.error);
|
|
515
|
+
const users = Array.isArray(result?.users) ? result.users : [];
|
|
516
|
+
ingestRosterUsers(users);
|
|
517
|
+
onUserList(users);
|
|
518
|
+
return users;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
async function updateSelf(patch = {}) {
|
|
522
|
+
await connect();
|
|
523
|
+
if (!socket?.connected) throw new Error("Not connected");
|
|
524
|
+
const result = await emit(socket, "updateSelf", patch);
|
|
525
|
+
if (result?.error) throw new Error(result.error);
|
|
526
|
+
return result?.user || null;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
async function stageAction(action, targetId) {
|
|
530
|
+
await connect();
|
|
531
|
+
if (!socket?.connected) throw new Error("Not connected");
|
|
532
|
+
const result = await emit(socket, "stageAction", { action, targetId });
|
|
533
|
+
if (result?.error) throw new Error(result.error);
|
|
534
|
+
if (Array.isArray(result?.users)) {
|
|
535
|
+
ingestRosterUsers(result.users);
|
|
536
|
+
onUserList(result.users);
|
|
537
|
+
} else if (result?.user) {
|
|
538
|
+
ingestRosterUser(result.user);
|
|
539
|
+
onUserUpdated(result.user);
|
|
540
|
+
}
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
|
|
377
544
|
async function startCamera({ cameraId, resolution, track } = {}) {
|
|
378
545
|
if (track !== undefined) requireLiveTrack(track, "video");
|
|
379
546
|
await connect();
|
|
@@ -597,7 +764,7 @@ export function createClient(options = {}) {
|
|
|
597
764
|
next.wanted = true;
|
|
598
765
|
notifyRecording(next);
|
|
599
766
|
for (const [source, crop] of recordingCrops) next.setVideoCrop(source, crop);
|
|
600
|
-
next.sync(tracksForRecording());
|
|
767
|
+
next.sync(tracksForRecording(), stagePeopleForRecording());
|
|
601
768
|
try {
|
|
602
769
|
await next.start();
|
|
603
770
|
} catch (error) {
|
|
@@ -696,6 +863,11 @@ export function createClient(options = {}) {
|
|
|
696
863
|
startRecording: guard(startRecording),
|
|
697
864
|
stopRecording: guard(stopRecording),
|
|
698
865
|
setRecordingCrop,
|
|
866
|
+
setRecordingStage,
|
|
867
|
+
getUserList: guard(getUserList),
|
|
868
|
+
updateSelf: guard(updateSelf),
|
|
869
|
+
stageAction: guard(stageAction),
|
|
870
|
+
getPeerId: () => selfPeerId,
|
|
699
871
|
end: guard(end),
|
|
700
872
|
listDevices: guard(listDevices),
|
|
701
873
|
};
|
package/src/record.js
CHANGED
|
@@ -118,6 +118,8 @@ export class CanvasRecorder {
|
|
|
118
118
|
this.webinarName = webinarName || webinarId;
|
|
119
119
|
this.recordingId = recordingId;
|
|
120
120
|
this.endpoint = String(endpoint || "").replace(/\/+$/, "");
|
|
121
|
+
/** @type {{ id: string, name: string, local?: boolean }[] | null} */
|
|
122
|
+
this.stagePeople = null;
|
|
121
123
|
this.token = token || "";
|
|
122
124
|
this.selfName = String(selfName || "Host").slice(0, 40);
|
|
123
125
|
this.onCaptureChange = typeof onCaptureChange === "function" ? onCaptureChange : () => {};
|
|
@@ -232,8 +234,25 @@ export class CanvasRecorder {
|
|
|
232
234
|
for (const type of events) window.addEventListener(type, unlock, true);
|
|
233
235
|
}
|
|
234
236
|
|
|
235
|
-
|
|
237
|
+
/**
|
|
238
|
+
* @param {object[]} tracks live mediasoup tracks
|
|
239
|
+
* @param {{ id?: string, name?: string, local?: boolean }[] | null} [stagePeople]
|
|
240
|
+
* People who should appear on the recording stage (avatar until their webcam arrives).
|
|
241
|
+
* Pass null/omit to keep the previous list; pass [] to clear.
|
|
242
|
+
*/
|
|
243
|
+
sync(tracks, stagePeople) {
|
|
236
244
|
this.tracks = tracks || [];
|
|
245
|
+
if (stagePeople !== undefined) {
|
|
246
|
+
this.stagePeople = Array.isArray(stagePeople)
|
|
247
|
+
? stagePeople
|
|
248
|
+
.map((person) => ({
|
|
249
|
+
id: String(person?.id || "").trim(),
|
|
250
|
+
name: String(person?.name || "Guest").trim().slice(0, 40) || "Guest",
|
|
251
|
+
local: Boolean(person?.local),
|
|
252
|
+
}))
|
|
253
|
+
.filter((person) => person.id || person.name)
|
|
254
|
+
: null;
|
|
255
|
+
}
|
|
237
256
|
for (const item of this.tracks) {
|
|
238
257
|
if (item?.kind !== "video" || !item.source) continue;
|
|
239
258
|
const crop = normalizeVideoCrop(item.crop);
|
|
@@ -525,33 +544,82 @@ export class CanvasRecorder {
|
|
|
525
544
|
};
|
|
526
545
|
(kind === "screen" ? screens : cameras).set(key, slot);
|
|
527
546
|
}
|
|
528
|
-
// Up to 4 camera tiles: prefer local host first, then earliest remotes.
|
|
529
|
-
const localCam = [...cameras.values()].find((slot) => slot.isLocal);
|
|
530
|
-
const remotes = [...cameras.values()]
|
|
531
|
-
.filter((slot) => !slot.isLocal)
|
|
532
|
-
.sort((a, b) => a.order - b.order);
|
|
533
|
-
const chosen = (localCam ? [localCam, ...remotes] : remotes).slice(0, 4);
|
|
534
547
|
const screen = [...screens.values()].find((slot) => slot.isLocal)
|
|
535
548
|
?? [...screens.values()].sort((a, b) => a.order - b.order)[0];
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
549
|
+
const maxCams = screen ? 3 : 4;
|
|
550
|
+
const stage = Array.isArray(this.stagePeople) ? this.stagePeople : null;
|
|
551
|
+
let chosen = [];
|
|
552
|
+
const keepPlaceholders = new Set();
|
|
553
|
+
|
|
554
|
+
if (stage && stage.length) {
|
|
555
|
+
// Exact participant stage: one tile per on-stage person (live webcam or avatar).
|
|
556
|
+
const used = new Set();
|
|
557
|
+
for (const person of stage.slice(0, maxCams)) {
|
|
558
|
+
const isLocal = Boolean(person.local);
|
|
559
|
+
const id = person.id || "";
|
|
560
|
+
const name = person.name || (isLocal ? (this.selfName || "Host") : "Guest");
|
|
561
|
+
let live = null;
|
|
562
|
+
for (const slot of cameras.values()) {
|
|
563
|
+
if (used.has(slot.key)) continue;
|
|
564
|
+
if (isLocal && slot.isLocal) {
|
|
565
|
+
live = slot;
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
if (!isLocal && id && String(slot.participantKey) === id) {
|
|
569
|
+
live = slot;
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
if (!isLocal && !id && String(slot.participantKey).toLowerCase() === name.toLowerCase()) {
|
|
573
|
+
live = slot;
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (live) {
|
|
578
|
+
used.add(live.key);
|
|
579
|
+
chosen.push({ ...live, displayName: name });
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
const phKey = `placeholder|${isLocal ? "local" : (id || name.toLowerCase())}`;
|
|
583
|
+
keepPlaceholders.add(phKey);
|
|
584
|
+
const track = this.ensurePlaceholderTrack(name, isLocal, phKey);
|
|
585
|
+
chosen.push({
|
|
586
|
+
key: `${phKey}|camera`,
|
|
587
|
+
kind: "camera",
|
|
588
|
+
isLocal,
|
|
589
|
+
participantKey: id || (isLocal ? "local" : name),
|
|
590
|
+
order: this.orderOf(`${phKey}|camera`),
|
|
591
|
+
video: this.compositor ? null : this.videoFor(`${phKey}|camera`, track),
|
|
592
|
+
track,
|
|
593
|
+
placeholder: true,
|
|
594
|
+
displayName: name,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
552
597
|
} else {
|
|
553
|
-
|
|
598
|
+
// Legacy: only live cams; empty stage keeps a single host placeholder.
|
|
599
|
+
const localCam = [...cameras.values()].find((slot) => slot.isLocal);
|
|
600
|
+
const remotes = [...cameras.values()]
|
|
601
|
+
.filter((slot) => !slot.isLocal)
|
|
602
|
+
.sort((a, b) => a.order - b.order);
|
|
603
|
+
chosen = (localCam ? [localCam, ...remotes] : remotes).slice(0, maxCams);
|
|
604
|
+
if (chosen.length === 0) {
|
|
605
|
+
const name = this.selfName || "Host";
|
|
606
|
+
const phKey = "placeholder|local";
|
|
607
|
+
keepPlaceholders.add(phKey);
|
|
608
|
+
const track = this.ensurePlaceholderTrack(name, true, phKey);
|
|
609
|
+
chosen.push({
|
|
610
|
+
key: "local|camera|placeholder",
|
|
611
|
+
kind: "camera",
|
|
612
|
+
isLocal: true,
|
|
613
|
+
participantKey: "local",
|
|
614
|
+
order: this.orderOf("local|camera|placeholder"),
|
|
615
|
+
video: this.compositor ? null : this.videoFor("local|camera|placeholder", track),
|
|
616
|
+
track,
|
|
617
|
+
placeholder: true,
|
|
618
|
+
displayName: name,
|
|
619
|
+
});
|
|
620
|
+
}
|
|
554
621
|
}
|
|
622
|
+
this.prunePlaceholders(keepPlaceholders);
|
|
555
623
|
this.slots = screen ? [screen, ...chosen] : chosen;
|
|
556
624
|
if (this.compositor) {
|
|
557
625
|
const layout = layoutSlots(chosen.length, Boolean(screen));
|
|
@@ -573,8 +641,7 @@ export class CanvasRecorder {
|
|
|
573
641
|
}
|
|
574
642
|
|
|
575
643
|
/** Synthetic webcam matching the live empty-stage avatar tile (native 1280×720, no upscale). */
|
|
576
|
-
ensurePlaceholderTrack(name, isLocal) {
|
|
577
|
-
const key = `placeholder|${isLocal ? "local" : name}`;
|
|
644
|
+
ensurePlaceholderTrack(name, isLocal, key = `placeholder|${isLocal ? "local" : name}`) {
|
|
578
645
|
let entry = this.placeholderSources.get(key);
|
|
579
646
|
if (entry) {
|
|
580
647
|
entry.name = name;
|
|
@@ -600,16 +667,22 @@ export class CanvasRecorder {
|
|
|
600
667
|
return track;
|
|
601
668
|
}
|
|
602
669
|
|
|
603
|
-
|
|
604
|
-
|
|
670
|
+
prunePlaceholders(keepKeys) {
|
|
671
|
+
const keep = keepKeys instanceof Set ? keepKeys : new Set(keepKeys || []);
|
|
672
|
+
for (const [key, entry] of [...this.placeholderSources]) {
|
|
673
|
+
if (keep.has(key)) continue;
|
|
605
674
|
clearInterval(entry.timer);
|
|
606
675
|
try {
|
|
607
676
|
entry.track.stop();
|
|
608
677
|
} catch {
|
|
609
678
|
// already ended
|
|
610
679
|
}
|
|
680
|
+
this.placeholderSources.delete(key);
|
|
611
681
|
}
|
|
612
|
-
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
clearPlaceholders() {
|
|
685
|
+
this.prunePlaceholders(new Set());
|
|
613
686
|
}
|
|
614
687
|
|
|
615
688
|
orderOf(key) {
|
|
@@ -682,7 +755,15 @@ export class CanvasRecorder {
|
|
|
682
755
|
const rect = layout.cameras[index];
|
|
683
756
|
if (!rect) return;
|
|
684
757
|
if (slot.placeholder) {
|
|
685
|
-
drawStagePlaceholder(
|
|
758
|
+
drawStagePlaceholder(
|
|
759
|
+
this.ctx,
|
|
760
|
+
rect.x,
|
|
761
|
+
rect.y,
|
|
762
|
+
rect.w,
|
|
763
|
+
rect.h,
|
|
764
|
+
slot.displayName || this.selfName,
|
|
765
|
+
Boolean(slot.isLocal),
|
|
766
|
+
);
|
|
686
767
|
return;
|
|
687
768
|
}
|
|
688
769
|
paint(this.ctx, slot.video, rect, null);
|
|
@@ -825,7 +906,7 @@ function placeholderLetter(name) {
|
|
|
825
906
|
|
|
826
907
|
/**
|
|
827
908
|
* Empty-stage tile for the recording canvas:
|
|
828
|
-
* maroon radial field, solid #
|
|
909
|
+
* maroon radial field, solid #e30096 name round (no border), white initial, name top-left.
|
|
829
910
|
*/
|
|
830
911
|
function drawStagePlaceholder(ctx, x, y, w, h, name, _isLocal) {
|
|
831
912
|
const cx = Math.round(x + w / 2);
|
|
@@ -842,7 +923,7 @@ function drawStagePlaceholder(ctx, x, y, w, h, name, _isLocal) {
|
|
|
842
923
|
const radius = diameter / 2;
|
|
843
924
|
ctx.beginPath();
|
|
844
925
|
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
|
|
845
|
-
ctx.fillStyle = "#
|
|
926
|
+
ctx.fillStyle = "#e30096";
|
|
846
927
|
ctx.fill();
|
|
847
928
|
|
|
848
929
|
const letterPx = Math.round(Math.min(Math.max(diameter * 0.42, 28), 45));
|