# Type Alias: NablaConnectClient

> **NablaConnectClient** = `object` & `EventTarget`

A client for one Connect iframe, bound to one iframe load. It is an `EventTarget`: see [NablaConnectEventMap](/connect/sdk/reference/type-aliases/NablaConnectEventMap.md).

## Type Declaration[​](#type-declaration "Direct link to Type Declaration")

### addEventListener[​](#addeventlistener "Direct link to addEventListener")

> **addEventListener**: <`K`>(`type`, `listener`, `options?`) => `void`

Listens to an SDK event.

#### Type Parameters[​](#type-parameters "Direct link to Type Parameters")

##### K[​](#k "Direct link to K")

`K` *extends* keyof [`NablaConnectEventMap`](/connect/sdk/reference/type-aliases/NablaConnectEventMap.md)

#### Parameters[​](#parameters "Direct link to Parameters")

##### type[​](#type "Direct link to type")

`K`

`stateChanged`, `noteExported`, `patientInstructionsExported` or `error`.

##### listener[​](#listener "Direct link to listener")

[`NablaConnectEventListener`](/connect/sdk/reference/type-aliases/NablaConnectEventListener.md)<`K`>

Receives the payload on `event.detail`.

##### options?[​](#options "Direct link to options?")

`boolean` | `AddEventListenerOptions`

As for `EventTarget.addEventListener`.

#### Returns[​](#returns "Direct link to Returns")

`void`

### destroy[​](#destroy "Direct link to destroy")

> **destroy**: () => `void`

Ends the client and rejects every pending call with `DESTROYED`. Idempotent.

#### Returns[​](#returns-1 "Direct link to Returns")

`void`

#### Remarks[​](#remarks "Direct link to Remarks")

Call it before the iframe changes encounter, after NablaConnectClient.waitUntilClosable when the encounter must not lose anything.

### exportNote[​](#exportnote "Direct link to exportNote")

> **exportNote**: () => `Promise`<`void`>

Exports the note, like the Export button.

#### Returns[​](#returns-2 "Direct link to Returns")

`Promise`<`void`>

#### Remarks[​](#remarks-1 "Direct link to Remarks")

Needs `EXPORT_NOTE` in [NablaConnectState.availableActions](/connect/sdk/reference/type-aliases/NablaConnectState.md#availableactions). A failed export rejects with `COMMAND_REJECTED` and the reason `EXPORT_FAILED`.

#### Throws[​](#throws "Direct link to Throws")

[NablaConnectError](/connect/sdk/reference/classes/NablaConnectError.md) with `BUSY` (another command runs, the state is in transition, or the provider is finishing the Nabla onboarding), `INVALID_MESSAGE` (the iframe could not read the command), `COMMAND_REJECTED` (with a `reason`), `TIMEOUT` (after 30 seconds), `CONTEXT_CHANGED`, `DESTROYED` or `UNKNOWN`. Before `ready`, also the error that ends the client: `UNSUPPORTED_VERSION`, `INVALID_ORIGIN` or `TIMEOUT`. After the client ended, the error that ended it.

### getCurrentState[​](#getcurrentstate "Direct link to getCurrentState")

> **getCurrentState**: () => [`NablaConnectState`](/connect/sdk/reference/type-aliases/NablaConnectState.md) | `null`

The latest state.

#### Returns[​](#returns-3 "Direct link to Returns")

[`NablaConnectState`](/connect/sdk/reference/type-aliases/NablaConnectState.md) | `null`

The same object until the next `stateChanged`. `null` until the first state, and once the client has ended.

### ready[​](#ready "Direct link to ready")

> `readonly` **ready**: `Promise`<[`NablaConnectState`](/connect/sdk/reference/type-aliases/NablaConnectState.md)>

The first state, once the iframe has loaded and the handshake is done.

#### Remarks[​](#remarks-2 "Direct link to Remarks")

The wait starts at `create` and lasts 30 seconds.

#### Throws[​](#throws-1 "Direct link to Throws")

[NablaConnectError](/connect/sdk/reference/classes/NablaConnectError.md) with `UNSUPPORTED_VERSION`, `INVALID_ORIGIN`, `CONTEXT_CHANGED`, `UNKNOWN` or `DESTROYED`. The client is then ended: create a new one. Or with `TIMEOUT` when the first state did not come in time: the client is not ended, it keeps listening and reports a late first state on `stateChanged`. Commands called before it reject with `TIMEOUT` too.

### removeEventListener[​](#removeeventlistener "Direct link to removeEventListener")

> **removeEventListener**: <`K`>(`type`, `listener`, `options?`) => `void`

Stops listening to an SDK event.

#### Type Parameters[​](#type-parameters-1 "Direct link to Type Parameters")

##### K[​](#k-1 "Direct link to K")

`K` *extends* keyof [`NablaConnectEventMap`](/connect/sdk/reference/type-aliases/NablaConnectEventMap.md)

#### Parameters[​](#parameters-1 "Direct link to Parameters")

##### type[​](#type-1 "Direct link to type")

`K`

`stateChanged`, `noteExported`, `patientInstructionsExported` or `error`.

##### listener[​](#listener-1 "Direct link to listener")

[`NablaConnectEventListener`](/connect/sdk/reference/type-aliases/NablaConnectEventListener.md)<`K`>

The listener given to `addEventListener`.

##### options?[​](#options-1 "Direct link to options?")

`boolean` | `EventListenerOptions`

As for `EventTarget.removeEventListener`.

#### Returns[​](#returns-4 "Direct link to Returns")

`void`

### startNoteGeneration[​](#startnotegeneration "Direct link to startNoteGeneration")

> **startNoteGeneration**: () => `Promise`<`void`>

Stops the recording if needed, then starts the note generation. From `NOTE_READY`, it generates the note again.

#### Returns[​](#returns-5 "Direct link to Returns")

`Promise`<`void`>

#### Remarks[​](#remarks-3 "Direct link to Remarks")

Needs `GENERATE_NOTE` in [NablaConnectState.availableActions](/connect/sdk/reference/type-aliases/NablaConnectState.md#availableactions). It resolves once the generation has started. The generation ends on `stateChanged`, with `NOTE_READY` or with `reason` set to `NOTE_GENERATION_FAILED`.

#### Throws[​](#throws-2 "Direct link to Throws")

[NablaConnectError](/connect/sdk/reference/classes/NablaConnectError.md) with `BUSY` (another command runs, the state is in transition, or the provider is finishing the Nabla onboarding), `INVALID_MESSAGE` (the iframe could not read the command), `COMMAND_REJECTED` (with a `reason`), `TIMEOUT` (after 30 seconds), `CONTEXT_CHANGED`, `DESTROYED` or `UNKNOWN`. Before `ready`, also the error that ends the client: `UNSUPPORTED_VERSION`, `INVALID_ORIGIN` or `TIMEOUT`. After the client ended, the error that ended it.

### startRecording[​](#startrecording "Direct link to startRecording")

> **startRecording**: () => `Promise`<`void`>

Starts the recording, or resumes it from `PAUSED` or `NOTE_READY`.

#### Returns[​](#returns-6 "Direct link to Returns")

`Promise`<`void`>

#### Remarks[​](#remarks-4 "Direct link to Remarks")

Needs `START_RECORDING` in [NablaConnectState.availableActions](/connect/sdk/reference/type-aliases/NablaConnectState.md#availableactions).

#### Throws[​](#throws-3 "Direct link to Throws")

[NablaConnectError](/connect/sdk/reference/classes/NablaConnectError.md) with `BUSY` (another command runs, the state is in transition, or the provider is finishing the Nabla onboarding), `INVALID_MESSAGE` (the iframe could not read the command), `COMMAND_REJECTED` (with a `reason`), `TIMEOUT` (after 30 seconds), `CONTEXT_CHANGED`, `DESTROYED` or `UNKNOWN`. Before `ready`, also the error that ends the client: `UNSUPPORTED_VERSION`, `INVALID_ORIGIN` or `TIMEOUT`. After the client ended, the error that ended it.

### stopRecording[​](#stoprecording "Direct link to stopRecording")

> **stopRecording**: () => `Promise`<`void`>

Stops the recording, like Pause in the Nabla UI.

#### Returns[​](#returns-7 "Direct link to Returns")

`Promise`<`void`>

#### Remarks[​](#remarks-5 "Direct link to Remarks")

Needs `STOP_RECORDING` in [NablaConnectState.availableActions](/connect/sdk/reference/type-aliases/NablaConnectState.md#availableactions). Accepted without effect when nothing is recording, so repeating it is safe.

#### Throws[​](#throws-4 "Direct link to Throws")

[NablaConnectError](/connect/sdk/reference/classes/NablaConnectError.md) with `BUSY` (another command runs, the state is in transition, or the provider is finishing the Nabla onboarding), `INVALID_MESSAGE` (the iframe could not read the command), `COMMAND_REJECTED` (with a `reason`), `TIMEOUT` (after 30 seconds), `CONTEXT_CHANGED`, `DESTROYED` or `UNKNOWN`. Before `ready`, also the error that ends the client: `UNSUPPORTED_VERSION`, `INVALID_ORIGIN` or `TIMEOUT`. After the client ended, the error that ended it.

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

> **waitUntilClosable**: () => `Promise`<`void`>

Waits until [NablaConnectState.canBeClosed](/connect/sdk/reference/type-aliases/NablaConnectState.md#canbeclosed) is `true`, at once if it already is. It has no timeout.

#### Returns[​](#returns-8 "Direct link to Returns")

`Promise`<`void`>

#### Throws[​](#throws-5 "Direct link to Throws")

[NablaConnectError](/connect/sdk/reference/classes/NablaConnectError.md): the error that ended the client, like `DESTROYED`, `CONTEXT_CHANGED` or the rejection of `ready`.

## Remarks[​](#remarks-6 "Direct link to Remarks")

No method throws. Failures arrive as rejected promises or on the `error` event, and an unexpected failure inside the SDK is an `UNKNOWN` error that leaves the client running.

A command resolves once the iframe has run it, and its effect arrives on `stateChanged`. One command runs at a time, and a command called before `ready` waits for it. Every command rejects with a [NablaConnectError](/connect/sdk/reference/classes/NablaConnectError.md):

* `BUSY`: another command is running, the iframe is changing state, or the provider is finishing the Nabla onboarding.
* `COMMAND_REJECTED`: the iframe refused or failed it. See [NablaConnectError.reason](/connect/sdk/reference/classes/NablaConnectError.md#reason).
* `INVALID_MESSAGE` or `UNKNOWN`: the iframe could not read it, the SDK could not send it, or this SDK could not read the answer.
* `TIMEOUT`: no answer within 30 seconds.
* The error that ended the client, like `DESTROYED`, `CONTEXT_CHANGED` or the rejection of `ready`.
