connect method
Connect using a V2Ray/Xray JSON configuration string.
configJson – Full V2Ray/Xray configuration as a JSON string.
name – Display name shown in the system VPN notification.
subProtocol – Optional hint about which sub-protocol is used
(vless, vmess, trojan, shadowsocks).
bypassPackages – Android only: exclude these apps from the tunnel.
durationSeconds – session time limit (e.g. a free-trial server's duration). When
set, the native Android service self-disconnects and posts a notification at
expiry, even if the app is backgrounded or killed. Null/0 = unlimited session.
Implementation
Future<void> connect(
String configJson,
String name, {
V2RaySubProtocol subProtocol = V2RaySubProtocol.vless,
List<String>? bypassPackages,
int? durationSeconds,
}) async {
if (!initialized) throw StateError('V2Ray must be initialized first.');
_tempDateTime = DateTime.now();
try {
await _channelControl.invokeMethod('connect', {
'config_json': configJson,
'name': name,
'sub_protocol': subProtocol.name,
'bypass_packages': bypassPackages ?? [],
'duration_seconds': durationSeconds ?? 0,
});
} on PlatformException catch (e) {
throw ArgumentError(e.message);
}
}