Clips API (BETA)
Record gameplay clips (canvas video with game audio, optional microphone, and optional webcam PiP overlay) and persist them as private UGC entries backed by the Files API.
Quick Start
import RundotGameAPI from '@series-inc/rundot-game-sdk/api'
const { clips } = RundotGameAPI
// 1. Route game audio through Web Audio (once at init)
clips.useGameAudio(myMasterGainNode)
// 2. Start recording (canvas + mic + game audio + webcam PiP)
await clips.startRecordingAsync({ camera: true })
// 3. Stop and persist as private UGC
const clip = await clips.stopRecordingAsync({ title: 'Boss kill', tags: ['win'] })
// clip.blob → Blob for immediate playback
// clip.ugc → private UGC entry (contentType: 'clip')
// clip.fileKey → durable GCS key for later retrieval
// clip.fileUrl → signed URL (~4h TTL, immediate playback only)
// 4. Optionally make it public
await clips.publishClipAsync(clip.ugc.id)How It Works
Clips captures the game's <canvas> via captureStream() and mixes in game audio (from a Web Audio node) and/or microphone audio via MediaRecorder. When camera is enabled, the SDK acquires the webcam and composites a PiP overlay onto an offscreen canvas before encoding. The resulting video is uploaded to the Files API and registered as a private UGC entry with contentType: 'clip'.
Game Audio
Call useGameAudio(node) once at init with your game's master AudioNode (typically a GainNode). Without it, only microphone audio is captured (or silence if mic is also off).
Camera PiP (Reaction Cam)
Add a picture-in-picture webcam overlay so players can record their reactions alongside gameplay. The webcam feed is composited directly into the video (no separate track or post-production). A live preview of the camera is always shown on screen during recording so the player knows they are being captured.
Basic Usage
Custom Layout
Options
camera
boolean | ClipCameraOptions
false
Enable webcam PiP. true uses defaults.
camera.facingMode
'user' | 'environment'
'user'
Which camera to use
camera.pip.position
ClipPipPosition
'top-center'
PiP placement (see positions below)
camera.pip.widthFraction
number
0.25
PiP width as a fraction of the canvas width
onCameraUnavailable
() => void
-
Called if camera access fails (recording continues without PiP)
Positions
'top-left' · 'top-center' · 'top-right' · 'bottom-left' · 'bottom-center' · 'bottom-right'
How It Works
When camera is enabled, the SDK:
Acquires webcam + mic in a single
getUserMediacall (one OS prompt)Creates an offscreen composite canvas (even in auto mode)
Draws the game canvas + a rounded PiP overlay each frame (mirrored only for the front camera; see below)
Feeds the composite into
MediaRecorderInjects a live camera preview (
<video>overlay) on top of the game canvas at the same position/size as the recorded PiP; the player sees exactly what will appear in the final video
The live preview is always visible when the camera is active. It is removed automatically when recording stops or is cancelled.
The PiP corner radius (12px) and the margin from the edge (16px) are fixed; only position and widthFraction are tunable.
Camera Failure Is Non-Fatal
If getUserMedia rejects (no camera, permission denied), the clip records normally without PiP. The onCameraUnavailable callback notifies your game:
Feature Detection
Consent & Permissions
Microphone and camera recording require permission, enforced automatically when either audio.microphone or camera is enabled. The SDK avoids double-prompting by coordinating between the browser/OS permission and the platform consent dialog.
1. Sign-in
Anonymous users cannot record with a microphone or camera. If the user isn't signed in, requestCaptureConsentAsync() routes through the host sign-in flow first.
2. Single Opt-in
The SDK checks the browser's device permission state before deciding whether to show the platform consent dialog:
Internal apps (trusted first-party creator)
Nothing: auto-granted server-side
First game on this origin (device permission not yet granted)
Browser/OS permission prompt only: serves as the single opt-in for that recording. App consent stays undetermined server-side because the host never self-grants on a game's behalf
Device permission already granted (e.g. a later recording, or a second game on the same origin)
Platform consent dialog: the browser won't prompt again, so the host shows its own gate
The host never persists granted from a game-supplied signal (the game cannot self-grant). As a result, the platform consent dialog may appear on a later recording even after the browser already granted device permission. A future enhancement could persist consent from a host-owned signal to make this a true once-only prompt.
3. App Capture Consent (per app, per user)
Consent status is persisted server-side per app per user. Use getCaptureConsentAsync() to check without prompting, and requestCaptureConsentAsync() to trigger the prompt (which itself applies the single opt-in logic above).
4. OS Permission
The browser/OS mic and camera permission is per-origin (not per-game). When both camera and mic are enabled, the SDK makes a single getUserMedia({ video, audio }) call so the user sees one combined prompt. This is separate from app consent; granted app consent does not guarantee OS permission.
Skipping Consent Entirely
If your game doesn't need mic or camera, pass audio: { microphone: false } (and omit camera) to skip all consent checks:
Capture Modes
Auto Mode (default)
Every frame the canvas renders is automatically captured. Use this for most games.
Manual Mode
Call captureFrame() to snapshot the canvas at specific points: useful when HUD elements are composited into the same canvas and you want to capture only the clean game render.
captureFrame() is a no-op when not recording, so it's safe to leave in your render loop.
Auto-Stop
When maxDurationMs elapses, the recorder stops capture and releases the mic immediately, but retains recorded data. The onAutoStop callback fires; the game must still call stopRecordingAsync() to get the blob and persist.
When a recording auto-stops at maxDurationMs, the resulting ClipResult.durationMs is reported as exactly maxDurationMs (not wall-clock time). For a manual stop it's the elapsed wall-clock time since recording started.
Cancel
Abort a recording, discard all data, and release the mic + camera:
Publishing
Clips are private by default. To share with other players:
Other players can browse published clips via UGC. browse returns a paginated UgcBrowseResponse, so read the entries array off the response (don't iterate the response itself):
Stored Clip Data
When a clip is persisted (persist: 'ugc', the default), stopRecordingAsync writes a fixed set of fields into the created UGC entry's data blob. They are merged under any caller-supplied data from ClipPersistOptions, so the fields below always win on collision. A game reading a clip back from UGC can rely on them:
data field
Type
Description
fileKey
string
Durable GCS key for the video. Resolve a fresh playback URL with files.getUrl({ key }).
durationMs
number
Clip length in milliseconds.
width
number
Recorded video width in pixels.
height
number
Recorded video height in pixels.
mimeType
string
Container/codec MIME type the clip was encoded with.
codec
string | undefined
Codec reported by file moderation/transcode metadata (may be absent).
Durable Playback URLs
The fileUrl in ClipResult expires after ~4 hours. For long-term playback, store fileKey and resolve fresh URLs:
API Reference
isSupportedAsync(): Promise<ClipsSupport>
Feature detection. Returns whether the environment supports recording.
getCaptureConsentAsync(): Promise<CaptureConsent>
Check the current app's mic consent status without prompting.
requestCaptureConsentAsync(opts?: { includesCamera?: boolean }): Promise<CaptureConsent>
Request capture consent. The SDK applies the single opt-in logic: internal apps short-circuit to granted; if the device permission state is exactly 'prompt' (the browser will still show its own prompt during recording), returns { status: 'granted', canAskAgain: true } so you don't double-prompt; otherwise shows the platform consent modal. If the device permission is already 'denied', there is no short-circuit; the platform consent dialog is shown and you get back whatever it yields. Pass { includesCamera: true } when the upcoming recording uses the webcam so the correct device permission (camera vs microphone) drives the decision.
useGameAudio(node: AudioNode): void
Register the master Web Audio output for game-audio capture. Call once at init, before recording.
startRecordingAsync(options?: StartClipRecordingOptions): Promise<void>
Begin recording.
captureFrame(): void
Manual mode only. Snapshot the canvas into the recording. No-op when not recording or in auto mode.
stopRecordingAsync(persist?: ClipPersistOptions): Promise<ClipResult>
Stop recording and optionally upload + create UGC.
cancelRecordingAsync(): Promise<void>
Abort recording, discard data, release mic, camera, and all tracks.
publishClipAsync(ugcId: string): Promise<UgcEntry>
Make a private clip public. Sets both the file visibility and UGC isPublic to true.
The entry is fetched first and publishing is refused unless its data.fileKey is a non-empty string, so only entries created by stopRecordingAsync (which writes data.fileKey) are publishable. If the ugc.update fails after the file is flipped public, the SDK best-effort reverts the file back to private so you never leave a public file behind a private entry. Throws:
[clips] UGC entry "<id>" not foundwhen the id resolves to nothing.[clips] UGC entry "<id>" has no data.fileKey; refusing to publish a clip with no accessible filewhendata.fileKeyis absent or empty.
Defaults
fps
30
maxDurationMs
60,000 (60s)
videoBitsPerSecond
2,500,000
audio.microphone
true
audio.gameAudio
true
camera
false
camera.facingMode
'user'
camera.pip.position
'top-center'
camera.pip.widthFraction
0.25
captureMode
'auto'
persist
'ugc'
Error Handling
CAPTURE_CONSENT_DENIED
Mic or camera enabled but app consent denied or user declined sign-in
[clips] a recording is already in progress
Second startRecordingAsync while recording
[clips] recording is not supported in this environment
No MediaRecorder or captureStream
[clips] MediaRecorder is not available in this environment
MediaRecorder / isTypeSupported missing entirely
[clips] no supported MediaRecorder mime type found
MediaRecorder exists but none of the SDK's preferred mp4/webm types are supported and no explicit mimeType was passed
[clips] no <canvas> found...
Canvas selector/element missing
[clips] failed to get 2D context for compositing
The composite canvas getContext('2d') returned null (manual mode or camera recording)
[clips] mimeType "..." is not supported here
Explicit unsupported mime type
[clips] no active recording to stop
stopRecordingAsync called with nothing recording
NotAllowedError (from getUserMedia)
OS mic permission denied (camera denial is non-fatal; see onCameraUnavailable)
[clips] clip is N bytes which exceeds the M-byte upload cap...
Over files.getQuota().maxFileBytes
[clips] upload PUT failed with status N
The blob PUT to the signed upload URL returned a non-2xx status (the partial file is deleted to avoid orphaning quota)
CONTENT_REJECTED
Video moderation flagged content
Supported Formats
The SDK auto-selects the first supported format:
Safari / iOS
video/mp4
Chrome / Android
video/webm
Both are accepted by the Files API and content moderation pipeline.
Limitations
Canvas only: DOM elements outside the canvas are not recorded (the webcam PiP is composited into the canvas recording and shown as a live DOM overlay)
Camera is best-effort: if
getUserMediafails for video, the clip records without PiP (non-fatal); useonCameraUnavailableto reactWeb Audio required for game sound:
<audio>/<video>elements can't be captured directlyLocal testing: recording is unavailable during local Playground testing; verify clips in the RUN.world app
Upload size cap: limited by
files.getQuota().maxFileBytes(typically 200 MB); tunemaxDurationMs,fps, andvideoBitsPerSecondaccordingly
Last updated