# Class: ClipRecorder

Defined in: [clip.ts:44](https://github.com/debuffjp/debuff/blob/3e11cb8bf00adfd52d063977f9e3328e72e765c5/packages/share/src/clip.ts#L44)

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](https://github.com/debuffjp/debuff/blob/3e11cb8bf00adfd52d063977f9e3328e72e765c5/packages/share/src/clip.ts#L54)

#### Parameters

##### canvas

`HTMLCanvasElement`

##### options?

[`ClipOptions`](../interfaces/ClipOptions.md) = `{}`

#### Returns

`ClipRecorder`

## Properties

### mimeType

> `readonly` **mimeType**: `string` \| `undefined`

Defined in: [clip.ts:45](https://github.com/debuffjp/debuff/blob/3e11cb8bf00adfd52d063977f9e3328e72e765c5/packages/share/src/clip.ts#L45)

## Accessors

### recording

#### Get Signature

> **get** **recording**(): `boolean`

Defined in: [clip.ts:72](https://github.com/debuffjp/debuff/blob/3e11cb8bf00adfd52d063977f9e3328e72e765c5/packages/share/src/clip.ts#L72)

##### Returns

`boolean`

## Methods

### clip()

> **clip**(): `Promise`\<[`Clip`](../interfaces/Clip.md) \| `undefined`\>

Defined in: [clip.ts:97](https://github.com/debuffjp/debuff/blob/3e11cb8bf00adfd52d063977f9e3328e72e765c5/packages/share/src/clip.ts#L97)

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

#### Returns

`Promise`\<[`Clip`](../interfaces/Clip.md) \| `undefined`\>

***

### start()

> **start**(): `boolean`

Defined in: [clip.ts:77](https://github.com/debuffjp/debuff/blob/3e11cb8bf00adfd52d063977f9e3328e72e765c5/packages/share/src/clip.ts#L77)

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

#### Returns

`boolean`

***

### stop()

> **stop**(): `void`

Defined in: [clip.ts:87](https://github.com/debuffjp/debuff/blob/3e11cb8bf00adfd52d063977f9e3328e72e765c5/packages/share/src/clip.ts#L87)

Stop recording and drop anything buffered.

#### Returns

`void`

***

### supported()

> `static` **supported**(`types?`): `string` \| `undefined`

Defined in: [clip.ts:66](https://github.com/debuffjp/debuff/blob/3e11cb8bf00adfd52d063977f9e3328e72e765c5/packages/share/src/clip.ts#L66)

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

#### Parameters

##### types?

`string`[] = `DEFAULT_TYPES`

#### Returns

`string` \| `undefined`
