V2ray class
A class for managing V2Ray connections and operations. Provides methods to initialize, start, stop, and query V2Ray services.
Constructors
- V2ray({required void onStatusChanged(V2RayStatus status)})
-
Creates a new V2ray instance.
onStatusChangedis a callback function that will be called whenever the V2Ray status changes.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- onStatusChanged → void Function(V2RayStatus status)
-
Callback function invoked when the V2Ray status changes.
It receives a V2RayStatus object containing details like duration, speeds, and state.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getConnectedServerDelay(
{String url = 'https://google.com/generate_204'}) → Future< int> -
Measures the delay to the currently connected V2Ray server.
urlis the server URL to test for delay (default is 'https://google.com/generate_204'). Returns a Future that completes with the delay in milliseconds. -
getCoreVersion(
) → Future< String> - Retrieves the version of the V2Ray core. Returns a Future that completes with a String representing the core version.
-
getServerDelay(
{required String config, String url = 'https://google.com/generate_204'}) → Future< int> -
Measures the delay to a V2Ray server using the provided configuration.
configis the V2Ray configuration in JSON format.urlis the server URL to test for delay (default is 'https://google.com/generate_204'). Throws an ArgumentError if the config is not valid JSON. Returns a Future that completes with the delay in milliseconds. -
initialize(
{String notificationIconResourceType = 'mipmap', String notificationIconResourceName = 'ic_launcher'}) → Future< void> -
Initializes the V2Ray client with notification settings and a status change callback.
notificationIconResourceTypespecifies the type of the notification icon (e.g., 'mipmap').notificationIconResourceNamespecifies the name of the notification icon (e.g., 'ic_launcher'). Returns a Future that completes when initialization is done. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
requestPermission(
) → Future< bool> - Requests permission to use V2Ray features, such as VPN access on Android. Returns a Future that completes with true if permission is granted, otherwise false. On non-Android platforms, it defaults to granting permission.
-
startV2Ray(
{required String remark, required String config, List< String> ? blockedApps, List<String> ? bypassSubnets, bool proxyOnly = false, String notificationDisconnectButtonName = 'DISCONNECT'}) → Future<void> -
Starts the V2Ray service with the given configuration and settings.
remarkis a string identifier for the connection.configis the V2Ray configuration in JSON format.blockedAppsis an optional list of app package names to block.bypassSubnetsis an optional list of subnets to bypass the VPN.proxyOnlyis a boolean indicating whether to run in proxy-only mode.notificationDisconnectButtonNameis the text for the disconnect button in notifications. Throws an ArgumentError if the config is not valid JSON. Returns a Future that completes when the service starts. -
stopV2Ray(
) → Future< void> - Stops the V2Ray service. Returns a Future that completes when the service is stopped.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
parseFromURL(
String url) → V2RayURL -
Parses a V2Ray URL string and returns the corresponding V2RayURL object.
urlis the V2Ray share link (e.g., 'vmess://', 'vless://', etc.). Throws an ArgumentError if the URL scheme is invalid. Returns a V2RayURL instance based on the scheme (e.g., VmessURL, VlessURL).