Skip to content

Documentation / @debuffjp/share / ClipRecorder

Class: ClipRecorder ​

Defined in: clip.ts:44

Rolling recorder for the last few seconds of a canvas, for "share that moment" buttons.

A WebM file can't be trimmed by dropping its early chunks, so two recorders run staggered by half the window and restart every window. clip() keeps whichever has run longer, so a clip is between half and all of seconds long. That costs two encoders while recording: start it when a run begins, not on load.

ts
const clips = new ClipRecorder(game.canvas);
clips.start();
// later, on a big moment or a "share" button
const clip = await clips.clip();
if (clip) await share({ text: "12x combo!", files: [clipFile(clip, "squish")] });

Constructors ​

Constructor ​

new ClipRecorder(canvas, options?): ClipRecorder

Defined in: clip.ts:54

Parameters ​

canvas ​

HTMLCanvasElement

options? ​

ClipOptions = {}

Returns ​

ClipRecorder

Properties ​

mimeType ​

readonly mimeType: string | undefined

Defined in: clip.ts:45

Accessors ​

recording ​

Get Signature ​

get recording(): boolean

Defined in: clip.ts:72

Returns ​

boolean

Methods ​

clip() ​

clip(): Promise<Clip | undefined>

Defined in: clip.ts:97

The recent past as a video, or undefined if not recording. Recording carries on afterwards.

Returns ​

Promise<Clip | undefined>


start() ​

start(): boolean

Defined in: clip.ts:77

Start recording. Returns false (and does nothing) where clips aren't supported.

Returns ​

boolean


stop() ​

stop(): void

Defined in: clip.ts:87

Stop recording and drop anything buffered.

Returns ​

void


supported() ​

static supported(types?): string | undefined

Defined in: clip.ts:66

First supported clip type, or undefined where this browser can't record a canvas.

Parameters ​

types? ​

string[] = DEFAULT_TYPES

Returns ​

string | undefined