For the complete documentation index, see llms.txt. This page is also available as Markdown.

Observe VPN Related Events

Provides a simple way to watch any events required by your applications integrating with VPN SDK.

The VPN SDK on both mobile platforms provides an observer interface that can be implemented in order to handle any events that occur from the client. The VPN SDK for macOS and Windows provides a unified connection status event, offering real-time updates.

The supported events that can be implemented are:

Status/Configuration Events

Property
Description

serverWillChange

The server defined in the client's configuration is about to change.

serverDidChange

The server defined in the client's configuration did change.

protocolWillChange

The protocol defined in the client's configuration is about to change.

protocolDidChange

The protocol defined in the client's configuration did change.

Connection Events

Property
Description

connectionWillBegin

The connection to the VPN server is about to start connecting.

connectionDidBegin

The connection to the VPN server did start connecting.

connectionWillReconnect

The connection to the VPN server is about to attempt to reconnect

connectionSucceeded

The connection to the VPN server was successful.

connectionFailed

The connection to the VPN server failed with error.

connectionWillDisconnect

The connection to the VPN server is about to disconnect.

connectionDidDisconnect

The connection to the VPN server did disconnect.

Miscellaneous Events

profileFailedToInstall

The iOS VPN profile failed to install and returned with error.

Called on connect(withConfiguration:completion:) if the VPN pop-up fails or is denied.

To subscribe to observing connection state events, use the subscribeToConnectionState method. An identifier of the subscription and an instance of a class that implements the ConnectionStateSubscriber interface must be passed in. This class will be notified of changes to the connection state when the connection traverses between DISCONNECTED, CONNECTING, CONNECTED and ERROR states.

Setting Up A Subscription

To setup the subscription, call the subscribeToConnectionState method as so:

val subscriptionId = UUID.randomUUID().toString()
val subscriber = object : ConnectionStateSubscriber {
    override fun onStateChanged(newState: SudoVPNState) {
        when (newState) {
            SudoVPNState.CONNECTED -> {
                // Handle change in connection state
            }
            SudoVPNState.CONNECTING -> {
                // Handle change in connection state
            }
            SudoVPNState.DISCONNECTED -> {
                // Handle change in connection state
            }
            SudoVPNState.ERROR -> {
                // Handle change in connection state
            }
        }
    }
}
launch {
    try {
        sudoVPNClient.subscribeToConnectionState(
            subscriptionId,
            subscriber
        )
    } catch (e: SudoVPNException) {
        // Handle/notify the user of exception
    }
}

Cancelling A Subscription

To cancel a subscription, use the unsubscribeFromConnectionState or unsubscribeAll method. For example:

This will ensure that the subscription is cancelled and system resources are freed.

To subscribe to observing connection state events, use the subscribe method. An identifier of the subscription and a function that accepts the SudoVPNConnectionStatus as a parameter must be passed in. This function will be notified of changes to the connection state when the connection traverses between states.

Valid States: disconnected disconnecting connecting connected error unknown

Setting Up A Subscription

To setup the subscription, call the subscribe method as so:

Cancelling A Subscription

To cancel a subscription, use the unsubscribe or unsubscribeAll method. For example:

This will ensure that the subscription is cancelled and system resources are freed.

Last updated