mediascale-sdk 1.0.16 → 1.0.17
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 +57 -3
- package/package.json +1 -1
- package/src/client.js +32 -2
- package/src/index.js +6 -1
- package/src/record-compositor.js +2 -1
- package/src/record-frame-compositor.js +27 -1
- package/src/record-worker.js +2 -1
- package/src/record.js +110 -8
package/docs/integration.md
CHANGED
|
@@ -119,6 +119,56 @@ Rules:
|
|
|
119
119
|
|
|
120
120
|
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.
|
|
121
121
|
|
|
122
|
+
### Active speaker in the recording
|
|
123
|
+
|
|
124
|
+
Keep server-side active-speaker detection enabled the same way you do for the live UI. The SDK already receives portal `activeSpeaker` events and paints a **cyan speak ring** on the matching camera or camera-off avatar tile in the recorded file. You do **not** call a separate “setSpeaking” API.
|
|
125
|
+
|
|
126
|
+
| Required? | Action |
|
|
127
|
+
| --- | --- |
|
|
128
|
+
| No (if already done for live UI) | Keep active-speaker detection enabled server-side |
|
|
129
|
+
| No new callback | Do not call a speak API — the recording host browser applies speak state automatically |
|
|
130
|
+
| Keep as today | Continue `setRecordingStage([{ id, name, local?, ... }])` so stage ids match peer ids used by `activeSpeaker` |
|
|
131
|
+
| Only if not 1080p | Pass once: `createClient({ recordingResolution: 2048 })` → `3640×2048` WebM (see [Recording resolution](#recording-resolution-custom-height)) |
|
|
132
|
+
| Verify | The recording host is the browser that receives portal `activeSpeaker` (same as live highlight) |
|
|
133
|
+
|
|
134
|
+
### Recording resolution (custom height)
|
|
135
|
+
|
|
136
|
+
The recorded WebM defaults to **1080p** (`1920×1080`). To raise (or lower) quality, set a custom **vertical** resolution — same meaning as “720p” / “1080p” / “2048p”: the number is the **height**, and width is derived at **16:9** (even dimensions for the encoder).
|
|
137
|
+
|
|
138
|
+
| `recordingResolution` | Output canvas | Notes |
|
|
139
|
+
| --- | --- | --- |
|
|
140
|
+
| unset / `1080` / `"1080p"` | `1920×1080` | Default |
|
|
141
|
+
| `720` / `"720p"` | `1280×720` | |
|
|
142
|
+
| `2048` / `"2048p"` | `3640×2048` | Custom “2048p” |
|
|
143
|
+
| any number `N` (360–4096) | width ≈ `N × 16/9` × height `N` | Height is clamped to 360–4096 |
|
|
144
|
+
|
|
145
|
+
Pass it once when creating the client (recommended for webinar apps), or when starting / updating recording:
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
// Preferred: set once at create time
|
|
149
|
+
const client = createClient({
|
|
150
|
+
endpoint,
|
|
151
|
+
sessionId,
|
|
152
|
+
token,
|
|
153
|
+
recording: true,
|
|
154
|
+
recordingResolution: 2048, // → 3640×2048 WebM
|
|
155
|
+
// recordingBitrate: 16_000_000, // optional override (bps); otherwise scales with pixels
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Or change before the next segment
|
|
159
|
+
client.setRecordingResolution(2048);
|
|
160
|
+
client.getRecordingResolution(); // { resolution: 2048, width: 3640, height: 2048 }
|
|
161
|
+
|
|
162
|
+
await client.startRecording({ resolution: 2048 });
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Details for integrators**
|
|
166
|
+
|
|
167
|
+
- Size and bitrate apply on the **next** recorder open / segment start (same pattern as `recordingFps`). A running segment keeps its size.
|
|
168
|
+
- VP8 bitrate scales with pixel count (~4.5 Mbps at 1080p; ~16 Mbps at 2048p) unless you set `recordingBitrate`.
|
|
169
|
+
- This only affects the **recording** canvas, not live RTMP (`rtmpResolution` is separate and still capped at 1080p).
|
|
170
|
+
- The JWT / Stream Control meet link does not carry resolution; set it in your app via `createClient` (the sample also accepts `?recordingResolution=2048` on the meet URL for QA).
|
|
171
|
+
|
|
122
172
|
## 2. Copy the room page
|
|
123
173
|
|
|
124
174
|
Copy `sdk/react-sdk/sample/app/room.js` into your app. The comments in that file are the steps.
|
|
@@ -225,7 +275,7 @@ await client.end(); // combines every segment into one file
|
|
|
225
275
|
|
|
226
276
|
| Function | What it does |
|
|
227
277
|
| --- | --- |
|
|
228
|
-
| `createClient({ endpoint, sessionId, token, recording, canvasBackground, avatarBackground, recordingFps, recordingBitrate, rtmpResolution, rtmpFps, rtmpBitrate, rtmpKeyframeInterval, iceServers, publishLimits, ...callbacks })` | Prepares the client. `sessionId` and `token` are required. `endpoint` defaults to `http://localhost:8080`. `recording` defaults to **false**. Optional `canvasBackground` (CSS color or gradient, default `#0A0036`; `recordingCanvasBackground` is the older name) and `avatarBackground` (camera-off tile gradient or list) style both recording and RTMP — see [Stage look](#stage-look-background--avatars). Optional `publishLimits: { cameraBps, screenBps }` overrides portal join caps. Frame rates are independent: `recordingFps` (default **15**) and `rtmpFps` (default **30**), each 1–60. `recordingBitrate` (default 4.5 Mbps) and `rtmpBitrate` (default and max 2.5 Mbps) are in bps. RTMP output quality: `rtmpResolution` (preset `480p`/`540p`/`720p`/`1080p` or any custom `"WxH"` / `{ width, height }`, default **1080p**), `rtmpKeyframeInterval` (seconds, default **2**) — or group them as `rtmpQuality: { resolution, fps, bitrate, keyframeInterval }`. See [Live stream quality](#live-stream-quality). Optional `videoCodec` (string or ordered list) sets the WebRTC camera / screen codec preference. The default is **`vp8`**, then `h264`, `vp9`, `av1`; the first one the browser and server both support is used. The live (RTMP) stage is always H264. |
|
|
278
|
+
| `createClient({ endpoint, sessionId, token, recording, canvasBackground, avatarBackground, recordingFps, recordingResolution, recordingBitrate, rtmpResolution, rtmpFps, rtmpBitrate, rtmpKeyframeInterval, iceServers, publishLimits, ...callbacks })` | Prepares the client. `sessionId` and `token` are required. `endpoint` defaults to `http://localhost:8080`. `recording` defaults to **false**. Optional `canvasBackground` (CSS color or gradient, default `#0A0036`; `recordingCanvasBackground` is the older name) and `avatarBackground` (camera-off tile gradient or list) style both recording and RTMP — see [Stage look](#stage-look-background--avatars). Optional `publishLimits: { cameraBps, screenBps }` overrides portal join caps. Frame rates are independent: `recordingFps` (default **15**) and `rtmpFps` (default **30**), each 1–60. `recordingResolution` defaults to **1080p** (`1920×1080`); a number `N` (e.g. `2048`) sets the **height** at 16:9 (like 1080p) — see [Recording resolution](#recording-resolution). `recordingBitrate` (default ~4.5 Mbps at 1080p, scales with pixels) and `rtmpBitrate` (default and max 2.5 Mbps) are in bps. RTMP output quality: `rtmpResolution` (preset `480p`/`540p`/`720p`/`1080p` or any custom `"WxH"` / `{ width, height }`, default **1080p**), `rtmpKeyframeInterval` (seconds, default **2**) — or group them as `rtmpQuality: { resolution, fps, bitrate, keyframeInterval }`. See [Live stream quality](#live-stream-quality). Optional `videoCodec` (string or ordered list) sets the WebRTC camera / screen codec preference. The default is **`vp8`**, then `h264`, `vp9`, `av1`; the first one the browser and server both support is used. The live (RTMP) stage is always H264. |
|
|
229
279
|
| `connect()` | Checks the token and joins the session. If recording is enabled for a **host**, recording starts in the background. If the host token has `rtmp: true` and the meeting already has enabled destinations, `startRtmp()` also runs in the background. Join does not wait for either to finish preparing. |
|
|
230
280
|
| `subscribe()` | Starts playing the other people. Call this once after `connect()`. |
|
|
231
281
|
| `startCamera({ cameraId, resolution, track })` | Publishes the camera. Pass `track` to use your own live video track (SDK clones it). |
|
|
@@ -240,11 +290,12 @@ await client.end(); // combines every segment into one file
|
|
|
240
290
|
| `stopCustomStream(identifier)` | Stops that custom stream. |
|
|
241
291
|
| `publish({ cameraId, micId, resolution })` | Turns on the camera and the microphone together. |
|
|
242
292
|
| `stop()` | Turns off the camera and the microphone. The screen share stays on. |
|
|
243
|
-
| `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. |
|
|
293
|
+
| `startRecording({ resolution? })` | Starts recording for this person (or resumes after `stopRecording()`). Optional `resolution` overrides `recordingResolution` for the next segment (same semantics as [Recording resolution](#recording-resolution)). 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. |
|
|
244
294
|
| `stopRecording()` | Pauses recording without saving. Call `startRecording()` again to continue; `end()` still combines all segments into one file. |
|
|
245
295
|
| `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. |
|
|
246
296
|
| `setRecordingStage(people)` | **Required for stage-accurate recording.** Who appears on the recording stage: `[{ id, name, local?, avatarBackground? }]` (max six on canvas). `avatarBackground` overrides that person's camera-off gradient. Avatars + name pills until that peer’s webcam arrives. See [Recording must match the live stage](#recording-must-match-the-live-stage). |
|
|
247
297
|
| `setRecordingFps(fps)` / `getRecordingFps()` | Recording frame rate (1–60). Applies to the next `startRecording()`; a running segment keeps its rate. |
|
|
298
|
+
| `setRecordingResolution(resolution)` / `getRecordingResolution()` | Custom recording output size for the next segment. `1080` → `1920×1080`; `2048` / `"2048p"` → height 2048 at 16:9 (`3640×2048`). See [Recording resolution](#recording-resolution-custom-height). `getRecordingResolution()` returns `{ resolution, width, height }`. |
|
|
248
299
|
| `startRtmp({ destinations? })` | **Go Live** (host / co-host). Streams the stage to every enabled destination. Optional `destinations` are added first. Also runs automatically after `connect()` when the host token has `rtmp: true` and destinations already exist. Throws if the browser cannot encode H264. |
|
|
249
300
|
| `stopRtmp()` | Ends the live stream on every platform. Destinations stay saved so the host can Go Live again. |
|
|
250
301
|
| `addRtmpDestinations(list)` | Adds `[{ platform, streamKey, serverUrl?, label? }]`. `platform` is `youtube`, `twitch`, `facebook`, or `custom` (custom needs `serverUrl`). Works before or during a live stream. |
|
|
@@ -409,6 +460,7 @@ Canvas is **1280×720**. Video tiles and audio follow these rules:
|
|
|
409
460
|
- 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.
|
|
410
461
|
- The pill is drawn even while the first video frame is still loading (dark tile + name).
|
|
411
462
|
- The large screen / whiteboard pane does **not** get a name pill.
|
|
463
|
+
- **Active speaker:** a cyan ring (same as live `.tile.speaking`) is burned onto the speaking camera or avatar tile. Presenter name-pill chrome stays separate from the speak ring.
|
|
412
464
|
|
|
413
465
|
Use `setRecordingStage([{ id, name, local? }, ...])` so avatar tiles and name pills match the live stage. Without it, only live tracks appear (plus a single host placeholder when nobody is publishing).
|
|
414
466
|
|
|
@@ -561,6 +613,7 @@ const client = createClient({
|
|
|
561
613
|
rtmpBitrate: 2_500_000, // bps, max 2 500 000 (2500 kbps)
|
|
562
614
|
rtmpKeyframeInterval: 2, // seconds (default 2)
|
|
563
615
|
recordingFps: 15, // independent of rtmpFps
|
|
616
|
+
recordingResolution: 2048, // optional custom height (3640×2048); default 1080p
|
|
564
617
|
onRtmpStatus: (status) => {
|
|
565
618
|
// status.enabled — show Live for managers once the room allows it
|
|
566
619
|
// status.live — true when platforms are receiving
|
|
@@ -691,6 +744,7 @@ RTMP server (one VM runs many meetings)
|
|
|
691
744
|
| Option | Default | Used for |
|
|
692
745
|
| --- | --- | --- |
|
|
693
746
|
| `recordingFps` | `15` | MediaRecorder recording canvas |
|
|
747
|
+
| `recordingResolution` | `1080` (`1920×1080`) | Custom MediaRecorder size; number `N` / `"Np"` = **height** at 16:9 (`2048` → `3640×2048`). See [Recording resolution](#recording-resolution-custom-height). |
|
|
694
748
|
| `rtmpFps` | `30` | Live stream canvas and H264 encode |
|
|
695
749
|
|
|
696
750
|
Separate canvases — each rate is independent. Live compositor window events: `mediascale:live-mode` / `mediascale:live-error`.
|
|
@@ -736,4 +790,4 @@ Open http://localhost:3200. The page asks your Next.js server for a token, then
|
|
|
736
790
|
|
|
737
791
|
Set `SDK_SECRET` in the environment before `npm run dev`. `MEDASCALE_ENDPOINT` is optional. The sample uses it when it is set, and otherwise uses `http://localhost:8080`.
|
|
738
792
|
|
|
739
|
-
With the full local stack (`deploy/local`), the sample is also served behind the gateway at `/meet`. Stream Control → Webinar can mint host/invite links with `recording` and `rtmp` from those toggles. When RTMP destinations were saved at create, the host page **starts streaming on join**; the **LIVE** button stays available to end, restart, or edit destinations (`sample/app/live-panel.js`). `?recordingFps=15&rtmpFps=30` on the meet URL overrides
|
|
793
|
+
With the full local stack (`deploy/local`), the sample is also served behind the gateway at `/meet`. Stream Control → Webinar can mint host/invite links with `recording` and `rtmp` from those toggles. When RTMP destinations were saved at create, the host page **starts streaming on join**; the **LIVE** button stays available to end, restart, or edit destinations (`sample/app/live-panel.js`). `?recordingFps=15&rtmpFps=30&recordingResolution=2048` on the meet URL overrides recording/live quality for testing. Active-speaker glow in the downloaded WebM needs no extra sample code — portal `activeSpeaker` is forwarded into the recorder automatically.
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
CanvasRecorder,
|
|
5
5
|
DEFAULT_RECORDING_FPS,
|
|
6
6
|
clampFps,
|
|
7
|
+
normalizeRecordingResolution,
|
|
7
8
|
normalizeVideoCrop,
|
|
8
9
|
recordingWebinarId,
|
|
9
10
|
resolveRecorderAffinity,
|
|
@@ -202,6 +203,8 @@ export function createClient(options = {}) {
|
|
|
202
203
|
let avatarBackground = normalizeAvatarBackground(options.avatarBackground);
|
|
203
204
|
// Frame rates are independent: recording (MediaRecorder) vs RTMP live output.
|
|
204
205
|
let recordingFps = clampFps(options.recordingFps, DEFAULT_RECORDING_FPS);
|
|
206
|
+
/** Long-edge / 1080p preset for the next recording segment (default 1080p → 1920×1080). */
|
|
207
|
+
let recordingResolution = options.recordingResolution != null ? options.recordingResolution : 1080;
|
|
205
208
|
const recordingBitrate = Number(options.recordingBitrate) > 0 ? Math.round(Number(options.recordingBitrate)) : undefined;
|
|
206
209
|
// RTMP output quality. Flat options or `rtmpQuality: { resolution, fps, bitrate, keyframeInterval }`.
|
|
207
210
|
const rtmpQualityOption = options.rtmpQuality && typeof options.rtmpQuality === "object" ? options.rtmpQuality : {};
|
|
@@ -809,12 +812,15 @@ export function createClient(options = {}) {
|
|
|
809
812
|
socket.on("activeSpeaker", (payload = {}) => {
|
|
810
813
|
if (closed) return;
|
|
811
814
|
const peerId = payload.peerId || null;
|
|
815
|
+
const local = Boolean(peerId && selfPeerId && peerId === selfPeerId);
|
|
812
816
|
onActiveSpeaker({
|
|
813
817
|
peerId,
|
|
814
818
|
displayName: payload.displayName || null,
|
|
815
819
|
producerId: payload.producerId || null,
|
|
816
|
-
local
|
|
820
|
+
local,
|
|
817
821
|
});
|
|
822
|
+
// Burn the same active-speaker highlight into the recording (no app API).
|
|
823
|
+
recorder?.setActiveSpeaker?.({ peerId, local });
|
|
818
824
|
});
|
|
819
825
|
socket.on("userJoined", (user) => {
|
|
820
826
|
if (closed) return;
|
|
@@ -1293,6 +1299,7 @@ export function createClient(options = {}) {
|
|
|
1293
1299
|
recorderPeer: peer,
|
|
1294
1300
|
fps: recordingFps,
|
|
1295
1301
|
bitrate: recordingBitrate,
|
|
1302
|
+
resolution: recordingResolution,
|
|
1296
1303
|
// Chunks start immediately; empty stage uses the same host placeholder as live UI.
|
|
1297
1304
|
onCaptureChange: () => notifyRecording(next),
|
|
1298
1305
|
onFailure: (error) => {
|
|
@@ -1330,8 +1337,11 @@ export function createClient(options = {}) {
|
|
|
1330
1337
|
throw lastError instanceof Error ? lastError : new Error(String(lastError || "Could not start recording"));
|
|
1331
1338
|
}
|
|
1332
1339
|
|
|
1333
|
-
async function startRecording() {
|
|
1340
|
+
async function startRecording(opts = {}) {
|
|
1334
1341
|
if (closed) throw new Error("The session has ended");
|
|
1342
|
+
if (opts && typeof opts === "object" && opts.resolution != null) {
|
|
1343
|
+
recordingResolution = opts.resolution;
|
|
1344
|
+
}
|
|
1335
1345
|
if (!sendTransport) await connect();
|
|
1336
1346
|
if (closed) return;
|
|
1337
1347
|
if (recorder) {
|
|
@@ -1792,6 +1802,24 @@ export function createClient(options = {}) {
|
|
|
1792
1802
|
return recordingFps;
|
|
1793
1803
|
}
|
|
1794
1804
|
|
|
1805
|
+
/**
|
|
1806
|
+
* Recording output size for the next segment start.
|
|
1807
|
+
* `1080` / `"1080p"` → 1920×1080; number N (e.g. 2048) → height N at 16:9 (≈3644×2048).
|
|
1808
|
+
*/
|
|
1809
|
+
function setRecordingResolution(resolution) {
|
|
1810
|
+
recordingResolution = resolution != null ? resolution : 1080;
|
|
1811
|
+
return getRecordingResolution();
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
function getRecordingResolution() {
|
|
1815
|
+
const out = normalizeRecordingResolution(recordingResolution);
|
|
1816
|
+
return {
|
|
1817
|
+
resolution: recordingResolution,
|
|
1818
|
+
width: out.width,
|
|
1819
|
+
height: out.height,
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1795
1823
|
/** Rebuild the live compositor (new fps / resolution) and swap tracks without leaving the platforms. */
|
|
1796
1824
|
async function restartLiveCompositor() {
|
|
1797
1825
|
if (!live || !liveVideo || !liveAudio) return;
|
|
@@ -1994,6 +2022,8 @@ export function createClient(options = {}) {
|
|
|
1994
2022
|
stopRecording: guard(stopRecording),
|
|
1995
2023
|
setRecordingFps,
|
|
1996
2024
|
getRecordingFps: () => recordingFps,
|
|
2025
|
+
setRecordingResolution,
|
|
2026
|
+
getRecordingResolution,
|
|
1997
2027
|
startRtmp: guard(startRtmp),
|
|
1998
2028
|
stopRtmp: guard(stopRtmp),
|
|
1999
2029
|
getRtmpStatus: guard(getRtmpStatus),
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export { createClient, DEFAULT_VIDEO_CODECS, normalizeVideoCodecs } from "./client.js";
|
|
2
2
|
export { FrameCompositor } from "./record-frame-compositor.js";
|
|
3
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
DEFAULT_RECORDING_FPS,
|
|
5
|
+
normalizeRecordingResolution,
|
|
6
|
+
recordingBitrateForSize,
|
|
7
|
+
stageOutputSize,
|
|
8
|
+
} from "./record.js";
|
|
4
9
|
export {
|
|
5
10
|
avatarBackgroundFor,
|
|
6
11
|
gradientToCss,
|
package/src/record-compositor.js
CHANGED
|
@@ -84,7 +84,7 @@ export async function createWorkerCompositor({ width, height, scale = 1, fps, ba
|
|
|
84
84
|
for (const [key, entry] of owned) if (!keys.has(key)) { release(entry); owned.delete(key); }
|
|
85
85
|
const transfer = [];
|
|
86
86
|
const updates = desired.map((source) => {
|
|
87
|
-
const { key, track, rect, crop, label, accent, radius, muted, fit, fillStyle, placeholder, avatarBackground: avatar } = source;
|
|
87
|
+
const { key, track, rect, crop, label, accent, radius, muted, fit, fillStyle, placeholder, avatarBackground: avatar, speaking } = source;
|
|
88
88
|
const chrome = {
|
|
89
89
|
key,
|
|
90
90
|
rect,
|
|
@@ -97,6 +97,7 @@ export async function createWorkerCompositor({ width, height, scale = 1, fps, ba
|
|
|
97
97
|
...(fillStyle ? { fillStyle } : {}),
|
|
98
98
|
placeholder: Boolean(placeholder),
|
|
99
99
|
avatarBackground: avatar || null,
|
|
100
|
+
speaking: Boolean(speaking),
|
|
100
101
|
};
|
|
101
102
|
const previous = owned.get(key);
|
|
102
103
|
if (previous?.original === track) return chrome;
|
|
@@ -219,6 +219,8 @@ export function roundedRectPath(ctx, x, y, w, h, radius) {
|
|
|
219
219
|
|
|
220
220
|
/** Neon magenta presenter ring — matches the live stage / webinar UI. */
|
|
221
221
|
export const PRESENTER_ACCENT = "#e879f9";
|
|
222
|
+
/** Cyan active-speaker ring — matches live `.tile.speaking` (`rgba(56, 189, 248, …)`). */
|
|
223
|
+
export const SPEAKING_ACCENT = "#38bdf8";
|
|
222
224
|
|
|
223
225
|
/**
|
|
224
226
|
* Bottom-left name label (design): plain white text + soft scrim. No mic / signal icons.
|
|
@@ -267,6 +269,27 @@ export function strokeTileBorder(ctx, x, y, w, h, radius, { accent = false, acce
|
|
|
267
269
|
ctx.restore();
|
|
268
270
|
}
|
|
269
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Active-speaker highlight burned into the recording. Drawn for flush tiles too
|
|
274
|
+
* (TILE_RADIUS = 0) so camera-off avatars match the live cyan ring.
|
|
275
|
+
*/
|
|
276
|
+
export function strokeSpeakingRing(ctx, x, y, w, h, radius = 0, color = SPEAKING_ACCENT) {
|
|
277
|
+
const base = parseCssColor(color) || { r: 56, g: 189, b: 248 };
|
|
278
|
+
ctx.save();
|
|
279
|
+
if (radius > 0) {
|
|
280
|
+
roundedRectPath(ctx, x + 0.5, y + 0.5, w - 1, h - 1, radius);
|
|
281
|
+
} else {
|
|
282
|
+
ctx.beginPath();
|
|
283
|
+
ctx.rect(x + 0.5, y + 0.5, w - 1, h - 1);
|
|
284
|
+
}
|
|
285
|
+
ctx.strokeStyle = cssRgb(base, 0.85);
|
|
286
|
+
ctx.lineWidth = 3;
|
|
287
|
+
ctx.shadowColor = cssRgb(base, 0.55);
|
|
288
|
+
ctx.shadowBlur = 12;
|
|
289
|
+
ctx.stroke();
|
|
290
|
+
ctx.restore();
|
|
291
|
+
}
|
|
292
|
+
|
|
270
293
|
/**
|
|
271
294
|
* Draw a video/image source into a rounded tile + bottom-left name (no mic icons).
|
|
272
295
|
* `fit: "cover"` fills the rect (cameras). `fit: "contain"` letterboxes screenshare.
|
|
@@ -288,6 +311,7 @@ export function paintRoundedTile(ctx, {
|
|
|
288
311
|
fit = "cover",
|
|
289
312
|
placeholder = false,
|
|
290
313
|
avatarBackground = null,
|
|
314
|
+
speaking = false,
|
|
291
315
|
}) {
|
|
292
316
|
const { x, y, w, h } = rect;
|
|
293
317
|
ctx.save();
|
|
@@ -330,6 +354,7 @@ export function paintRoundedTile(ctx, {
|
|
|
330
354
|
}
|
|
331
355
|
ctx.restore();
|
|
332
356
|
if (label) drawNamePill(ctx, x, y, w, h, label, { presenter: accent, muted });
|
|
357
|
+
if (speaking) strokeSpeakingRing(ctx, x, y, w, h, radius);
|
|
333
358
|
}
|
|
334
359
|
|
|
335
360
|
/** Owns at most one input frame per source and one output write. */
|
|
@@ -408,7 +433,7 @@ export class FrameCompositor {
|
|
|
408
433
|
if (!this.active || (!this.dirty && !this.steady && !idleTiles) || this.writing || now - this.lastDraw < this.interval) return;
|
|
409
434
|
this.backdrop.paint(this.ctx, this.width, this.height);
|
|
410
435
|
for (const source of this.sources) {
|
|
411
|
-
const { key, rect, crop, label, accent, radius, muted, fit, fillStyle, placeholder, avatarBackground } = source;
|
|
436
|
+
const { key, rect, crop, label, accent, radius, muted, fit, fillStyle, placeholder, avatarBackground, speaking } = source;
|
|
412
437
|
const frame = this.frames.get(key);
|
|
413
438
|
if (!rect) continue;
|
|
414
439
|
const tileRadius = radius == null ? 0 : radius;
|
|
@@ -422,6 +447,7 @@ export class FrameCompositor {
|
|
|
422
447
|
fit: fit === "contain" ? "contain" : "cover",
|
|
423
448
|
placeholder: Boolean(placeholder),
|
|
424
449
|
avatarBackground: avatarBackground || this.avatarBackground,
|
|
450
|
+
speaking: Boolean(speaking),
|
|
425
451
|
};
|
|
426
452
|
if (!frame) {
|
|
427
453
|
// Screenshare before its first frame: keep the uniform backdrop.
|
package/src/record-worker.js
CHANGED
|
@@ -69,7 +69,7 @@ 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, label, accent, radius, muted, fit, fillStyle, placeholder, avatarBackground }) => ({
|
|
72
|
+
compositor.setSources(data.sources.map(({ key, rect, crop, label, accent, radius, muted, fit, fillStyle, placeholder, avatarBackground, speaking }) => ({
|
|
73
73
|
key,
|
|
74
74
|
rect,
|
|
75
75
|
crop: crop || null,
|
|
@@ -81,6 +81,7 @@ self.onmessage = async ({ data }) => {
|
|
|
81
81
|
...(fillStyle ? { fillStyle } : {}),
|
|
82
82
|
placeholder: Boolean(placeholder),
|
|
83
83
|
avatarBackground: avatarBackground || null,
|
|
84
|
+
speaking: Boolean(speaking),
|
|
84
85
|
})));
|
|
85
86
|
for (const source of data.sources) {
|
|
86
87
|
if (!source.readable && !source.track) continue;
|
package/src/record.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
roundedRectPath,
|
|
8
8
|
fillNameTone,
|
|
9
9
|
drawInitialAvatar,
|
|
10
|
+
strokeSpeakingRing,
|
|
10
11
|
STAGE_BACKGROUND,
|
|
11
12
|
PRESENTER_ACCENT,
|
|
12
13
|
} from "./record-frame-compositor.js";
|
|
@@ -14,6 +15,7 @@ export {
|
|
|
14
15
|
FrameCompositor,
|
|
15
16
|
fillRadialBackground,
|
|
16
17
|
PRESENTER_ACCENT,
|
|
18
|
+
SPEAKING_ACCENT,
|
|
17
19
|
STAGE_BACKGROUND,
|
|
18
20
|
} from "./record-frame-compositor.js";
|
|
19
21
|
|
|
@@ -23,16 +25,24 @@ export {
|
|
|
23
25
|
*/
|
|
24
26
|
const W = 1280;
|
|
25
27
|
const H = 720;
|
|
26
|
-
/**
|
|
28
|
+
/** Default output limits (RTMP + legacy recording): never more pixels than 1080p, long edge ≤ 1920. */
|
|
27
29
|
const MAX_OUTPUT_EDGE = 1920;
|
|
28
30
|
const MAX_OUTPUT_PIXELS = 1920 * 1080;
|
|
29
31
|
const MIN_OUTPUT_EDGE = 160;
|
|
32
|
+
/** Recording resolution long-edge clamp (createClient / startRecording). */
|
|
33
|
+
const MIN_RECORDING_EDGE = 360;
|
|
34
|
+
const MAX_RECORDING_EDGE = 4096;
|
|
35
|
+
/** Reference pixel count for bitrate scaling (1080p). */
|
|
36
|
+
const BASE_OUTPUT_PIXELS = 1920 * 1080;
|
|
30
37
|
|
|
31
38
|
/**
|
|
32
39
|
* Output size for the stage. Accepts `{ width, height }`, or a height (16:9 width derived).
|
|
33
40
|
* Keeps the aspect ratio while clamping to the limits; dimensions are even (H264 needs it).
|
|
41
|
+
* Optional `limits: { maxEdge, maxPixels }` — recording may raise these for 2048 long-edge.
|
|
34
42
|
*/
|
|
35
|
-
export function stageOutputSize(size = H) {
|
|
43
|
+
export function stageOutputSize(size = H, limits = {}) {
|
|
44
|
+
const maxEdge = Number(limits.maxEdge) > 0 ? Number(limits.maxEdge) : MAX_OUTPUT_EDGE;
|
|
45
|
+
const maxPixels = Number(limits.maxPixels) > 0 ? Number(limits.maxPixels) : MAX_OUTPUT_PIXELS;
|
|
36
46
|
let width;
|
|
37
47
|
let height;
|
|
38
48
|
if (size && typeof size === "object") {
|
|
@@ -43,14 +53,48 @@ export function stageOutputSize(size = H) {
|
|
|
43
53
|
}
|
|
44
54
|
if (!Number.isFinite(height) || height <= 0) height = H;
|
|
45
55
|
if (!Number.isFinite(width) || width <= 0) width = (height * W) / H;
|
|
46
|
-
let fit = Math.min(1,
|
|
56
|
+
let fit = Math.min(1, maxEdge / Math.max(width, height), Math.sqrt(maxPixels / (width * height)));
|
|
47
57
|
fit = Math.max(fit, MIN_OUTPUT_EDGE / Math.min(width, height));
|
|
48
58
|
const even = (v) => Math.max(2, Math.round(v / 2) * 2);
|
|
49
|
-
const outW = even(Math.min(
|
|
50
|
-
const outH = even(Math.min(
|
|
59
|
+
const outW = even(Math.min(maxEdge, width * fit));
|
|
60
|
+
const outH = even(Math.min(maxEdge, height * fit));
|
|
51
61
|
const scale = outW / W;
|
|
52
62
|
return { width: outW, height: outH, scale, layoutWidth: W, layoutHeight: outH / scale };
|
|
53
63
|
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Resolve recording output size from `recordingResolution` / `startRecording({ resolution })`.
|
|
67
|
+
* Same “Np” meaning as 720p / 1080p: N is the **height**, width is 16:9.
|
|
68
|
+
* - unset / `1080` / `"1080p"` → 1920×1080
|
|
69
|
+
* - number N (e.g. 2048) → height N at 16:9 (3640×2048), even dims, height clamped 360–4096
|
|
70
|
+
*/
|
|
71
|
+
export function normalizeRecordingResolution(value, fallback = 1080) {
|
|
72
|
+
const as1080p = () => stageOutputSize({ width: 1920, height: 1080 }, {
|
|
73
|
+
maxEdge: 1920,
|
|
74
|
+
maxPixels: 1920 * 1080,
|
|
75
|
+
});
|
|
76
|
+
if (value == null || value === "") {
|
|
77
|
+
return fallback === 1080 || fallback === "1080" || fallback === "1080p"
|
|
78
|
+
? as1080p()
|
|
79
|
+
: normalizeRecordingResolution(fallback, 1080);
|
|
80
|
+
}
|
|
81
|
+
const text = String(value).trim().toLowerCase();
|
|
82
|
+
if (text === "1080" || text === "1080p") return as1080p();
|
|
83
|
+
// "2048p" / "720p" → use the numeric height.
|
|
84
|
+
const pLabel = text.match(/^(\d{3,4})p$/);
|
|
85
|
+
const n = pLabel ? Number(pLabel[1]) : Number(value);
|
|
86
|
+
if (!Number.isFinite(n) || n <= 0) return as1080p();
|
|
87
|
+
if (n === 1080) return as1080p();
|
|
88
|
+
const even = (v) => Math.max(2, Math.round(v / 2) * 2);
|
|
89
|
+
const height = even(Math.max(MIN_RECORDING_EDGE, Math.min(MAX_RECORDING_EDGE, Math.round(n))));
|
|
90
|
+
const width = even((height * 16) / 9);
|
|
91
|
+
const longEdge = Math.max(width, height);
|
|
92
|
+
return stageOutputSize({ width, height }, {
|
|
93
|
+
maxEdge: Math.max(longEdge, MAX_OUTPUT_EDGE),
|
|
94
|
+
maxPixels: Math.max(width * height, BASE_OUTPUT_PIXELS),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
54
98
|
/** Outer margin around the whole layout. */
|
|
55
99
|
const PAD = 28;
|
|
56
100
|
/**
|
|
@@ -74,6 +118,14 @@ const MAX_STAGE_CAMERAS = 6;
|
|
|
74
118
|
const BITRATE = 4_500_000;
|
|
75
119
|
const mime = "video/webm;codecs=vp8,opus";
|
|
76
120
|
|
|
121
|
+
/** VP8 bitrate scaled with output pixels (4.5 Mbps at 1080p). */
|
|
122
|
+
export function recordingBitrateForSize(width, height, override) {
|
|
123
|
+
if (Number(override) > 0) return Math.round(Number(override));
|
|
124
|
+
const pixels = Math.max(1, Number(width) * Number(height));
|
|
125
|
+
const scaled = BITRATE * (pixels / BASE_OUTPUT_PIXELS);
|
|
126
|
+
return Math.max(1_500_000, Math.min(20_000_000, Math.round(scaled)));
|
|
127
|
+
}
|
|
128
|
+
|
|
77
129
|
/** Clamp a configured frame rate to 1–60 (fallback when missing or invalid). */
|
|
78
130
|
export function clampFps(value, fallback = DEFAULT_RECORDING_FPS) {
|
|
79
131
|
const n = Math.round(Number(value));
|
|
@@ -322,9 +374,24 @@ export class CanvasRecorder {
|
|
|
322
374
|
bitrate,
|
|
323
375
|
outputHeight,
|
|
324
376
|
outputSize,
|
|
377
|
+
resolution,
|
|
325
378
|
}) {
|
|
326
379
|
/** Canvas pixel size; layout math stays in design units (1280 wide). */
|
|
327
|
-
|
|
380
|
+
let output;
|
|
381
|
+
if (outputSize && typeof outputSize === "object" && Number(outputSize.width) > 0 && Number(outputSize.height) > 0) {
|
|
382
|
+
// Live / explicit size (already normalized). Allow the requested dims through.
|
|
383
|
+
const reqW = Number(outputSize.width);
|
|
384
|
+
const reqH = Number(outputSize.height);
|
|
385
|
+
output = stageOutputSize({ width: reqW, height: reqH }, {
|
|
386
|
+
maxEdge: Math.max(reqW, reqH, MAX_OUTPUT_EDGE),
|
|
387
|
+
maxPixels: Math.max(reqW * reqH, MAX_OUTPUT_PIXELS),
|
|
388
|
+
});
|
|
389
|
+
} else if (resolution != null || outputHeight != null) {
|
|
390
|
+
output = normalizeRecordingResolution(resolution ?? outputHeight);
|
|
391
|
+
} else {
|
|
392
|
+
// Recording default: 1080p (1920×1080).
|
|
393
|
+
output = normalizeRecordingResolution(1080);
|
|
394
|
+
}
|
|
328
395
|
this.outputWidth = output.width;
|
|
329
396
|
this.outputHeight = output.height;
|
|
330
397
|
this.outputScale = output.scale;
|
|
@@ -332,7 +399,7 @@ export class CanvasRecorder {
|
|
|
332
399
|
this.layoutHeight = output.layoutHeight;
|
|
333
400
|
/** Compositor + capture frame rate (recording and live output can differ). */
|
|
334
401
|
this.fps = clampFps(fps);
|
|
335
|
-
this.bitrate =
|
|
402
|
+
this.bitrate = recordingBitrateForSize(this.outputWidth, this.outputHeight, bitrate);
|
|
336
403
|
/** Window event prefix: "recording" here, "live" for the RTMP compositor. */
|
|
337
404
|
this.eventPrefix = "recording";
|
|
338
405
|
/** Worker compositor emits frames only on change unless steady (live output sets this). */
|
|
@@ -346,6 +413,9 @@ export class CanvasRecorder {
|
|
|
346
413
|
if (this.recorderPeer) writeStoredRecorderPeer(this.webinarId, this.recorderPeer);
|
|
347
414
|
/** @type {{ id: string, name: string, local?: boolean }[] | null} */
|
|
348
415
|
this.stagePeople = null;
|
|
416
|
+
/** Active speaker from portal → cyan ring on matching camera / avatar tile. */
|
|
417
|
+
this.speakingPeerId = null;
|
|
418
|
+
this.speakingLocal = false;
|
|
349
419
|
this.token = token || "";
|
|
350
420
|
this.selfName = String(selfName || "Host").slice(0, 40);
|
|
351
421
|
/** Color or gradient spec (string / object) for the stage backdrop. */
|
|
@@ -529,6 +599,28 @@ export class CanvasRecorder {
|
|
|
529
599
|
if (this.prepared) this.retile();
|
|
530
600
|
}
|
|
531
601
|
|
|
602
|
+
/**
|
|
603
|
+
* Portal activeSpeaker → cyan speak ring on the matching camera / avatar tile.
|
|
604
|
+
* Pass `{ peerId: null }` (or omit peerId) to clear.
|
|
605
|
+
*/
|
|
606
|
+
setActiveSpeaker({ peerId = null, local = false } = {}) {
|
|
607
|
+
const nextPeer = peerId ? String(peerId) : null;
|
|
608
|
+
const nextLocal = Boolean(local);
|
|
609
|
+
if (this.speakingPeerId === nextPeer && this.speakingLocal === nextLocal) return;
|
|
610
|
+
this.speakingPeerId = nextPeer;
|
|
611
|
+
this.speakingLocal = nextLocal;
|
|
612
|
+
if (this.prepared) this.retile();
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** True when this camera / avatar slot matches the current active speaker. */
|
|
616
|
+
isSpeakingSlot(slot) {
|
|
617
|
+
if (!slot || slot.kind === "screen") return false;
|
|
618
|
+
if (!this.speakingPeerId && !this.speakingLocal) return false;
|
|
619
|
+
if (slot.isLocal) return this.speakingLocal;
|
|
620
|
+
if (!this.speakingPeerId) return false;
|
|
621
|
+
return String(slot.participantKey || "") === this.speakingPeerId;
|
|
622
|
+
}
|
|
623
|
+
|
|
532
624
|
updateCapture() {
|
|
533
625
|
const run = this.captureGate.then(async () => {
|
|
534
626
|
if (this.finishing || !this.prepared) return;
|
|
@@ -927,7 +1019,7 @@ export class CanvasRecorder {
|
|
|
927
1019
|
});
|
|
928
1020
|
}
|
|
929
1021
|
}
|
|
930
|
-
// Attach mic / presenter chrome onto camera slots for both compositor paths.
|
|
1022
|
+
// Attach mic / presenter / speaking chrome onto camera slots for both compositor paths.
|
|
931
1023
|
chosen = chosen.map((slot) => {
|
|
932
1024
|
const label = resolveTileLabel(slot, this.selfName);
|
|
933
1025
|
return {
|
|
@@ -935,6 +1027,7 @@ export class CanvasRecorder {
|
|
|
935
1027
|
displayName: label,
|
|
936
1028
|
micMuted: !hasLiveMic(slot, mics),
|
|
937
1029
|
presenter: isPresenterSlot(slot, label),
|
|
1030
|
+
speaking: this.isSpeakingSlot(slot),
|
|
938
1031
|
// Resolved per tile so the worker gets a single spec (also used before the first frame).
|
|
939
1032
|
avatarBackground: slot.avatarBackground || avatarBackgroundFor(label, this.avatarBackground),
|
|
940
1033
|
};
|
|
@@ -955,6 +1048,7 @@ export class CanvasRecorder {
|
|
|
955
1048
|
fit: "contain",
|
|
956
1049
|
radius: layout.screen?.radius ?? SCREEN_RADIUS,
|
|
957
1050
|
placeholder: false,
|
|
1051
|
+
speaking: false,
|
|
958
1052
|
}] : []),
|
|
959
1053
|
...chosen.map((slot, index) => {
|
|
960
1054
|
const rect = layout.cameras[index];
|
|
@@ -970,6 +1064,7 @@ export class CanvasRecorder {
|
|
|
970
1064
|
fit: "cover",
|
|
971
1065
|
placeholder: Boolean(slot.placeholder),
|
|
972
1066
|
avatarBackground: slot.avatarBackground,
|
|
1067
|
+
speaking: Boolean(slot.speaking),
|
|
973
1068
|
};
|
|
974
1069
|
}),
|
|
975
1070
|
]);
|
|
@@ -1082,12 +1177,14 @@ export class CanvasRecorder {
|
|
|
1082
1177
|
if (!rect) return;
|
|
1083
1178
|
const label = resolveTileLabel(slot, this.selfName);
|
|
1084
1179
|
const radius = rect.radius ?? TILE_RADIUS;
|
|
1180
|
+
const speaking = Boolean(slot.speaking);
|
|
1085
1181
|
if (slot.placeholder) {
|
|
1086
1182
|
drawStagePlaceholder(this.ctx, rect.x, rect.y, rect.w, rect.h, label, false, STAGE_BACKGROUND, {
|
|
1087
1183
|
chrome: true,
|
|
1088
1184
|
radius,
|
|
1089
1185
|
muted: false,
|
|
1090
1186
|
avatarBackground: slot.avatarBackground,
|
|
1187
|
+
speaking,
|
|
1091
1188
|
});
|
|
1092
1189
|
return;
|
|
1093
1190
|
}
|
|
@@ -1098,6 +1195,7 @@ export class CanvasRecorder {
|
|
|
1098
1195
|
radius,
|
|
1099
1196
|
muted: false,
|
|
1100
1197
|
avatarBackground: slot.avatarBackground,
|
|
1198
|
+
speaking,
|
|
1101
1199
|
});
|
|
1102
1200
|
});
|
|
1103
1201
|
this.capture?.requestFrame();
|
|
@@ -1285,6 +1383,7 @@ function drawStagePlaceholder(ctx, x, y, w, h, name, _accent = false, _accentCol
|
|
|
1285
1383
|
ctx.restore();
|
|
1286
1384
|
if (!chrome) return;
|
|
1287
1385
|
drawNamePill(ctx, x, y, w, h, name, {});
|
|
1386
|
+
if (options.speaking) strokeSpeakingRing(ctx, x, y, w, h, corner);
|
|
1288
1387
|
}
|
|
1289
1388
|
|
|
1290
1389
|
function paint(ctx, video, rect, crop, options = {}) {
|
|
@@ -1293,6 +1392,7 @@ function paint(ctx, video, rect, crop, options = {}) {
|
|
|
1293
1392
|
const accentColor = options.accentColor || PRESENTER_ACCENT;
|
|
1294
1393
|
const radius = options.radius ?? TILE_RADIUS;
|
|
1295
1394
|
const muted = Boolean(options.muted);
|
|
1395
|
+
const speaking = Boolean(options.speaking);
|
|
1296
1396
|
const fit = options.fit === "contain" ? "contain" : "cover";
|
|
1297
1397
|
const fillStyle = options.fillStyle || STAGE_BACKGROUND;
|
|
1298
1398
|
if (!video || video.readyState < 2 || !video.videoWidth) {
|
|
@@ -1312,6 +1412,7 @@ function paint(ctx, video, rect, crop, options = {}) {
|
|
|
1312
1412
|
fillStyle,
|
|
1313
1413
|
placeholder: true,
|
|
1314
1414
|
avatarBackground: options.avatarBackground || null,
|
|
1415
|
+
speaking,
|
|
1315
1416
|
});
|
|
1316
1417
|
return;
|
|
1317
1418
|
}
|
|
@@ -1342,6 +1443,7 @@ function paint(ctx, video, rect, crop, options = {}) {
|
|
|
1342
1443
|
muted,
|
|
1343
1444
|
fit,
|
|
1344
1445
|
fillStyle,
|
|
1446
|
+
speaking,
|
|
1345
1447
|
});
|
|
1346
1448
|
}
|
|
1347
1449
|
|