# Connection

TypeScript source: `dai-connection/connection.ts`

## Classes

### DAIConnection

Source: `dai-connection/connection.ts:138`

Manages a DepthAI backend connection, stream subscriptions, service polling, and pipeline decoding.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `constructor` | `unknown` |  |
| `alive` | `boolean` | Whether this connection instance should continue processing events and service responses. |
| `connection?` | `VisualizerConnection` | Underlying visualizer connection used by Foxglove-derived panels. |
| `topicsTouched` | `boolean` | Whether topic subscription state was changed explicitly by the user. |
| `canPollService` | `unknown` |  |
| `dispose` | `unknown` |  |
| `fetchService` | `unknown` |  |
| `fetchServiceBlocking` | `unknown` |  |
| `getFakeTopics` | `unknown` |  |
| `handleKeyPress` | `unknown` |  |
| `init` | `unknown` |  |
| `on` | `unknown` |  |
| `postToService` | `unknown` |  |
| `postToServiceRaw` | `unknown` |  |
| `restartTopics` | `unknown` |  |
| `serviceToKind` | `unknown` |  |
| `setActiveServices` | `unknown` |  |
| `setFakeTopics` | `unknown` |  |
| `setOnService` | `unknown` |  |
| `setupConnection` | `unknown` |  |
| `stopTopics` | `unknown` |  |
| `toggleTopic` | `unknown` |  |

## Types

### DaiConnectionEventMap

Source: `dai-connection/connection.ts:91`

Event callbacks emitted by `DAIConnection`.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `close` | `() => void` | Fired after the connection is disposed or closed. |
| `disconnect` | `(error: ErrorEvent) => void` | Fired when the backend disconnects with an error event. |
| `error` | `DeserializationErrorCallback` | Fired when stream message decoding reports an error. |
| `fullPipeline` | `(pipeline: Pipeline | null) => void` | Fired when the full parsed pipeline changes. |
| `open` | `() => void` | Fired when the underlying visualizer connection opens. |
| `pipeline` | `(pipeline: Pipeline | null) => void` | Fired when the default parsed pipeline changes. |
| `pipelineState` | `(pipelineState: PipelineState[] | null) => void` | Fired when live pipeline node state changes. |
| `reconnect` | `() => void` | Fired when the underlying connection begins reconnecting. |
| `topics` | `(topics: Topic[]) => void` | Fired when the advertised stream topic list changes. |

### DAIConnectionInitArgs

Source: `dai-connection/connection.ts:41`

Initialization parameters for a DepthAI connection.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `automaticTokenRefresh?` | `(token: string) => void` | Callback invoked when a refreshed WebRTC token is available. |
| `clientId` | `string` | WebRTC client id. |
| `connectionUrl` | `string` | WebSocket URL or signaling endpoint used by the selected transport. |
| `debugLogs?` | `boolean` | Enables verbose connection logging. |
| `defaultTopics?` | `string[]` | Stream topics opened by default when no explicit stream selection exists. |
| `enabledStreams` | `string[]` | Stream topics that should be subscribed immediately after channel discovery. |
| `isViewer?` | `boolean` | Enables Viewer-specific default stream behavior. |
| `messageHandlerVersion?` | `MessageHandlerVersion` | Backend message handling protocol expected by the connection. |
| `sessionRecovery?` | `WebRtcConfig["sessionRecovery"]` | WebRTC session recovery behavior forwarded to the remote connection
layer. |
| `token` | `string` | WebRTC auth token. |
| `type` | `"ws" | "webrtc"` | Transport used to connect to the DepthAI backend. |

### DAIService

Source: `dai-connection/connection.ts:133`

```ts
keyof typeof DAI_SERVICE_NAME
```

Supported DepthAI backend service key.

### MessageHandlerVersion

Source: `dai-connection/connection.ts:36`

```ts
"v1" | "v2"
```

Backend message handling protocol version used by the visualizer connection.
