# Real-time sockets

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

Use the socket module only for SDK features that consume Ovok real-time events.
`SocketProvider` exposes a Socket.IO client to descendants; ordinary API requests
still go through the native `Ovok` client.

```tsx
import { OvokProvider } from "@ovok/core/next/react";
import { SocketProvider } from "@ovok/native/socket";

<OvokProvider client={client}>
  <SocketProvider>
    <RealtimeScreen />
  </SocketProvider>
</OvokProvider>
```

Read the connection through `useSocket` and subscribe to AI events with
`useAiEventListener` from within the provider. Keep event handling idempotent because
real-time delivery can repeat or arrive after a screen has changed. Remove any
application-owned listeners when their owning screen unmounts.

The provider disconnects when the session ends or the network goes offline. It
reconnects the same socket, with its listeners, when network access returns. A new
session token replaces the old socket connection. Provide a refresh path for
user-visible features that depend on live events.

## References [#references]

- [SocketProvider](/native-sdk/guide/components/socket/socket-provider/)
- [Socket hooks](/native-sdk/guide/components/socket/hooks/)
- [Socket context and event payload types](/native-sdk/guide/components/socket/types/)
- [Socket module reference](/native-sdk/guide/components/socket/)

## API reference [#api-reference]

Every export of `@ovok/native/socket`, with signatures, props and types, is in the [`socket` API reference](/native-sdk/reference/socket).
