Skip to content

Berk190772/VPNclient-controller-flutter

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ VPN Client Controller Flutter

🌍 Overview

VPN Client Controller Flutter is a Flutter wrapper for managing VPN connections with an intuitive API. It provides seamless integration with various platforms, allowing developers to control VPN connections efficiently. VPN Client Controller

βœ… Supported Platforms

  • iOS 15+ (iPhone, iPad, MacOS M)
  • Android
  • πŸ—οΈ MacOS Intel (coming soon)
  • πŸ—οΈ Windows (coming soon)
  • πŸ—οΈ Ubuntu (coming soon)

πŸ“₯ Getting Started

To start using VPN Client Controller Flutter, ensure you have Flutter installed and set up your project accordingly.

πŸ“¦ Installation

flutter pub add vpnclient_controller

πŸ“Œ Example Usage

// Initialize the controller
vpnController.initialize();

// Load subscription
vpnController.loadSubscription(
  subscriptionLink: "https://pastebin.com/raw/ZCYiJ98W"
);

// Connect to a VPN server
vpnController.connect(index: 1);

// Listen for connection status changes
vpnController.onConnectionStatusChanged.listen((status) {
  print("Connection status: $status");
});

// Set routing rules
vpnController.setRoutingRules(
  rules: [
    RoutingRule(appName: "YouTube", action: "routeThroughVPN"),
    RoutingRule(domain: "ads.com", action: "block"),
  ],
);

// Ping a server
vpnController.pingServer(index: 1);
vpnController.onPingResult.listen((result) {
  print("Ping result: ${result.latencyInMs} ms");
});

βš™οΈ 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).

πŸ”Ή 8. loadSubscription({required String subscriptionLink})

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

🀝 Contributing

Contributions are welcome! Feel free to submit issues and pull requests.

πŸ“œ License

This project is licensed under ...

About

Flutter wrapper for VPN Client Controller: Xray(VMESS, VLESS, REALITY) + WireGuard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 44.8%
  • HTML 32.8%
  • Swift 17.7%
  • Kotlin 3.7%
  • Objective-C 1.0%