V2ray class
A class for managing V2Ray connections and operations. Provides methods to initialize, start, stop, and query V2Ray services.
Constructors
- V2ray.new({required void onStatusChanged(V2RayStatus status)})
-
Creates a new V2ray instance.
onStatusChanged
is 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.
url
is 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.
config
is the V2Ray configuration in JSON format.url
is 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.
notificationIconResourceType
specifies the type of the notification icon (e.g., 'mipmap').notificationIconResourceName
specifies 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.
remark
is a string identifier for the connection.config
is the V2Ray configuration in JSON format.blockedApps
is an optional list of app package names to block.bypassSubnets
is an optional list of subnets to bypass the VPN.proxyOnly
is a boolean indicating whether to run in proxy-only mode.notificationDisconnectButtonName
is 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.
url
is 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).