Components / Record
@peerkit-dev/record
Screen, camera, and microphone recording that stays in the browser.
Use RecordingController, the <peerkit-record> element, or the React component. Visitors record locally and download the file. No account, API key, or PeerKit session is required, and nothing is uploaded.
JavaScript and Web Components
npm install @peerkit-dev/record-coreReact
npm install @peerkit-dev/record react react-domInteractive demo
PeerKitRecord
Records in this browser. Screen, camera, and microphone media stay on this device — PeerKit does not upload or store it.
Record
Ready00:00
Choose a source, then start. The recording stays in this browser.
Installation
Install @peerkit-dev/record-core for vanilla JavaScript or the <peerkit-record> element. Install @peerkit-dev/record when the page is React. The React package depends on the core package and re-exports RecordingController. No API key, account, or PeerKit session is required.
JavaScript and Web Components
npm install @peerkit-dev/record-core
React
npm install @peerkit-dev/record react react-dom
Vanilla JavaScript
RecordingController is the recorder. subscribe and getSnapshot read status, elapsed time, and the finished file. start, pause, resume, stop, download, and dispose are the actions.
import { RecordingController } from "@peerkit-dev/record-core";
const recorder = new RecordingController();
recorder.subscribe(() => {
const snapshot = recorder.getSnapshot();
console.log(snapshot.status, snapshot.durationMs);
});
await recorder.start({ mode: "screen", microphone: true });
recorder.stop();
recorder.download();Web Component
Import @peerkit-dev/record-core/element to register <peerkit-record>. The same element is available from dist/element.global.js for a plain script tag. Removing the element disposes the recording.
<script type="module"> import "@peerkit-dev/record-core/element"; </script> <peerkit-record></peerkit-record>
React
PeerKitRecord records locally with MediaRecorder. Completed files are downloaded by the visitor. They are not uploaded.
import { PeerKitRecord } from "@peerkit-dev/record";
export function Recorder() {
return (
<PeerKitRecord
defaultSettings={{ mode: "screen", microphone: true }}
onComplete={(recording) => console.log(recording.filename, recording.mimeType)}
onError={(error) => console.error(error.code, error.message)}
/>
);
}Custom interface
usePeerKitRecorder is the React hook for a custom layout. RecordingController is the same recorder without React. Both expose start, pause, resume, stop, download, and cleanup.
import { usePeerKitRecorder } from "@peerkit-dev/record";
export function CameraButton() {
const recorder = usePeerKitRecorder();
return (
<button
type="button"
onClick={() =>
void recorder.start({
mode: "camera",
microphone: true,
systemAudio: false,
webcamOverlay: false,
})
}
>
Record camera
</button>
);
}React props
RecordingController.start takes the same settings object. The custom element accepts them as defaultSettings before it connects.
| Prop | Purpose |
|---|---|
defaultSettings / settings | Mode (screen or camera), microphone, system audio, and camera overlay. |
labels | Override titles, source names, and button copy. |
preferredMimeType | Preferred MediaRecorder mime type when the browser supports it. |
filename | Download name, or a function of the mime type and start time. |
className / style | Root styling. Theme with --peerkit-record-* variables on .pk-record. |
onComplete, onError, onStatusChange, onDownload | Callbacks for the finished blob, failures, status, and download. |
Recording modes
| Mode | What it captures |
|---|---|
screen | Screen, window, or browser tab, chosen in the browser picker. Optional microphone, system or tab audio, and camera overlay. |
camera | Camera video, with the microphone when that option is on. |
Browser limitations
- Requires HTTPS or localhost. Insecure pages cannot record.
- Screen capture works on current desktop Chromium, Firefox, and Safari. iOS and most mobile browsers cannot share the screen.
- The visitor picks screen, window, or tab in the browser dialog. The component cannot force that choice.
- System and tab audio are most reliable in Chromium when the share dialog includes audio. Firefox and Safari often record without it.
- Camera overlay needs canvas capture. It composites a picture-in-picture at 30fps instead of recording the raw screen track.
- Chromium and Firefox usually produce WebM. Safari usually produces MP4. Playback is not guaranteed across browsers.
- Permission denial and the browser Stop sharing control end capture. Tracks and audio nodes are released. A partial recording can still be downloaded.
- The file lives in this tab until download, reset, or navigation. PeerKit never receives it.
Theming
PeerKitRecord ships neutral defaults. Override --peerkit-record-* variables in your CSS. Fonts inherit from the host app unless you set --peerkit-record-font.
.my-recorder {
--peerkit-record-accent: #0d9488;
--peerkit-record-button-bg: #0d9488;
--peerkit-record-button-ink: #ffffff;
--peerkit-record-bg: #f8fafc;
}