# Commands

Commands are methods of the [client](/connect/sdk/reference/type-aliases/NablaConnectClient.md). Each one returns a promise.

## Available commands[​](#available-commands "Direct link to Available commands")

| Method                  | Requires `availableActions` | Effect                                                                                                               |
| ----------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `startRecording()`      | `START_RECORDING`           | Start, or resume from `PAUSED` or `NOTE_READY`.                                                                      |
| `stopRecording()`       | `STOP_RECORDING`            | Same as Pause in the Nabla UI. Accepted without effect when nothing is recording, so repeating it is safe.           |
| `startNoteGeneration()` | `GENERATE_NOTE`             | Stop the recording if needed, then generate the note. From `NOTE_READY`, regenerates it.                             |
| `exportNote()`          | `EXPORT_NOTE`               | Same as the Export button: the [`noteExported`](/connect/sdk/guides/exports.md) event plus your configured callback. |

Offer a command only when the iframe lists it in [`availableActions`](/connect/sdk/guides/encounter-state.md#available-actions).

## When a command resolves[​](#when-a-command-resolves "Direct link to When a command resolves")

A command resolves once the iframe has run it: the recording has started or paused, the note was exported, or the note generation has started. A generation ends on `stateChanged`, with `NOTE_READY` or with `reason` set to `NOTE_GENERATION_FAILED`.

The iframe sends no `stateChanged` while one of your commands runs, and none while nothing changes. The new state follows right after the command resolves. Expect no update until then, and do not take the silence for a crash.

## One command at a time[​](#one-command-at-a-time "Direct link to One command at a time")

A second call while one is pending rejects with [`BUSY`](/connect/sdk/guides/errors.md#busy). Wait for the first one to settle.

## Timeouts[​](#timeouts "Direct link to Timeouts")

A command that gets no answer within 30 seconds rejects with [`TIMEOUT`](/connect/sdk/guides/errors.md#timeout) and the `reason` `NO_RESULT`. This does not mean the command failed. The iframe answers when it is done, and that can take longer: the user may take time to allow the microphone, or the audio may still be uploading. The command can still succeed, and the late answer is dropped. Read `stateChanged` or `getCurrentState()` to learn the outcome.

## Before `ready`[​](#before-ready "Direct link to before-ready")

A command called before `ready` waits for it. If `ready` rejects, the command rejects with the same error.

## `waitUntilClosable()`[​](#waituntilclosable "Direct link to waituntilclosable")

`waitUntilClosable()` is not a command. It resolves once `state.canBeClosed` is `true`, immediately if it already is, so you can wait before you call `destroy()` or tear down the page. It has no timeout, and rejects with `DESTROYED` or `CONTEXT_CHANGED`. See [Leave and switch encounters](/connect/sdk/guides/leave-and-switch.md).
