Listening for Events
You can listen for SDK events by implementing the UpscopeListener interface and assigning it to the Upscope object:
Upscope.listener = object : UpscopeListener {
// Override methods you need
}
UpscopeListener Interface
All listener methods have default empty implementations, so you only need to override the ones you care about.
Upscope.listener = object : UpscopeListener {
override fun onConnectionStateChanged(state: ConnectionState) {
// Connection state changed
when (state) {
is ConnectionState.Inactive -> println("Inactive")
is ConnectionState.Connecting -> println("Connecting...")
is ConnectionState.Connected -> println("Connected")
is ConnectionState.Reconnecting -> println("Reconnecting...")
is ConnectionState.Error -> println("Error: ${state.error.message}")
}
}
override fun onSessionStarted(agentName: String?) {
println("Session started with ${agentName ?: "an agent"}")
}
override fun onSessionEnded(reason: SessionEndReason) {
when (reason) {
is SessionEndReason.UserStopped -> println("User ended session")
is SessionEndReason.AgentStopped -> println("Agent ended session")
is SessionEndReason.Timeout -> println("Session timed out")
is SessionEndReason.Error -> println("Session error: ${reason.error.message}")
}
}
override fun onCustomMessageReceived(message: String, viewerId: String) {
println("Message from $viewerId: $message")
}
override fun onError(error: UpscopeError) {
println("Error: ${error.code} - ${error.message}")
}
override fun onViewerJoined(viewer: Viewer) {
println("Viewer joined: ${viewer.name ?: viewer.id}")
}
override fun onViewerLeft(viewerId: String) {
println("Viewer left: $viewerId")
}
override fun onViewerCountChanged(count: Int) {
println("Viewers: $count")
}
override fun onRemoteControlStateChanged(state: RemoteControlState) {
when (state) {
RemoteControlState.ACTIVE -> println("Remote control active")
RemoteControlState.INACTIVE -> println("Remote control inactive")
}
}
override fun onFullDeviceSharingStateChanged(state: FullDeviceSharingState) {
when (state) {
FullDeviceSharingState.ACTIVE -> println("Full device sharing active")
FullDeviceSharingState.INACTIVE -> println("Full device sharing inactive")
}
}
}
Event Reference
| Method | Description |
|---|---|
onConnectionStateChanged(state) | Called when the connection state changes. |
onSessionStarted(agentName) | A screen sharing session has started. agentName is the agent's display name if available. |
onSessionEnded(reason) | A session has ended. reason indicates why (user stopped, agent stopped, timeout, or error). |
onCustomMessageReceived(message, viewerId) | A custom message was received from a viewer. |
onError(error) | An SDK error occurred. |
onViewerJoined(viewer) | An agent started viewing the session. The Viewer includes id, name, screen dimensions, and focus state. |
onViewerLeft(viewerId) | An agent stopped viewing the session. |
onViewerCountChanged(count) | The total number of active viewers changed. |
onRemoteControlStateChanged(state) | Whether an agent currently has remote control of the device (ability to tap and scroll) changed. Independent of the session being active. RemoteControlState: INACTIVE, ACTIVE. |
onFullDeviceSharingStateChanged(state) | Whether full-device (entire screen) sharing is currently running changed, as opposed to default in-app screen sharing. FullDeviceSharingState: INACTIVE, ACTIVE. |