Documentation

    SDK Functions

    Here's a list of all the functions and properties supported by the Co-Browsing API Flutter SDK.

    All methods are accessed through the Upscope.instance singleton.

    Connection Management

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

    Session Control

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

    State

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

    Visitor Identification

    Use updateConnection() to set or update visitor identity:

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

    Pass null to keep an existing value unchanged. Only non-null parameters are updated.

    Reactive Streams

    Subscribe to state changes using Dart Streams. These work with StreamBuilder for reactive UI updates.

    // Connection state changes
    StreamBuilder<ConnectionState>(
      stream: Upscope.instance.connectionState,
      builder: (context, snapshot) {
        final state = snapshot.data;
        return Text('Connection: ${state?.name ?? "unknown"}');
      },
    );
    
    // Session state changes
    StreamBuilder<SessionState>(
      stream: Upscope.instance.sessionState,
      builder: (context, snapshot) {
        final state = snapshot.data;
        return Text('Session: ${state?.name ?? "unknown"}');
      },
    );
    
    // Short ID changes
    Upscope.instance.shortId.listen((shortId) {
      print('Short ID: $shortId');
    });
    
    // Lookup code changes
    Upscope.instance.lookupCode.listen((code) {
      print('Lookup code: $code');
    });
    

    Available Streams

    StreamTypeDescription
    connectionStateStreamConnection state changes (inactive, connecting, connected, reconnecting, error).
    sessionStateStreamSession state changes (inactive, pendingRequest, active, paused, ended).
    shortIdStreamThe visitor's short ID.
    lookupCodeStreamThe current lookup code.
    onSessionStartedStreamEmits when a session begins. The value is the agent's name, if available.
    onSessionEndedStreamEmits the reason when a session ends.
    onObserverJoinedStreamEmits when an agent starts observing.
    onObserverLeftStreamEmits the observer ID when an agent stops observing.
    onObserverCountChangedStreamEmits the current count of active observers.
    onCustomMessageReceivedStreamEmits custom messages received from agents.
    onErrorStreamEmits SDK-level errors.

    Masking

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

    UpscopeMasked(
      child: TextField(
        decoration: InputDecoration(labelText: 'Credit Card Number'),
        obscureText: true,
      ),
    )
    

    The UpscopeMasked widget automatically tracks its child's position and replaces the region with a black rectangle in the agent's view. The user sees the real content as normal.