connect method

Future<void> connect(
  1. String configJson,
  2. String name, {
  3. V2RaySubProtocol subProtocol = V2RaySubProtocol.vless,
  4. List<String>? bypassPackages,
})

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.

Implementation

Future<void> connect(
  String configJson,
  String name, {
  V2RaySubProtocol subProtocol = V2RaySubProtocol.vless,
  List<String>? bypassPackages,
}) 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 ?? [],
    });
  } on PlatformException catch (e) {
    throw ArgumentError(e.message);
  }
}