API

βš™οΈ Methods

πŸ”Ή 1. initialize()

Initializes the VPN controller. This should be called before using any other method.

πŸ”Ή 2. connect({required int index})

Connects to the specified VPN server.

  • index: Index of the server from getServerList().

πŸ”Ή 3. disconnect()

Disconnects the active VPN connection.

πŸ”Ή 4. getConnectionStatus()

Returns the current connection status (connected, disconnected, connecting, error).

πŸ”Ή 5. getServerList()

Fetches the list of available VPN servers.

πŸ”Ή 6. pingServer({required int index})

Pings a specific server to check latency.

  • index: Index of the server from getServerList().

  • Returns: Latency in milliseconds.

πŸ”Ή 7. setRoutingRules({required List rules})

Configures routing rules for apps or domains.

  • rules: List of routing rules (e.g., route YouTube traffic through VPN, block ads.com).

Loads a VPN subscription from the provided link.

  • subscriptionLink: The subscription file URL.

πŸ”Ή 9. getSessionStatistics()

Returns statistics for the current VPN session (e.g., data usage, session duration).

πŸ”Ή 10. setAutoConnect({required bool enable})

Enables or disables auto-connect functionality.

  • enable: true to enable, false to disable.

πŸ”Ή 11. setKillSwitch({required bool enable})

Enables or disables the kill switch.

  • enable: true to enable, false to disable.


πŸ”” Events

πŸ“‘ 1. onConnectionStatusChanged

Triggered when VPN connection status changes.

  • Payload: ConnectionStatus (e.g., connected, disconnected, error).

⚠️ 2. onError

Triggered when an error occurs.

  • Payload: ErrorCode and ErrorMessage.

πŸ”„ 3. onServerSwitched

Triggered when the VPN server is switched.

  • Payload: newServerAddress.

πŸ“Š 4. onPingResult

Triggered when a ping operation completes.

  • Payload: serverIndex and latencyInMs.

πŸ”‘ 5. onSubscriptionLoaded

Triggered when a subscription is loaded successfully.

  • Payload: subscriptionDetails.

πŸ“ˆ 6. onDataUsageUpdated

Triggered periodically with updated data usage statistics.

  • Payload: dataUsed and dataRemaining.

πŸ“Œ 7. onRoutingRulesApplied

Triggered when routing rules are applied.

  • Payload: List<RoutingRule>.

🚨 8. onKillSwitchTriggered

Triggered when the kill switch is activated.


πŸ“‚ Data Models

πŸ”Ή 1. ConnectionStatus

Enum: connecting, connected, disconnected, error.

πŸ”Ή 2. Server

  • address

  • latency

  • location

  • isPreferred

πŸ”Ή 3. RoutingRule

  • appName

  • domain

  • action (block, allow, routeThroughVPN).

πŸ”Ή 4. ProxyConfig

  • type (socks5, http)

  • address

  • port

  • credentials

πŸ”Ή 5. ErrorCode

Enum: invalidCredentials, serverUnavailable, subscriptionExpired, unknownError.

πŸ”Ή 6. SubscriptionDetails

  • expiryDate

  • dataLimit

  • usedData

Last updated