# @ovok/native/socket

Canonical page: https://docs.ovok.com/native-sdk/reference/socket

Realtime socket provider and context.

Import from `@ovok/native/socket`.

## Components [#components]

### SocketProvider() [#socketprovider]

```ts
function SocketProvider(__namedParameters): Element;
```

Connects a Socket.IO client authenticated with the current session and shares it with descendants.

#### Parameters [#parameters]

| Parameter | Type |
| ------ | ------ |
| `__namedParameters` | `SocketProviderProps` |

#### Returns [#returns]

`Element`

## Hooks [#hooks]

### useAiEventListener() [#useaieventlistener]

```ts
function useAiEventListener(): object;
```

Subscribes to AI session events delivered over the socket.

#### Returns [#returns-1]

`subscribe(type, callback)`, which returns a function that removes the subscription.

| Name | Type | Description |
| ------ | ------ | ------ |
| `subscribe()` | (`type`, `callback`) => () => `boolean` \| `undefined` | Registers a callback for an event type; returns a function that unsubscribes it. |

***

### useSocket() [#usesocket]

```ts
function useSocket(): SocketContextType;
```

Returns the socket and its connection state; must be used within a `SocketProvider`.

#### Returns [#returns-2]

[`SocketContextType`](#socketcontexttype)

## Type Aliases [#type-aliases]

### SocketContextType [#socketcontexttype]

```ts
type SocketContextType = object;
```

Value of the socket context.

#### Properties [#properties]

##### isConnected [#isconnected]

```ts
isConnected: boolean;
```

Whether the socket is currently connected.

##### socket [#socket]

```ts
socket: ReturnType<typeof io> | null;
```

The Socket.IO client, or `null` before it is created.

***

### SocketLogPayload [#socketlogpayload]

```ts
type SocketLogPayload = object;
```

Log message received over the socket.

#### Properties [#properties-1]

##### level [#level]

```ts
level: "info" | "warn" | "error";
```

Severity of the message.

##### message [#message]

```ts
message: string;
```

Log text.

## Variables [#variables]

### SocketContext [#socketcontext]

```ts
const SocketContext: Context<SocketContextType | null>;
```

Context holding the socket and its connection state.
