VmessURL constructor
VmessURL({
- required String url,
Implementation
VmessURL({required super.url}) {
if (!url.startsWith('vmess://')) {
throw ArgumentError('url is invalid');
}
String raw = url.substring(8);
if (raw.length % 4 > 0) {
raw += "=" * (4 - raw.length % 4);
}
try {
rawConfig = jsonDecode(utf8.decode(base64Decode(raw)));
} catch (_) {
throw ArgumentError('url is invalid');
}
var sni = super.populateTransportSettings(
transport: rawConfig['net'],
headerType: rawConfig['type'],
host: rawConfig['host'],
path: rawConfig['path'],
seed: rawConfig['path'],
quicSecurity: rawConfig['host'],
key: rawConfig['path'],
mode: rawConfig['type'],
serviceName: rawConfig['path'],
);
String? fingerprint = (rawConfig['fp'] != null && rawConfig['fp'] != '')
? rawConfig['fp']
: streamSetting['tlsSettings']?['fingerprint'];
super.populateTlsSettings(
streamSecurity: rawConfig['tls'],
allowInsecure: allowInsecure,
sni: sni,
fingerprint: fingerprint,
alpns: rawConfig['alpn'],
publicKey: null,
shortId: null,
spiderX: null,
);
}