mediascale-sdk 1.0.11 → 1.0.12
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 +5 -5
- package/package.json +1 -1
- package/src/client.js +25 -0
- package/src/record-compositor.js +17 -4
- package/src/record-frame-compositor.js +115 -38
- package/src/record-worker.js +11 -1
- package/src/record.js +94 -49
package/docs/integration.md
CHANGED
|
@@ -373,15 +373,15 @@ Canvas is **1280×720**. Video tiles and audio follow these rules:
|
|
|
373
373
|
|
|
374
374
|
| Case | Layout |
|
|
375
375
|
| --- | --- |
|
|
376
|
-
| Single camera or avatar (no screen / featured video) | **Full-bleed** — tile fills the canvas
|
|
377
|
-
| Two or more cameras (no screen) |
|
|
378
|
-
| Screen share or featured custom video (e.g. whiteboard) |
|
|
376
|
+
| Single camera or avatar (no screen / featured video) | **Full-bleed** — tile fills the canvas. No borders. Name + mic pill still drawn. |
|
|
377
|
+
| Two or more cameras (no screen) | **Flush mosaic** — zero margins/gaps between tiles, edge-to-edge, no borders. 3 cams → one row; otherwise 2- or 3-column pack. |
|
|
378
|
+
| Screen share or featured custom video (e.g. whiteboard) | Screen fills the left (~80%) with **contain** (no crop — blue letterbox top/bottom as needed). Up to **six** cameras in a right rail, **vertically centered**, **16:9** height (not stretched). Zero gaps. Extra stage video beyond six is omitted from the canvas. |
|
|
379
379
|
| Audio | **Uncapped** — every mic and screen-audio track is mixed even if that person is not among the six video tiles. |
|
|
380
380
|
|
|
381
381
|
**Name pills**
|
|
382
382
|
|
|
383
|
-
- Every camera / avatar tile gets a bottom-left **name
|
|
384
|
-
- Label comes from `setRecordingStage` `name`, else the track `displayName`, else the local host JWT name (`Guest` / `Host` as fallback).
|
|
383
|
+
- Every camera / avatar tile gets a bottom-left pill with **name + mic status** (green signal bars when live, red muted mic when muted), same as the live stage UI.
|
|
384
|
+
- Label comes from `setRecordingStage` `name`, else the track `displayName`, else the local host JWT name (`Guest` / `Host` as fallback). Presenter gets `(Presenter)` on the pill.
|
|
385
385
|
- The pill is drawn even while the first video frame is still loading (dark tile + name).
|
|
386
386
|
- The large screen / whiteboard pane does **not** get a name pill.
|
|
387
387
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -135,6 +135,8 @@ export function createClient(options = {}) {
|
|
|
135
135
|
/** When set, parent-provided stage list wins over roster-derived stageById. */
|
|
136
136
|
let stageOverride = null;
|
|
137
137
|
let lastStageSig = "";
|
|
138
|
+
/** Integration debug: log current recording stage every 5s. */
|
|
139
|
+
let stageDebugTimer = null;
|
|
138
140
|
const pending = [];
|
|
139
141
|
let readyPromise = null;
|
|
140
142
|
let settleReady = null;
|
|
@@ -165,14 +167,33 @@ export function createClient(options = {}) {
|
|
|
165
167
|
return [...stageById.values()];
|
|
166
168
|
}
|
|
167
169
|
|
|
170
|
+
function logRecordingStage(reason) {
|
|
171
|
+
const people = stagePeopleForRecording();
|
|
172
|
+
console.log("[mediascale] recording stage", {
|
|
173
|
+
reason,
|
|
174
|
+
source: stageOverride ? "setRecordingStage" : "roster",
|
|
175
|
+
count: people.length,
|
|
176
|
+
people: people.map((p) => ({ id: p.id, name: p.name, local: Boolean(p.local) })),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
168
180
|
function emitStageChanged() {
|
|
169
181
|
const people = stagePeopleForRecording();
|
|
170
182
|
const sig = people.map((p) => `${p.id}|${p.name}|${p.local ? 1 : 0}`).join(";");
|
|
171
183
|
if (sig === lastStageSig) return;
|
|
172
184
|
lastStageSig = sig;
|
|
185
|
+
// Integration: confirm setRecordingStage / roster stage updates reach the SDK recorder.
|
|
186
|
+
logRecordingStage("changed");
|
|
173
187
|
onStageChanged(people);
|
|
174
188
|
}
|
|
175
189
|
|
|
190
|
+
if (typeof setInterval === "function") {
|
|
191
|
+
stageDebugTimer = setInterval(() => {
|
|
192
|
+
if (closed) return;
|
|
193
|
+
logRecordingStage("poll-5s");
|
|
194
|
+
}, 5000);
|
|
195
|
+
}
|
|
196
|
+
|
|
176
197
|
function ingestRosterUsers(users) {
|
|
177
198
|
if (!Array.isArray(users)) return;
|
|
178
199
|
stageById.clear();
|
|
@@ -992,6 +1013,10 @@ export function createClient(options = {}) {
|
|
|
992
1013
|
async function end(options = {}) {
|
|
993
1014
|
if (closed) return;
|
|
994
1015
|
closed = true;
|
|
1016
|
+
if (stageDebugTimer) {
|
|
1017
|
+
clearInterval(stageDebugTimer);
|
|
1018
|
+
stageDebugTimer = null;
|
|
1019
|
+
}
|
|
995
1020
|
settleReady?.(new Error("Ended"));
|
|
996
1021
|
// Finalize only on explicit stop-session / finalize. Browser close uses disconnect handoff.
|
|
997
1022
|
const forceFinalize = options.finalize === true || options.endSession === true;
|
package/src/record-compositor.js
CHANGED
|
@@ -83,16 +83,29 @@ export async function createWorkerCompositor({ width, height, fps, background =
|
|
|
83
83
|
const keys = new Set(desired.map((source) => source.key));
|
|
84
84
|
for (const [key, entry] of owned) if (!keys.has(key)) { release(entry); owned.delete(key); }
|
|
85
85
|
const transfer = [];
|
|
86
|
-
const updates = desired.map((
|
|
86
|
+
const updates = desired.map((source) => {
|
|
87
|
+
const { key, track, rect, crop, label, accent, radius, muted, fit, fillStyle } = source;
|
|
88
|
+
const chrome = {
|
|
89
|
+
key,
|
|
90
|
+
rect,
|
|
91
|
+
crop: crop || null,
|
|
92
|
+
label: label || "",
|
|
93
|
+
accent: Boolean(accent),
|
|
94
|
+
radius: radius == null ? 0 : radius,
|
|
95
|
+
muted: Boolean(muted),
|
|
96
|
+
fit: fit === "contain" ? "contain" : "cover",
|
|
97
|
+
...(fillStyle ? { fillStyle } : {}),
|
|
98
|
+
};
|
|
87
99
|
const previous = owned.get(key);
|
|
88
|
-
if (previous?.original === track) return
|
|
100
|
+
if (previous?.original === track) return chrome;
|
|
89
101
|
if (previous) release(previous);
|
|
102
|
+
if (!track) return chrome;
|
|
90
103
|
const clone = track.clone();
|
|
91
104
|
owned.set(key, { clone, original: track });
|
|
92
|
-
if (standard) { transfer.push(clone); return {
|
|
105
|
+
if (standard) { transfer.push(clone); return { ...chrome, track: clone }; }
|
|
93
106
|
const readable = new MediaStreamTrackProcessor({ track: clone, maxBufferSize: 1 }).readable;
|
|
94
107
|
transfer.push(readable);
|
|
95
|
-
return {
|
|
108
|
+
return { ...chrome, readable };
|
|
96
109
|
});
|
|
97
110
|
worker.postMessage({ type: "sources", sources: updates }, transfer);
|
|
98
111
|
};
|
|
@@ -85,45 +85,111 @@ export function roundedRectPath(ctx, x, y, w, h, radius) {
|
|
|
85
85
|
ctx.closePath();
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
/**
|
|
89
|
-
export
|
|
90
|
-
|
|
88
|
+
/** Neon magenta presenter ring — matches the live stage / webinar UI. */
|
|
89
|
+
export const PRESENTER_ACCENT = "#e879f9";
|
|
90
|
+
|
|
91
|
+
function drawSignalBars(ctx, left, cy, iconSize) {
|
|
92
|
+
const barW = Math.max(2, Math.round(iconSize * 0.18));
|
|
93
|
+
const gap = Math.max(1.5, Math.round(iconSize * 0.12));
|
|
94
|
+
const heights = [0.45, 0.7, 1];
|
|
95
|
+
ctx.fillStyle = "#22c55e";
|
|
96
|
+
for (let i = 0; i < 3; i += 1) {
|
|
97
|
+
const h = iconSize * heights[i];
|
|
98
|
+
const x = left + i * (barW + gap);
|
|
99
|
+
const y = cy - h / 2;
|
|
100
|
+
ctx.beginPath();
|
|
101
|
+
roundedRectPath(ctx, x, y, barW, h, barW / 2);
|
|
102
|
+
ctx.fill();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function drawMicMuted(ctx, cx, cy, iconSize) {
|
|
107
|
+
const r = iconSize * 0.22;
|
|
108
|
+
ctx.strokeStyle = "#f43f5e";
|
|
109
|
+
ctx.fillStyle = "#f43f5e";
|
|
110
|
+
ctx.lineWidth = Math.max(1.5, iconSize * 0.1);
|
|
111
|
+
ctx.lineCap = "round";
|
|
112
|
+
// Mic capsule
|
|
113
|
+
ctx.beginPath();
|
|
114
|
+
ctx.moveTo(cx - r, cy - iconSize * 0.05);
|
|
115
|
+
ctx.quadraticCurveTo(cx - r, cy - iconSize * 0.38, cx, cy - iconSize * 0.38);
|
|
116
|
+
ctx.quadraticCurveTo(cx + r, cy - iconSize * 0.38, cx + r, cy - iconSize * 0.05);
|
|
117
|
+
ctx.lineTo(cx + r, cy + iconSize * 0.02);
|
|
118
|
+
ctx.quadraticCurveTo(cx + r, cy + iconSize * 0.22, cx, cy + iconSize * 0.22);
|
|
119
|
+
ctx.quadraticCurveTo(cx - r, cy + iconSize * 0.22, cx - r, cy + iconSize * 0.02);
|
|
120
|
+
ctx.closePath();
|
|
121
|
+
ctx.fill();
|
|
122
|
+
// Stem + base
|
|
123
|
+
ctx.beginPath();
|
|
124
|
+
ctx.arc(cx, cy + iconSize * 0.05, iconSize * 0.28, 0.15 * Math.PI, 0.85 * Math.PI);
|
|
125
|
+
ctx.stroke();
|
|
126
|
+
ctx.beginPath();
|
|
127
|
+
ctx.moveTo(cx, cy + iconSize * 0.32);
|
|
128
|
+
ctx.lineTo(cx, cy + iconSize * 0.42);
|
|
129
|
+
ctx.moveTo(cx - iconSize * 0.16, cy + iconSize * 0.42);
|
|
130
|
+
ctx.lineTo(cx + iconSize * 0.16, cy + iconSize * 0.42);
|
|
131
|
+
ctx.stroke();
|
|
132
|
+
// Slash
|
|
133
|
+
ctx.beginPath();
|
|
134
|
+
ctx.moveTo(cx - iconSize * 0.32, cy + iconSize * 0.38);
|
|
135
|
+
ctx.lineTo(cx + iconSize * 0.32, cy - iconSize * 0.38);
|
|
136
|
+
ctx.stroke();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Bottom-left name pill matching the live stage UI:
|
|
141
|
+
* dark pill + green signal bars (live) or red muted mic + optional "(Presenter)".
|
|
142
|
+
*/
|
|
143
|
+
export function drawNamePill(ctx, x, y, w, h, label, { presenter = false, muted = false } = {}) {
|
|
144
|
+
let text = String(label || "").trim().slice(0, 40);
|
|
91
145
|
if (!text) return;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
146
|
+
if (presenter && !/\(\s*presenter\s*\)/i.test(text)) {
|
|
147
|
+
text = `${text.slice(0, 28)} (Presenter)`;
|
|
148
|
+
}
|
|
149
|
+
const padX = Math.max(10, Math.round(Math.min(w, h) * 0.035));
|
|
150
|
+
const padY = Math.max(8, Math.round(Math.min(w, h) * 0.03));
|
|
151
|
+
const namePx = Math.round(Math.min(Math.max(Math.min(w, h) * 0.08, 11), 15));
|
|
152
|
+
const iconSize = Math.round(namePx * 1.15);
|
|
95
153
|
ctx.save();
|
|
96
154
|
ctx.font = `600 ${namePx}px "Segoe UI", Roboto, Helvetica, Arial, sans-serif`;
|
|
97
155
|
ctx.textAlign = "left";
|
|
98
156
|
ctx.textBaseline = "middle";
|
|
99
157
|
const textW = ctx.measureText(text).width;
|
|
100
|
-
const
|
|
101
|
-
const
|
|
158
|
+
const iconGap = Math.round(iconSize * 0.45);
|
|
159
|
+
const pillH = Math.max(iconSize + padY * 0.7, namePx + padY);
|
|
160
|
+
const contentW = iconSize + iconGap + textW;
|
|
161
|
+
const pillW = Math.min(w - padX * 2, contentW + padX * 1.5);
|
|
102
162
|
const pillX = x + padX;
|
|
103
163
|
const pillY = y + h - padY - pillH;
|
|
104
164
|
const radius = pillH / 2;
|
|
105
165
|
roundedRectPath(ctx, pillX, pillY, pillW, pillH, radius);
|
|
106
166
|
ctx.fillStyle = "rgba(15, 23, 42, 0.72)";
|
|
107
167
|
ctx.fill();
|
|
168
|
+
|
|
169
|
+
const cy = pillY + pillH / 2;
|
|
170
|
+
const iconLeft = pillX + padX * 0.55;
|
|
171
|
+
if (presenter || !muted) {
|
|
172
|
+
drawSignalBars(ctx, iconLeft, cy, iconSize);
|
|
173
|
+
} else {
|
|
174
|
+
drawMicMuted(ctx, iconLeft + iconSize / 2, cy, iconSize);
|
|
175
|
+
}
|
|
108
176
|
ctx.fillStyle = "#ffffff";
|
|
109
|
-
|
|
177
|
+
const textX = iconLeft + iconSize + iconGap;
|
|
178
|
+
ctx.fillText(text, textX, cy + 0.5, Math.max(8, pillW - (textX - pillX) - padX * 0.5));
|
|
110
179
|
ctx.restore();
|
|
111
180
|
}
|
|
112
181
|
|
|
113
|
-
export function strokeTileBorder(ctx, x, y, w, h, radius, { accent = false, accentColor =
|
|
114
|
-
|
|
115
|
-
|
|
182
|
+
export function strokeTileBorder(ctx, x, y, w, h, radius, { accent = false, accentColor = PRESENTER_ACCENT } = {}) {
|
|
183
|
+
// Recording layout is flush (no borders). Accent only affects the name pill.
|
|
184
|
+
if (!(radius > 0)) return;
|
|
185
|
+
const base = parseCssColor(accentColor) || { r: 232, g: 121, b: 249 };
|
|
116
186
|
ctx.save();
|
|
117
|
-
|
|
118
|
-
else {
|
|
119
|
-
ctx.beginPath();
|
|
120
|
-
ctx.rect(x + 0.5, y + 0.5, w - 1, h - 1);
|
|
121
|
-
}
|
|
187
|
+
roundedRectPath(ctx, x + 0.5, y + 0.5, w - 1, h - 1, radius);
|
|
122
188
|
if (accent) {
|
|
123
|
-
ctx.strokeStyle = cssRgb(shadeRgb(base, 1.
|
|
189
|
+
ctx.strokeStyle = cssRgb(shadeRgb(base, 1.05));
|
|
124
190
|
ctx.lineWidth = 3;
|
|
125
|
-
ctx.shadowColor = cssRgb(base, 0.
|
|
126
|
-
ctx.shadowBlur =
|
|
191
|
+
ctx.shadowColor = cssRgb(base, 0.95);
|
|
192
|
+
ctx.shadowBlur = 14;
|
|
127
193
|
} else {
|
|
128
194
|
ctx.strokeStyle = "rgba(255, 255, 255, 0.45)";
|
|
129
195
|
ctx.lineWidth = 1.5;
|
|
@@ -134,7 +200,9 @@ export function strokeTileBorder(ctx, x, y, w, h, radius, { accent = false, acce
|
|
|
134
200
|
}
|
|
135
201
|
|
|
136
202
|
/**
|
|
137
|
-
* Draw a video/image source into a
|
|
203
|
+
* Draw a video/image source into a tile (flush by default) + name/mic pill.
|
|
204
|
+
* `fit: "cover"` fills the rect (cameras). `fit: "contain"` letterboxes inside
|
|
205
|
+
* the rect (screenshare — no cropping; bars use `fillStyle`, typically brand blue).
|
|
138
206
|
* `source` may be an HTMLVideoElement or VideoFrame-like canvas image source.
|
|
139
207
|
*/
|
|
140
208
|
export function paintRoundedTile(ctx, {
|
|
@@ -146,20 +214,28 @@ export function paintRoundedTile(ctx, {
|
|
|
146
214
|
sh,
|
|
147
215
|
label = "",
|
|
148
216
|
accent = false,
|
|
149
|
-
accentColor =
|
|
150
|
-
radius =
|
|
217
|
+
accentColor = PRESENTER_ACCENT,
|
|
218
|
+
radius = 0,
|
|
151
219
|
fillStyle = "#0f172a",
|
|
220
|
+
muted = false,
|
|
221
|
+
fit = "cover",
|
|
152
222
|
}) {
|
|
153
223
|
const { x, y, w, h } = rect;
|
|
154
224
|
ctx.save();
|
|
155
225
|
if (radius > 0) {
|
|
156
226
|
roundedRectPath(ctx, x, y, w, h, radius);
|
|
157
227
|
ctx.clip();
|
|
228
|
+
} else {
|
|
229
|
+
ctx.beginPath();
|
|
230
|
+
ctx.rect(x, y, w, h);
|
|
231
|
+
ctx.clip();
|
|
158
232
|
}
|
|
159
233
|
ctx.fillStyle = fillStyle;
|
|
160
234
|
ctx.fillRect(x, y, w, h);
|
|
161
235
|
if (source && sw > 0 && sh > 0) {
|
|
162
|
-
const scale =
|
|
236
|
+
const scale = fit === "contain"
|
|
237
|
+
? Math.min(w / sw, h / sh)
|
|
238
|
+
: Math.max(w / sw, h / sh);
|
|
163
239
|
const dw = sw * scale;
|
|
164
240
|
const dh = sh * scale;
|
|
165
241
|
const prev = ctx.imageSmoothingEnabled;
|
|
@@ -169,7 +245,7 @@ export function paintRoundedTile(ctx, {
|
|
|
169
245
|
}
|
|
170
246
|
ctx.restore();
|
|
171
247
|
if (radius > 0) strokeTileBorder(ctx, x, y, w, h, radius, { accent, accentColor });
|
|
172
|
-
if (label) drawNamePill(ctx, x, y, w, h, label);
|
|
248
|
+
if (label) drawNamePill(ctx, x, y, w, h, label, { presenter: accent, muted });
|
|
173
249
|
}
|
|
174
250
|
|
|
175
251
|
/** Owns at most one input frame per source and one output write. */
|
|
@@ -229,23 +305,28 @@ export class FrameCompositor {
|
|
|
229
305
|
if (!this.active || !this.dirty || this.writing || now - this.lastDraw < this.interval) return;
|
|
230
306
|
fillRadialBackground(this.ctx, 0, 0, this.canvas.width, this.canvas.height, this.background);
|
|
231
307
|
for (const source of this.sources) {
|
|
232
|
-
const { key, rect, crop, label, accent, radius } = source;
|
|
308
|
+
const { key, rect, crop, label, accent, radius, muted, fit, fillStyle } = source;
|
|
233
309
|
const frame = this.frames.get(key);
|
|
234
310
|
if (!rect) continue;
|
|
235
|
-
const tileRadius = radius == null ?
|
|
311
|
+
const tileRadius = radius == null ? 0 : radius;
|
|
312
|
+
const chrome = {
|
|
313
|
+
label: label || "",
|
|
314
|
+
accent: Boolean(accent),
|
|
315
|
+
accentColor: PRESENTER_ACCENT,
|
|
316
|
+
radius: tileRadius,
|
|
317
|
+
muted: Boolean(muted),
|
|
318
|
+
fillStyle: fillStyle || "#0f172a",
|
|
319
|
+
fit: fit === "contain" ? "contain" : "cover",
|
|
320
|
+
};
|
|
236
321
|
if (!frame) {
|
|
237
322
|
// Still show the name pill while the first video frame is arriving.
|
|
238
|
-
if (label) {
|
|
323
|
+
if (chrome.label) {
|
|
239
324
|
paintRoundedTile(this.ctx, {
|
|
240
325
|
source: null,
|
|
241
326
|
rect,
|
|
242
327
|
sw: 0,
|
|
243
328
|
sh: 0,
|
|
244
|
-
|
|
245
|
-
accent: Boolean(accent),
|
|
246
|
-
accentColor: this.background,
|
|
247
|
-
radius: tileRadius,
|
|
248
|
-
fillStyle: "#0f172a",
|
|
329
|
+
...chrome,
|
|
249
330
|
});
|
|
250
331
|
}
|
|
251
332
|
continue;
|
|
@@ -271,11 +352,7 @@ export class FrameCompositor {
|
|
|
271
352
|
sy,
|
|
272
353
|
sw,
|
|
273
354
|
sh,
|
|
274
|
-
|
|
275
|
-
accent: Boolean(accent),
|
|
276
|
-
accentColor: this.background,
|
|
277
|
-
radius: tileRadius,
|
|
278
|
-
fillStyle: "#0f172a",
|
|
355
|
+
...chrome,
|
|
279
356
|
});
|
|
280
357
|
}
|
|
281
358
|
this.timestamp = Math.max(this.timestamp + 1, Math.round((now - this.startedAt) * 1000));
|
package/src/record-worker.js
CHANGED
|
@@ -69,7 +69,17 @@ self.onmessage = async ({ data }) => {
|
|
|
69
69
|
} else if (data.type === "sources") {
|
|
70
70
|
const keys = new Set(data.sources.map((source) => source.key));
|
|
71
71
|
for (const key of readers.keys()) if (!keys.has(key)) remove(key);
|
|
72
|
-
compositor.setSources(data.sources.map(({ key, rect, crop
|
|
72
|
+
compositor.setSources(data.sources.map(({ key, rect, crop, label, accent, radius, muted, fit, fillStyle }) => ({
|
|
73
|
+
key,
|
|
74
|
+
rect,
|
|
75
|
+
crop: crop || null,
|
|
76
|
+
label: label || "",
|
|
77
|
+
accent: Boolean(accent),
|
|
78
|
+
radius: radius == null ? 0 : radius,
|
|
79
|
+
muted: Boolean(muted),
|
|
80
|
+
fit: fit === "contain" ? "contain" : "cover",
|
|
81
|
+
...(fillStyle ? { fillStyle } : {}),
|
|
82
|
+
})));
|
|
73
83
|
for (const source of data.sources) {
|
|
74
84
|
if (!source.readable && !source.track) continue;
|
|
75
85
|
remove(source.key);
|
package/src/record.js
CHANGED
|
@@ -5,16 +5,21 @@ import {
|
|
|
5
5
|
drawNamePill,
|
|
6
6
|
strokeTileBorder,
|
|
7
7
|
roundedRectPath,
|
|
8
|
+
PRESENTER_ACCENT,
|
|
8
9
|
} from "./record-frame-compositor.js";
|
|
9
|
-
export { FrameCompositor, fillRadialBackground } from "./record-frame-compositor.js";
|
|
10
|
+
export { FrameCompositor, fillRadialBackground, PRESENTER_ACCENT } from "./record-frame-compositor.js";
|
|
10
11
|
|
|
11
12
|
const W = 1280;
|
|
12
13
|
const H = 720;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
14
|
+
/** Right rail width with screenshare (~20%). Camera tiles keep 16:9 — not stretched to full height. */
|
|
15
|
+
const COL = Math.round(W * 0.2);
|
|
16
|
+
/** Flush mosaic: no outer margin and no gutters between tiles. */
|
|
17
|
+
const PAD = 0;
|
|
18
|
+
const GAP = 0;
|
|
19
|
+
/** Recording tiles are square-edged (no borders / radius). */
|
|
20
|
+
const TILE_RADIUS = 0;
|
|
21
|
+
/** Side-rail camera aspect (width / height). */
|
|
22
|
+
const SIDE_CAM_ASPECT = 16 / 9;
|
|
18
23
|
const FPS = 15;
|
|
19
24
|
const SLICE_MS = 5000;
|
|
20
25
|
/** Hard cap for on-canvas camera / avatar tiles (host included). Audio is uncapped. */
|
|
@@ -29,7 +34,7 @@ export function recordingWebinarId(channelId) {
|
|
|
29
34
|
return cleaned || "webinar";
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
/** Equal tiles, or
|
|
37
|
+
/** Equal flush tiles, or screenshare + cameras stacked from the top (proportionate height). Up to 6 cameras. */
|
|
33
38
|
export function layoutSlots(cameras, screen) {
|
|
34
39
|
const n = Math.max(0, Math.min(MAX_STAGE_CAMERAS, Number(cameras) || 0));
|
|
35
40
|
// One tile only — fill the canvas so recordingCanvasBackground is not visible as a border.
|
|
@@ -40,31 +45,40 @@ export function layoutSlots(cameras, screen) {
|
|
|
40
45
|
return { cameras: [{ x: 0, y: 0, w: W, h: H }] };
|
|
41
46
|
}
|
|
42
47
|
if (screen) {
|
|
43
|
-
const mainW = W - COL
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
const mainW = W - COL;
|
|
49
|
+
// Keep 16:9 side tiles; shrink only when the stack would overflow the canvas.
|
|
50
|
+
let tileH = Math.max(1, Math.round(COL / SIDE_CAM_ASPECT));
|
|
51
|
+
if (n > 0 && tileH * n > H) {
|
|
52
|
+
tileH = Math.max(1, Math.floor(H / n));
|
|
53
|
+
}
|
|
54
|
+
const stackH = n * tileH;
|
|
55
|
+
const y0 = Math.max(0, Math.floor((H - stackH) / 2));
|
|
47
56
|
return {
|
|
48
|
-
screen: { x:
|
|
57
|
+
screen: { x: 0, y: 0, w: mainW, h: H },
|
|
49
58
|
cameras: Array.from({ length: n }, (_, i) => ({
|
|
50
|
-
x:
|
|
51
|
-
y:
|
|
59
|
+
x: mainW,
|
|
60
|
+
y: y0 + i * tileH,
|
|
52
61
|
w: COL,
|
|
53
62
|
h: tileH,
|
|
54
63
|
})),
|
|
55
64
|
};
|
|
56
65
|
}
|
|
57
|
-
|
|
66
|
+
// Gallery: 3 cams → one row; otherwise pack 2 or 3 columns. Zero gaps, edge-to-edge.
|
|
67
|
+
const cols = n <= 3 ? n : n <= 4 ? 2 : 3;
|
|
58
68
|
const rows = Math.max(1, Math.ceil(n / cols));
|
|
59
|
-
const cellW = Math.floor(
|
|
60
|
-
const cellH = Math.floor(
|
|
69
|
+
const cellW = Math.floor(W / cols);
|
|
70
|
+
const cellH = Math.floor(H / rows);
|
|
61
71
|
return {
|
|
62
|
-
cameras: Array.from({ length: n }, (_, i) =>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
cameras: Array.from({ length: n }, (_, i) => {
|
|
73
|
+
const col = i % cols;
|
|
74
|
+
const row = Math.floor(i / cols);
|
|
75
|
+
const x = col * cellW;
|
|
76
|
+
const y = row * cellH;
|
|
77
|
+
// Give leftover pixels to the last column / row so the mosaic reaches the canvas edge.
|
|
78
|
+
const w = col === cols - 1 ? W - x : cellW;
|
|
79
|
+
const h = row === rows - 1 ? H - y : cellH;
|
|
80
|
+
return { x, y, w, h };
|
|
81
|
+
}),
|
|
68
82
|
};
|
|
69
83
|
}
|
|
70
84
|
|
|
@@ -119,12 +133,16 @@ function resolveTileLabel(slot, selfName) {
|
|
|
119
133
|
return "Guest";
|
|
120
134
|
}
|
|
121
135
|
|
|
122
|
-
function
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
function hasLiveMic(slot, mics) {
|
|
137
|
+
if (!mics || typeof mics.has !== "function") return false;
|
|
138
|
+
if (slot?.isLocal) return mics.has("local-mic");
|
|
139
|
+
const key = String(slot?.participantKey || "").trim();
|
|
140
|
+
if (!key) return false;
|
|
141
|
+
return mics.has(`${key}|mic`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function isPresenterSlot(slot, label) {
|
|
145
|
+
return Boolean(slot?.isLocal) || /presenter/i.test(String(label || ""));
|
|
128
146
|
}
|
|
129
147
|
|
|
130
148
|
/** Screen share and custom video (e.g. whiteboard) use the large featured slot. */
|
|
@@ -679,6 +697,16 @@ export class CanvasRecorder {
|
|
|
679
697
|
});
|
|
680
698
|
}
|
|
681
699
|
}
|
|
700
|
+
// Attach mic / presenter chrome onto camera slots for both compositor paths.
|
|
701
|
+
chosen = chosen.map((slot) => {
|
|
702
|
+
const label = resolveTileLabel(slot, this.selfName);
|
|
703
|
+
return {
|
|
704
|
+
...slot,
|
|
705
|
+
displayName: label,
|
|
706
|
+
micMuted: !hasLiveMic(slot, mics),
|
|
707
|
+
presenter: isPresenterSlot(slot, label),
|
|
708
|
+
};
|
|
709
|
+
});
|
|
682
710
|
this.prunePlaceholders(keepPlaceholders);
|
|
683
711
|
this.slots = screen ? [screen, ...chosen] : chosen;
|
|
684
712
|
if (this.compositor) {
|
|
@@ -688,23 +716,27 @@ export class CanvasRecorder {
|
|
|
688
716
|
key: screen.key,
|
|
689
717
|
track: screen.track,
|
|
690
718
|
rect: layout.screen,
|
|
691
|
-
crop:
|
|
719
|
+
crop: null,
|
|
692
720
|
label: "",
|
|
693
721
|
accent: false,
|
|
722
|
+
muted: false,
|
|
723
|
+
// Letterbox screenshare (no crop); bars use brand canvas blue.
|
|
724
|
+
fit: "contain",
|
|
725
|
+
fillStyle: this.canvasBackground || "#2563eb",
|
|
694
726
|
}] : []),
|
|
695
727
|
...chosen.map((slot, index) => {
|
|
696
728
|
const rect = layout.cameras[index];
|
|
697
|
-
const label = resolveTileLabel(slot, this.selfName);
|
|
698
|
-
const fullBleed = isFullBleedRect(rect);
|
|
699
729
|
return {
|
|
700
730
|
key: slot.key,
|
|
701
731
|
track: slot.track,
|
|
702
732
|
rect,
|
|
703
733
|
crop: null,
|
|
704
|
-
label,
|
|
705
|
-
// Presenter
|
|
706
|
-
accent:
|
|
707
|
-
radius:
|
|
734
|
+
label: slot.displayName,
|
|
735
|
+
// Presenter flag drives the name-pill label only (no tile borders).
|
|
736
|
+
accent: Boolean(slot.presenter),
|
|
737
|
+
radius: TILE_RADIUS,
|
|
738
|
+
muted: Boolean(slot.micMuted),
|
|
739
|
+
fit: "cover",
|
|
708
740
|
};
|
|
709
741
|
}),
|
|
710
742
|
]);
|
|
@@ -832,31 +864,35 @@ export class CanvasRecorder {
|
|
|
832
864
|
const layout = layoutSlots(cameras.length, Boolean(screen));
|
|
833
865
|
fillRadialBackground(this.ctx, 0, 0, W, H, this.canvasBackground);
|
|
834
866
|
if (screen && layout.screen) {
|
|
835
|
-
paint(this.ctx, screen.video, layout.screen,
|
|
867
|
+
paint(this.ctx, screen.video, layout.screen, null, {
|
|
836
868
|
label: "",
|
|
837
869
|
accent: false,
|
|
838
870
|
accentColor: this.canvasBackground,
|
|
871
|
+
fit: "contain",
|
|
872
|
+
fillStyle: this.canvasBackground || "#2563eb",
|
|
839
873
|
});
|
|
840
874
|
}
|
|
841
875
|
cameras.forEach((slot, index) => {
|
|
842
876
|
const rect = layout.cameras[index];
|
|
843
877
|
if (!rect) return;
|
|
844
878
|
const label = resolveTileLabel(slot, this.selfName);
|
|
845
|
-
const
|
|
846
|
-
const
|
|
847
|
-
const
|
|
879
|
+
const accent = slot.presenter != null ? Boolean(slot.presenter) : isPresenterSlot(slot, label);
|
|
880
|
+
const radius = TILE_RADIUS;
|
|
881
|
+
const muted = slot.micMuted != null ? Boolean(slot.micMuted) : false;
|
|
848
882
|
if (slot.placeholder) {
|
|
849
|
-
drawStagePlaceholder(this.ctx, rect.x, rect.y, rect.w, rect.h, label, accent,
|
|
883
|
+
drawStagePlaceholder(this.ctx, rect.x, rect.y, rect.w, rect.h, label, accent, PRESENTER_ACCENT, {
|
|
850
884
|
chrome: true,
|
|
851
885
|
radius,
|
|
886
|
+
muted,
|
|
852
887
|
});
|
|
853
888
|
return;
|
|
854
889
|
}
|
|
855
890
|
paint(this.ctx, slot.video, rect, null, {
|
|
856
891
|
label,
|
|
857
892
|
accent,
|
|
858
|
-
accentColor:
|
|
893
|
+
accentColor: PRESENTER_ACCENT,
|
|
859
894
|
radius,
|
|
895
|
+
muted,
|
|
860
896
|
});
|
|
861
897
|
});
|
|
862
898
|
this.capture?.requestFrame();
|
|
@@ -1018,11 +1054,12 @@ function placeholderLetter(name) {
|
|
|
1018
1054
|
}
|
|
1019
1055
|
|
|
1020
1056
|
/**
|
|
1021
|
-
* Empty-stage tile: magenta avatar field. With chrome: rounded border + name pill (
|
|
1057
|
+
* Empty-stage tile: magenta avatar field. With chrome: rounded border + name pill (signal / mute icons).
|
|
1022
1058
|
*/
|
|
1023
|
-
function drawStagePlaceholder(ctx, x, y, w, h, name, accent = false, accentColor =
|
|
1059
|
+
function drawStagePlaceholder(ctx, x, y, w, h, name, accent = false, accentColor = PRESENTER_ACCENT, options = {}) {
|
|
1024
1060
|
const chrome = options.chrome !== false;
|
|
1025
1061
|
const corner = options.radius ?? TILE_RADIUS;
|
|
1062
|
+
const muted = Boolean(options.muted);
|
|
1026
1063
|
const cx = Math.round(x + w / 2);
|
|
1027
1064
|
const cy = Math.round(y + h / 2);
|
|
1028
1065
|
ctx.save();
|
|
@@ -1055,14 +1092,17 @@ function drawStagePlaceholder(ctx, x, y, w, h, name, accent = false, accentColor
|
|
|
1055
1092
|
|
|
1056
1093
|
if (!chrome) return;
|
|
1057
1094
|
if (corner > 0) strokeTileBorder(ctx, x, y, w, h, corner, { accent, accentColor });
|
|
1058
|
-
drawNamePill(ctx, x, y, w, h, name);
|
|
1095
|
+
drawNamePill(ctx, x, y, w, h, name, { presenter: accent, muted });
|
|
1059
1096
|
}
|
|
1060
1097
|
|
|
1061
1098
|
function paint(ctx, video, rect, crop, options = {}) {
|
|
1062
1099
|
const label = options.label || "";
|
|
1063
1100
|
const accent = Boolean(options.accent);
|
|
1064
|
-
const accentColor = options.accentColor ||
|
|
1101
|
+
const accentColor = options.accentColor || PRESENTER_ACCENT;
|
|
1065
1102
|
const radius = options.radius ?? TILE_RADIUS;
|
|
1103
|
+
const muted = Boolean(options.muted);
|
|
1104
|
+
const fit = options.fit === "contain" ? "contain" : "cover";
|
|
1105
|
+
const fillStyle = options.fillStyle || "#0f172a";
|
|
1066
1106
|
if (!video || video.readyState < 2 || !video.videoWidth) {
|
|
1067
1107
|
paintRoundedTile(ctx, {
|
|
1068
1108
|
source: null,
|
|
@@ -1073,7 +1113,9 @@ function paint(ctx, video, rect, crop, options = {}) {
|
|
|
1073
1113
|
accent,
|
|
1074
1114
|
accentColor,
|
|
1075
1115
|
radius,
|
|
1076
|
-
|
|
1116
|
+
muted,
|
|
1117
|
+
fit,
|
|
1118
|
+
fillStyle,
|
|
1077
1119
|
});
|
|
1078
1120
|
return;
|
|
1079
1121
|
}
|
|
@@ -1081,7 +1123,8 @@ function paint(ctx, video, rect, crop, options = {}) {
|
|
|
1081
1123
|
let sy = 0;
|
|
1082
1124
|
let sw = video.videoWidth;
|
|
1083
1125
|
let sh = video.videoHeight;
|
|
1084
|
-
|
|
1126
|
+
// Screenshare uses contain (no crop). Camera tiles may still honor a stage crop.
|
|
1127
|
+
const cropNorm = fit === "contain" ? null : normalizeVideoCrop(crop);
|
|
1085
1128
|
if (cropNorm) {
|
|
1086
1129
|
sx = cropNorm.x * video.videoWidth;
|
|
1087
1130
|
sy = cropNorm.y * video.videoHeight;
|
|
@@ -1100,7 +1143,9 @@ function paint(ctx, video, rect, crop, options = {}) {
|
|
|
1100
1143
|
accent,
|
|
1101
1144
|
accentColor,
|
|
1102
1145
|
radius,
|
|
1103
|
-
|
|
1146
|
+
muted,
|
|
1147
|
+
fit,
|
|
1148
|
+
fillStyle,
|
|
1104
1149
|
});
|
|
1105
1150
|
}
|
|
1106
1151
|
|