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.
@@ -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 (no outer margin). **No border radius.** Name pill still drawn. Brand canvas background is not visible as a letterbox. |
377
- | Two or more cameras (no screen) | Grid with even outer padding and gutters (`16px`), rounded tiles (`14px` radius), light border. Local / presenter tile gets an accent glow from `recordingCanvasBackground`. |
378
- | Screen share or featured custom video (e.g. whiteboard) | Large main pane on the left; up to **six** cameras / avatars in a **right column stacked from the top** (fixed tile height so fewer cameras sit at the top, not stretched apart). Extra stage video beyond six is omitted from the canvas. |
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-only** pill (no mic or signal icons).
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediascale-sdk",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Mediascale React/browser SDK for live sessions, WebRTC publish/subscribe, and recording",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
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;
@@ -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(({ key, track, rect, crop }) => {
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 { key, rect, crop: crop || null };
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 { key, rect, crop: crop || null, track: clone }; }
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 { key, rect, crop: crop || null, readable };
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
- /** Bottom-left name pill — text only (no mic / signal icons). */
89
- export function drawNamePill(ctx, x, y, w, h, label) {
90
- const text = String(label || "").trim().slice(0, 40);
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
- const padX = Math.max(10, Math.round(Math.min(w, h) * 0.04));
93
- const padY = Math.max(8, Math.round(Math.min(w, h) * 0.035));
94
- const namePx = Math.round(Math.min(Math.max(Math.min(w, h) * 0.085, 11), 16));
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 pillH = namePx + padY;
101
- const pillW = Math.min(w - padX * 2, textW + padX * 1.6);
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
- ctx.fillText(text, pillX + padX * 0.75, pillY + pillH / 2 + 0.5, pillW - padX * 1.2);
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 = "#a855f7" } = {}) {
114
- if (!(radius > 0) && !accent) return;
115
- const base = parseCssColor(accentColor) || { r: 168, g: 85, b: 247 };
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
- if (radius > 0) roundedRectPath(ctx, x + 0.5, y + 0.5, w - 1, h - 1, radius);
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.15));
189
+ ctx.strokeStyle = cssRgb(shadeRgb(base, 1.05));
124
190
  ctx.lineWidth = 3;
125
- ctx.shadowColor = cssRgb(base, 0.85);
126
- ctx.shadowBlur = 10;
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 rounded tile with border + name pill.
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 = "#a855f7",
150
- radius = 14,
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 = Math.min(w / sw, h / sh);
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 ? 14 : radius;
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
- label,
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
- label: label || "",
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));
@@ -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 }) => ({ key, rect, crop: crop || null })));
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
- const COL = 240;
14
- /** Match reference stage: even outer margin and gutters between tiles. */
15
- const PAD = 16;
16
- const GAP = 16;
17
- const TILE_RADIUS = 14;
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 one screenshare with cameras stacked from the top in a side column. Up to 6 cameras. */
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 - PAD * 2 - GAP;
44
- const mainH = H - PAD * 2;
45
- // Fixed tile height so up to 6 fit; fewer cameras stack from the top (not stretched apart).
46
- const tileH = Math.floor((mainH - GAP * (MAX_STAGE_CAMERAS - 1)) / MAX_STAGE_CAMERAS);
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: PAD, y: PAD, w: mainW, h: mainH },
57
+ screen: { x: 0, y: 0, w: mainW, h: H },
49
58
  cameras: Array.from({ length: n }, (_, i) => ({
50
- x: PAD + mainW + GAP,
51
- y: PAD + i * (tileH + GAP),
59
+ x: mainW,
60
+ y: y0 + i * tileH,
52
61
  w: COL,
53
62
  h: tileH,
54
63
  })),
55
64
  };
56
65
  }
57
- const cols = n <= 1 ? 1 : n <= 2 ? 2 : n <= 4 ? 2 : 3;
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((W - PAD * 2 - GAP * (cols - 1)) / cols);
60
- const cellH = Math.floor((H - PAD * 2 - GAP * (rows - 1)) / rows);
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
- x: PAD + (i % cols) * (cellW + GAP),
64
- y: PAD + Math.floor(i / cols) * (cellH + GAP),
65
- w: cellW,
66
- h: cellH,
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 isFullBleedRect(rect) {
123
- return rect
124
- && rect.x <= 0
125
- && rect.y <= 0
126
- && rect.w >= W - 1
127
- && rect.h >= H - 1;
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: screen.crop || null,
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 / local host gets the accent glow border from the brand color.
706
- accent: !fullBleed && (Boolean(slot.isLocal) || /presenter/i.test(label)),
707
- radius: fullBleed ? 0 : TILE_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, screen.crop, {
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 fullBleed = isFullBleedRect(rect);
846
- const accent = !fullBleed && (Boolean(slot.isLocal) || /presenter/i.test(label));
847
- const radius = fullBleed ? 0 : TILE_RADIUS;
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, this.canvasBackground, {
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: this.canvasBackground,
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 (no mic/signal icons).
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 = "#2563eb", options = {}) {
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 || "#2563eb";
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
- fillStyle: "#0f172a",
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
- const cropNorm = normalizeVideoCrop(crop);
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
- fillStyle: "#0f172a",
1146
+ muted,
1147
+ fit,
1148
+ fillStyle,
1104
1149
  });
1105
1150
  }
1106
1151