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
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
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:
val subscriptionId = // From where the subscription was set up
launch {
try {
sudoVPNClient.unsubscribeFromConnectionState(subscriptionId)
// or
sudoVPNClient.unsubscribeAll()
} catch (e: SudoVPNException) {
// Handle/notify the user of exception
}
}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:
const subscriptionId = uuid() //unique id to identify the subscription
const subscriber: (status: SudoVPNConnectionStatus) => void = (status) => {
// ...
}
const subscribeResult = await sudoVpnClient.subscribe(subscriptionId, subscriber)Cancelling A Subscription
To cancel a subscription, use the unsubscribe or unsubscribeAll method. For example:
const subscriptionId = // From where the subscription was set up
sudoVpnClient.unsubscribe(subscriptionId)
// or
sudoVpnClient.unsubscribeAll() This will ensure that the subscription is cancelled and system resources are freed.
Last updated