Documentation

    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 observerId: String) {
            print("Message from \(observerId): \(message)")
        }
    
        func upscope(_ upscope: Upscope, didEncounterError error: UpscopeError) {
            print("Error: \(error.code) - \(error.message)")
        }
    
        func upscope(_ upscope: Upscope, observerDidJoin observer: Observer) {
            print("Observer joined: \(observer.name ?? observer.id)")
        }
    
        func upscope(_ upscope: Upscope, observerDidLeave observerId: String) {
            print("Observer left: \(observerId)")
        }
    
        func upscope(_ upscope: Upscope, observerCountDidChange count: Int) {
            print("Observers: \(count)")
        }
    }
    

    Event Reference

    MethodDescription
    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 an observer.
    upscope(_:didEncounterError:)An SDK error occurred.
    upscope(_:observerDidJoin:)An agent started observing the session. The Observer includes id, name, screen dimensions, and focus state.
    upscope(_:observerDidLeave:)An agent stopped observing the session.
    upscope(_:observerCountDidChange:)The total number of active observers changed.