startWithStreamId method
Last updated: 2026-03-05T10:53:28.864Z
Metrics
LOC: 56
Complexity: 5
Params: 2
Signature
startWithStreamId(streamId, optionsOverride)
Source Code
async startWithStreamId(streamId, optionsOverride) {
if (state !== "inactive") {
log.warn("Recording already active");
return;
}
const opts: ScreenRecordOptions = {
...DEFAULT_SCREEN_RECORD_OPTIONS,
...optionsOverride,
};
const constraints: MediaStreamConstraints = {
audio: opts.includeAudio
? ({
mandatory: {
chromeMediaSource: "tab",
chromeMediaSourceId: streamId,
},
} as MediaTrackConstraints)
: false,
video: {
mandatory: {
chromeMediaSource: "tab",
chromeMediaSourceId: streamId,
},
} as MediaTrackConstraints,
};
try {
stream = await navigator.mediaDevices.getUserMedia(constraints);
chunks = [];
const mimeType = mimeForCodec(opts.codec);
recorder = new MediaRecorder(stream, {
mimeType,
videoBitsPerSecond: opts.videoBitrate,
});
recorder.ondataavailable = (e: BlobEvent) => {
if (e.data.size > 0) chunks.push(e.data);
};
recorder.onerror = (e) => {
log.error("MediaRecorder error:", e);
state = "inactive";
};
recorder.start(1000);
state = "recording";
log.info(`Recording started via streamId, codec=${opts.codec}`);
} catch (err) {
log.error("Failed to start recording from streamId:", err);
state = "inactive";
throw err;
}
},
Dependencies (Outgoing)
| Target | Type |
|---|---|
| mimeForCodec | calls |
No incoming dependencies.