# Connection Provider

TypeScript source: `providers/ConnectionProvider.tsx`

## Components

### ConnectionProvider

Source: `providers/ConnectionProvider.tsx:83`

```ts
React.FC<ConnectionProviderProps>
```

Creates and provides a DepthAI connection based on data provider connection settings.

#### Remarks

This provider reads transport settings from DataProvider, delegates connection creation to useCreateConnection, and wraps children
with the visualizer connection context used by stream panels.

#### Example

```tsx
<ConnectionProvider activeServices={[]}>{children}</ConnectionProvider>
```

## Types

### ConnectionProviderProps

Source: `providers/ConnectionProvider.tsx:38`

```ts
React.PropsWithChildren<{ activeServices: DAIService[]; defaultTopics?: string[]; messageHandlerVersion?: MessageHandlerVersion; tokenRefresh?: TokenRefreshHandler; withDebugLogs?: boolean }>
```

Props for the DepthAI connection provider.

#### Members

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `activeServices` | `DAIService[]` | `[]` | DepthAI service names polled while the connection is alive. |
| `defaultTopics?` | `string[]` | | Stream topics opened automatically after connection.<br />Remarks: `undefined` preserves the
connection/backend default topic behavior. |
| `messageHandlerVersion?` | `MessageHandlerVersion` | | Backend message handling protocol expected by the visualizer connection.
|
| `tokenRefresh?` | `TokenRefreshHandler` | `false` | Controls how refreshed WebRTC tokens are propagated to the host application.
|
| `withDebugLogs?` | `boolean` | `false` | Enables verbose connection logging. |

## Functions

### useDaiConnection

Source: `providers/ConnectionProvider.tsx:118`

```ts
() => ConnectionData
```

Returns the current DepthAI connection context.

#### Remarks

Outside ConnectionProvider, this hook returns the disconnected default context.

## Constants

### ConnectionContext

Source: `providers/ConnectionProvider.tsx:19`

```ts
Context<ConnectionData>
```

React context containing the current DepthAI connection state.

#### Remarks

The default value represents a disconnected, idle provider state and is used only before a matching ConnectionProvider is mounted.
