Documentation

SDK Functions

Here's a list of all the functions and properties supported by the UserView 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.
stopRemoteControl()Revokes the agent's remote control of the device. The session continues; only the agent's ability to interact stops. Safe no-op if no agent has control. Returns Future.
stopFullDeviceSharing()Stops full-device screen sharing and reverts to in-app screen sharing. Safe no-op if not active. Returns Future.
respondToFullDeviceRequest(String requestId, bool accept)Responds to an onFullDeviceRequest event. true allows full-device sharing (proceeds to the system permission prompt); false declines. 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.
onViewerJoinedStreamEmits when an agent starts viewing.
onViewerLeftStreamEmits the viewer ID when an agent stops viewing.
onViewerCountChangedStreamEmits the current count of active viewers.
onCustomMessageReceivedStreamEmits custom messages received from agents.
onErrorStreamEmits SDK-level errors.
remoteControlStateStreamEmits when remote control state changes (inactive, active). See Listening for Events for details.
fullDeviceSharingStateStreamEmits when full-device sharing state changes (inactive, active). See Listening for Events for details.
onFullDeviceRequestStreamFires when an agent requests full-device sharing. Emits a requestId; respond with respondToFullDeviceRequest. See Listening for Events for details.

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.