---
title: Events & Methods
url: https://docs.kaltura.com/docs/embeddable-kaltura-products/express-capture/events
---

## Events & Methods

The runtime object exposes methods to control recording, events to react to it, and a state you can watch.

### Methods

| Method | Description |
|---|---|
| `startRecording()` | Starts a session: shows the 3-second countdown, then starts capturing. It's safe to call before the camera is ready, for example right after the workspace loads: if the countdown ends while the camera is still opening, capture waits at "Get ready" until it is, so it can start later than three seconds. If nothing can be recorded even then, the session ends as a cancel and the recorder shows its error screen. *Coming soon:* in production today, calling it before the camera is ready can produce a recording that captures nothing. |
| `stopRecording()` | Stops the current session. Called during the countdown, it cancels instead and fires no completion event. |
| `mountVisual(options)` | Renders the recorder into an element. Returns an object with an `id`. See [Getting Started](/docs/embeddable-kaltura-products/express-capture/getting-started). |
| `unmountVisual(id)` | Removes a rendered recorder. |

The user can also start and stop recording from the keyboard: **Alt+Shift+R** and **Alt+Shift+S** on Windows and Linux, **Option+Cmd+R** and **Option+Cmd+S** on macOS.

### Events

Subscribe with `.on()`, which returns a function that unsubscribes:

```js
const off = runtime.onRecordingComplete.on((payload) => {
  console.log('Recorded', payload.durationMs, 'ms');
});
// later
off();
```

| Event | Payload | When it fires |
|---|---|---|
| `onRecordingStarted` | none | A session starts: when the countdown begins, not when capture does. |
| `onRecordingComplete` | `{ cameraBlob, screenBlob, durationMs }` | Capture finished. `screenBlob` is null unless the user shared their screen; `cameraBlob` is null when the camera was off. In a screen share, all the audio is on `screenBlob`. `durationMs` excludes time spent paused. See [Screen Sharing](/docs/embeddable-kaltura-products/express-capture/screen-sharing). |
| `onUseThisSelected` | `{ cameraBlob, screenBlob, fileName, durationMs, mimeType, size }` | The user clicked **Use This**. Fires in both save modes, before any upload. `mimeType` is what the browser recorded, for example `video/webm;codecs=vp9`. `size` is the blobs' combined bytes. |
| `onUploadComplete` | `{ entries: [{ entryId, source, role }] }` | The upload to Kaltura finished successfully. Fires **once**, after every entry has uploaded. See below. |
| `onOrientationChanged` | `{ orientation }` | The user picked a different orientation. See below. |

### Upload Results

`onUploadComplete` fires once per upload, after the last entry's media has landed, and lists every entry:

```js
runtime.onUploadComplete.on(({ entries }) => {
  const primary = entries.find((e) => e.role === 'primary');
  console.log('Uploaded as entry', primary.entryId);
});
```

| Field | Description |
|---|---|
| `entryId` | The entry the media landed on: your `recorderConfig.entryId` for the primary entry if you set one, otherwise an entry the recorder created. |
| `source` | `'camera'` or `'screen'`. |
| `role` | `'primary'` for the parent entry, or `'secondary'` for its child. |

- A screen share with the camera on lists two entries: the screen as `primary` (the parent, with the audio) and the camera as `secondary` (its child). It fires only after the camera has finished uploading too. Every other recording lists one `primary` entry.
- `entries` puts the primary first, but read `role` rather than relying on the order.
- It never fires for an upload that failed or was cancelled, including one where the screen uploaded but the camera didn't. It never fires at all under `saveMode: 'non_kaltura'`.
- It fires whether or not `showUploadUI` is on.

:::info Coming soon
In production today, `onUploadComplete` fires **once per entry**, with a single entry's `{ entryId, source }` and no `role`. A screen share with the camera on fires it twice, the screen first, and the first event arrives before the camera upload has finished. To handle both now, read the entries like this:

```js
runtime.onUploadComplete.on((payload) => {
  const entries = payload.entries ?? [payload];
  // ...
});
```
:::

### State

`isRecording` is `true` from `startRecording()` until the session ends or is cancelled:

```js
runtime.isRecording.onChanges((recording) => {
  stopButton.disabled = !recording;
});
```

A cancelled session, whether the user pressed Stop during the countdown or the recording couldn't start, sets `isRecording` back to `false` but fires no event, and `onRecordingComplete` never arrives. To tell a cancel from a finished recording, watch `isRecording`.

### Follow Orientation Changes

The recorder fills the element you give it, so resize that element when the orientation changes:

```js
const container = document.getElementById('recorder');
const SIZE = {
  landscape: { width: '800px', height: '450px' },
  portrait: { width: '450px', height: '800px' },
};

runtime.onOrientationChanged.on(({ orientation }) => {
  Object.assign(container.style, SIZE[orientation]);
});
```

- It fires **on selection, before the camera restarts**, so you can resize in step.
- If the camera then rejects the new orientation, the recorder switches back and **fires again with the previous one**. Always size to the latest event.
- On mount, it fires once only when the starting orientation came from the user's saved choice. For the `landscape` default, or an `orientation` you set in `recorderConfig`, it doesn't fire, since you already know the value. Size the element from that value at first render.
