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
| Function | Description |
|---|---|
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
| Function | Description |
|---|---|
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
| Method | Return Type | Description |
|---|---|---|
getShortId() | Future | The visitor's unique short ID assigned by the server. |
getWatchLink() | Future | The 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
| Stream | Type | Description |
|---|---|---|
connectionState | Stream | Connection state changes (inactive, connecting, connected, reconnecting, error). |
sessionState | Stream | Session state changes (inactive, pendingRequest, active, paused, ended). |
shortId | Stream | The visitor's short ID. |
lookupCode | Stream | The current lookup code. |
onSessionStarted | Stream | Emits when a session begins. The value is the agent's name, if available. |
onSessionEnded | Stream | Emits the reason when a session ends. |
onObserverJoined | Stream | Emits when an agent starts observing. |
onObserverLeft | Stream | Emits the observer ID when an agent stops observing. |
onObserverCountChanged | Stream | Emits the current count of active observers. |
onCustomMessageReceived | Stream | Emits custom messages received from agents. |
onError | Stream | Emits 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.