Documentation

    SDK Functions

    Here's a list of all the functions and hooks supported by the Co-Browsing API React Native SDK.

    Imperative API

    All methods are accessed through the default Upscope import or the useUpscope() hook.

    import Upscope from '@upscopeio/react-native-sdk';
    

    Connection Management

    FunctionDescription
    connect()Establishes a WebSocket connection to the servers.
    disconnect()Closes the connection and ends any active session.
    reset(reconnect?: boolean)Resets the connection, clearing all stored identities and visitor data. Pass false to stay disconnected after reset. Defaults to true.

    Session Control

    FunctionDescription
    stopSession()Ends the current screen sharing session.
    requestAgent()Signals that the visitor wants assistance from an agent.
    cancelAgentRequest()Cancels a pending agent request.
    getLookupCode()Requests a 4-digit lookup code from the server. Access the code via the useLookupCode() hook or lookupCodeChanged event.
    sendCustomMessage(message: string)Sends a custom text or JSON message to the agent (max 5000 characters).

    State

    FunctionReturn TypeDescription
    getShortId()PromiseThe visitor's unique short ID assigned by the server.
    getWatchLink()PromiseThe full URL where agents can view the session (https://upscope.com/w/{shortId}).

    Visitor Identification

    Use updateConnection() to set or update visitor identity:

    Upscope.updateConnection({
      uniqueId: 'user-123',
      callName: 'John Smith',
      tags: ['#VIP'],
      identities: ['John Smith', 'john@example.com'],
      metadata: { plan: 'enterprise', region: 'US' },
    });
    

    Only provided fields are updated. Omit a field to keep its existing value.

    React Hooks

    All hooks are reactive — components re-render automatically when the underlying state changes.

    import {
      useConnectionState,
      useSessionState,
      useShortId,
      useLookupCode,
      useUpscope,
    } from '@upscopeio/react-native-sdk';
    

    `useConnectionState()`

    Returns the current connection state.

    const connectionState = useConnectionState();
    // "inactive" | "connecting" | "connected" | "reconnecting" | "error"
    

    `useSessionState()`

    Returns the current session state.

    const sessionState = useSessionState();
    // "inactive" | "pendingRequest" | "active" | "paused" | "ended"
    

    `useShortId()`

    Returns the visitor's short ID, or null if not yet assigned.

    const shortId = useShortId();
    

    `useLookupCode()`

    Returns the current lookup code, or null if not yet generated.

    const lookupCode = useLookupCode();
    

    `useUpscope()`

    Returns a stable object of imperative action methods. Safe to use as a dependency in useCallback / useEffect.

    const {
      connect,
      disconnect,
      stopSession,
      requestAgent,
      cancelAgentRequest,
      sendCustomMessage,
      getLookupCode,
      reset,
    } = useUpscope();
    

    Masking

    Hide sensitive content from agents during screen sharing using the UpscopeMasked component.

    import { UpscopeMasked } from '@upscopeio/react-native-sdk';
    
    <UpscopeMasked>
      <TextInput secureTextEntry placeholder="Credit Card Number" />
    </UpscopeMasked>
    

    UpscopeMasked accepts all standard View props and replaces the wrapped region with a black rectangle in the agent's view. The user sees the real content as normal.