buildVmessConfig static method

String buildVmessConfig({
  1. required String address,
  2. required int port,
  3. required String uuid,
  4. int alterId = 0,
  5. String network = 'tcp',
  6. String security = 'tls',
  7. String? serverName,
  8. String? path,
})

Build a minimal VMess JSON config string.

Implementation

static String buildVmessConfig({
  required String address,
  required int port,
  required String uuid,
  int alterId = 0,
  String network = 'tcp',
  String security = 'tls',
  String? serverName,
  String? path,
}) {
  return jsonEncode({
    'log': {'loglevel': 'warning'},
    'inbounds': [
      {
        'port': 10808,
        'protocol': 'socks',
        'settings': {'auth': 'noauth'},
      },
    ],
    'outbounds': [
      {
        'protocol': 'vmess',
        'settings': {
          'vnext': [
            {
              'address': address,
              'port': port,
              'users': [
                {
                  'id': uuid,
                  'alterId': alterId,
                  'security': 'auto',
                },
              ],
            },
          ],
        },
        'streamSettings': {
          'network': network,
          if (network == 'ws') 'wsSettings': {'path': path ?? '/'},
          'security': security,
          if (security == 'tls')
            'tlsSettings': {
              'serverName': serverName ?? address,
              'allowInsecure': false,
            },
        },
      },
    ],
  });
}