Listening for Events
You can listen for SDK events by implementing the UpscopeDelegate protocol and assigning it to the shared instance:
Upscope.shared.delegate = self
UpscopeDelegate Protocol
All delegate methods are optional.
extension YourClass: UpscopeDelegate {
func upscope(_ upscope: Upscope, didChangeConnectionState state: ConnectionState) {
// Connection state changed
switch state {
case .inactive:
print("Inactive")
case .connecting:
print("Connecting...")
case .connected:
print("Connected")
case .reconnecting:
print("Reconnecting...")
case .error(let error):
print("Error: \(error.message)")
}
}
func upscopeSessionDidStart(_ upscope: Upscope, agentName: String?) {
print("Session started with \(agentName ?? "an agent")")
}
func upscopeSessionDidEnd(_ upscope: Upscope, reason: SessionEndReason) {
switch reason {
case .userStopped:
print("User ended session")
case .agentStopped:
print("Agent ended session")
case .timeout:
print("Session timed out")
case .error(let error):
print("Session error: \(error.message)")
}
}
func upscope(_ upscope: Upscope, didReceiveCustomMessage message: String, from viewerId: String) {
print("Message from \(viewerId): \(message)")
}
func upscope(_ upscope: Upscope, didEncounterError error: UpscopeError) {
print("Error: \(error.code) - \(error.message)")
}
func upscope(_ upscope: Upscope, viewerDidJoin viewer: Viewer) {
print("Viewer joined: \(viewer.name ?? viewer.id)")
}
func upscope(_ upscope: Upscope, viewerDidLeave viewerId: String) {
print("Viewer left: \(viewerId)")
}
func upscope(_ upscope: Upscope, viewerCountDidChange count: Int) {
print("Viewers: \(count)")
}
func upscope(_ upscope: Upscope, didChangeRemoteControlState state: RemoteControlState) {
// Whether an agent currently has remote control changed
print("Remote control state: \(state)")
}
func upscope(_ upscope: Upscope, didChangeFullDeviceSharingState state: FullDeviceSharingState) {
// Whether full-device screen sharing is active changed
print("Full device sharing state: \(state)")
}
}
Event Reference
| Method | Description |
|---|---|
upscope(_:didChangeConnectionState:) | Called when the connection state changes. |
upscopeSessionDidStart(_:agentName:) | A screen sharing session has started. agentName is the agent's display name if available. |
upscopeSessionDidEnd(_:reason:) | A session has ended. reason indicates why (user stopped, agent stopped, timeout, or error). |
upscope(_:didReceiveCustomMessage:from:) | A custom message was received from a viewer. |
upscope(_:didEncounterError:) | An SDK error occurred. |
upscope(_:viewerDidJoin:) | An agent started viewing the session. The Viewer includes id, name, screen dimensions, and focus state. |
upscope(_:viewerDidLeave:) | An agent stopped viewing the session. |
upscope(_:viewerCountDidChange:) | The total number of active viewers changed. |
upscope(_:didChangeRemoteControlState:) | Whether an agent currently has remote control of the device (ability to tap and scroll) changed. Independent of the session being active. |
upscope(_:didChangeFullDeviceSharingState:) | Whether full-device (entire screen) sharing is currently running changed, as opposed to default in-app screen sharing. |