Skip to main content

Socket hooks

Both hooks require a SocketProvider ancestor. They are intended for real-time features; use the SDK client for request and response API calls.

useSocket​

Returns { socket, isConnected }. socket is null until the first connection is established. Check isConnected before emitting or attaching a listener. Calling the hook outside SocketProvider throws.

const { socket, isConnected } = useSocket();

useAiEventListener​

Returns subscribe(type, callback) for the message event on /ai/session/message. The callback receives the event's content, mode, reference, sender, sent time, and session. subscribe returns an unsubscribe function; call it when an app-owned subscription ends.

import * as React from "react";
import { useAiEventListener } from "@ovok/native/socket";

const { subscribe } = useAiEventListener();

React.useEffect(() => {
return subscribe("message", handleMessage);
}, [subscribe, handleMessage]);

Event consumers should tolerate reconnects and repeated messages. The provider's current network recovery behavior can leave a replacement socket without the original listener set.