| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302 | 
							- const Protocols = {
 
-     Freedom: "freedom",
 
-     Blackhole: "blackhole",
 
-     DNS: "dns",
 
-     VMess: "vmess",
 
-     VLESS: "vless",
 
-     Trojan: "trojan",
 
-     Shadowsocks: "shadowsocks",
 
-     Socks: "socks",
 
-     HTTP: "http",
 
-     Wireguard: "wireguard"
 
- };
 
- const SSMethods = {
 
-     AES_256_GCM: 'aes-256-gcm',
 
-     AES_128_GCM: 'aes-128-gcm',
 
-     CHACHA20_POLY1305: 'chacha20-poly1305',
 
-     CHACHA20_IETF_POLY1305: 'chacha20-ietf-poly1305',
 
-     XCHACHA20_POLY1305: 'xchacha20-poly1305',
 
-     XCHACHA20_IETF_POLY1305: 'xchacha20-ietf-poly1305',
 
-     BLAKE3_AES_128_GCM: '2022-blake3-aes-128-gcm',
 
-     BLAKE3_AES_256_GCM: '2022-blake3-aes-256-gcm',
 
-     BLAKE3_CHACHA20_POLY1305: '2022-blake3-chacha20-poly1305',
 
- };
 
- const TLS_FLOW_CONTROL = {
 
-     VISION: "xtls-rprx-vision",
 
-     VISION_UDP443: "xtls-rprx-vision-udp443",
 
- };
 
- const UTLS_FINGERPRINT = {
 
-     UTLS_CHROME: "chrome",
 
-     UTLS_FIREFOX: "firefox",
 
-     UTLS_SAFARI: "safari",
 
-     UTLS_IOS: "ios",
 
-     UTLS_android: "android",
 
-     UTLS_EDGE: "edge",
 
-     UTLS_360: "360",
 
-     UTLS_QQ: "qq",
 
-     UTLS_RANDOM: "random",
 
-     UTLS_RANDOMIZED: "randomized",
 
-     UTLS_RONDOMIZEDNOALPN: "randomizednoalpn",
 
-     UTLS_UNSAFE: "unsafe",
 
- };
 
- const ALPN_OPTION = {
 
-     H3: "h3",
 
-     H2: "h2",
 
-     HTTP1: "http/1.1",
 
- };
 
- const OutboundDomainStrategies = [
 
-     "AsIs",
 
-     "UseIP",
 
-     "UseIPv4",
 
-     "UseIPv6",
 
-     "UseIPv6v4",
 
-     "UseIPv4v6",
 
-     "ForceIP",
 
-     "ForceIPv6v4",
 
-     "ForceIPv6",
 
-     "ForceIPv4v6",
 
-     "ForceIPv4"
 
- ];
 
- const WireguardDomainStrategy = [
 
-     "ForceIP",
 
-     "ForceIPv4",
 
-     "ForceIPv4v6",
 
-     "ForceIPv6",
 
-     "ForceIPv6v4"
 
- ];
 
- const USERS_SECURITY = {
 
-     AES_128_GCM: "aes-128-gcm",
 
-     CHACHA20_POLY1305: "chacha20-poly1305",
 
-     AUTO: "auto",
 
-     NONE: "none",
 
-     ZERO: "zero",
 
- };
 
- const MODE_OPTION = {
 
-     AUTO: "auto",
 
-     PACKET_UP: "packet-up",
 
-     STREAM_UP: "stream-up",
 
-     STREAM_ONE: "stream-one",
 
- };
 
- const Address_Port_Strategy = {
 
-     NONE: "none",
 
-     SrvPortOnly: "srvportonly",
 
-     SrvAddressOnly: "srvaddressonly",
 
-     SrvPortAndAddress: "srvportandaddress",
 
-     TxtPortOnly: "txtportonly",
 
-     TxtAddressOnly: "txtaddressonly",
 
-     TxtPortAndAddress: "txtportandaddress"
 
- };
 
- Object.freeze(Protocols);
 
- Object.freeze(SSMethods);
 
- Object.freeze(TLS_FLOW_CONTROL);
 
- Object.freeze(UTLS_FINGERPRINT);
 
- Object.freeze(ALPN_OPTION);
 
- Object.freeze(OutboundDomainStrategies);
 
- Object.freeze(WireguardDomainStrategy);
 
- Object.freeze(USERS_SECURITY);
 
- Object.freeze(MODE_OPTION);
 
- Object.freeze(Address_Port_Strategy);
 
- class CommonClass {
 
-     static toJsonArray(arr) {
 
-         return arr.map(obj => obj.toJson());
 
-     }
 
-     static fromJson() {
 
-         return new CommonClass();
 
-     }
 
-     toJson() {
 
-         return this;
 
-     }
 
-     toString(format = true) {
 
-         return format ? JSON.stringify(this.toJson(), null, 2) : JSON.stringify(this.toJson());
 
-     }
 
- }
 
- class TcpStreamSettings extends CommonClass {
 
-     constructor(type = 'none', host, path) {
 
-         super();
 
-         this.type = type;
 
-         this.host = host;
 
-         this.path = path;
 
-     }
 
-     static fromJson(json = {}) {
 
-         let header = json.header;
 
-         if (!header) return new TcpStreamSettings();
 
-         if (header.type == 'http' && header.request) {
 
-             return new TcpStreamSettings(
 
-                 header.type,
 
-                 header.request.headers.Host.join(','),
 
-                 header.request.path.join(','),
 
-             );
 
-         }
 
-         return new TcpStreamSettings(header.type, '', '');
 
-     }
 
-     toJson() {
 
-         return {
 
-             header: {
 
-                 type: this.type,
 
-                 request: this.type === 'http' ? {
 
-                     headers: {
 
-                         Host: ObjectUtil.isEmpty(this.host) ? [] : this.host.split(',')
 
-                     },
 
-                     path: ObjectUtil.isEmpty(this.path) ? ["/"] : this.path.split(',')
 
-                 } : undefined,
 
-             }
 
-         };
 
-     }
 
- }
 
- class KcpStreamSettings extends CommonClass {
 
-     constructor(
 
-         mtu = 1350,
 
-         tti = 50,
 
-         uplinkCapacity = 5,
 
-         downlinkCapacity = 20,
 
-         congestion = false,
 
-         readBufferSize = 2,
 
-         writeBufferSize = 2,
 
-         type = 'none',
 
-         seed = '',
 
-     ) {
 
-         super();
 
-         this.mtu = mtu;
 
-         this.tti = tti;
 
-         this.upCap = uplinkCapacity;
 
-         this.downCap = downlinkCapacity;
 
-         this.congestion = congestion;
 
-         this.readBuffer = readBufferSize;
 
-         this.writeBuffer = writeBufferSize;
 
-         this.type = type;
 
-         this.seed = seed;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new KcpStreamSettings(
 
-             json.mtu,
 
-             json.tti,
 
-             json.uplinkCapacity,
 
-             json.downlinkCapacity,
 
-             json.congestion,
 
-             json.readBufferSize,
 
-             json.writeBufferSize,
 
-             ObjectUtil.isEmpty(json.header) ? 'none' : json.header.type,
 
-             json.seed,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             mtu: this.mtu,
 
-             tti: this.tti,
 
-             uplinkCapacity: this.upCap,
 
-             downlinkCapacity: this.downCap,
 
-             congestion: this.congestion,
 
-             readBufferSize: this.readBuffer,
 
-             writeBufferSize: this.writeBuffer,
 
-             header: {
 
-                 type: this.type,
 
-             },
 
-             seed: this.seed,
 
-         };
 
-     }
 
- }
 
- class WsStreamSettings extends CommonClass {
 
-     constructor(
 
-         path = '/',
 
-         host = '',
 
-         heartbeatPeriod = 0,
 
-     ) {
 
-         super();
 
-         this.path = path;
 
-         this.host = host;
 
-         this.heartbeatPeriod = heartbeatPeriod;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new WsStreamSettings(
 
-             json.path,
 
-             json.host,
 
-             json.heartbeatPeriod,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             path: this.path,
 
-             host: this.host,
 
-             heartbeatPeriod: this.heartbeatPeriod
 
-         };
 
-     }
 
- }
 
- class GrpcStreamSettings extends CommonClass {
 
-     constructor(
 
-         serviceName = "",
 
-         authority = "",
 
-         multiMode = false
 
-     ) {
 
-         super();
 
-         this.serviceName = serviceName;
 
-         this.authority = authority;
 
-         this.multiMode = multiMode;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new GrpcStreamSettings(json.serviceName, json.authority, json.multiMode);
 
-     }
 
-     toJson() {
 
-         return {
 
-             serviceName: this.serviceName,
 
-             authority: this.authority,
 
-             multiMode: this.multiMode
 
-         }
 
-     }
 
- }
 
- class HttpUpgradeStreamSettings extends CommonClass {
 
-     constructor(path = '/', host = '') {
 
-         super();
 
-         this.path = path;
 
-         this.host = host;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new HttpUpgradeStreamSettings(
 
-             json.path,
 
-             json.host,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             path: this.path,
 
-             host: this.host,
 
-         };
 
-     }
 
- }
 
- class xHTTPStreamSettings extends CommonClass {
 
-     constructor(
 
-         path = '/',
 
-         host = '',
 
-         mode = '',
 
-         noGRPCHeader = false,
 
-         scMinPostsIntervalMs = "30",
 
-         xmux = {
 
-             maxConcurrency: "16-32",
 
-             maxConnections: 0,
 
-             cMaxReuseTimes: 0,
 
-             hMaxRequestTimes: "600-900",
 
-             hMaxReusableSecs: "1800-3000",
 
-             hKeepAlivePeriod: 0,
 
-         },
 
-     ) {
 
-         super();
 
-         this.path = path;
 
-         this.host = host;
 
-         this.mode = mode;
 
-         this.noGRPCHeader = noGRPCHeader;
 
-         this.scMinPostsIntervalMs = scMinPostsIntervalMs;
 
-         this.xmux = xmux;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new xHTTPStreamSettings(
 
-             json.path,
 
-             json.host,
 
-             json.mode,
 
-             json.noGRPCHeader,
 
-             json.scMinPostsIntervalMs,
 
-             json.xmux
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             path: this.path,
 
-             host: this.host,
 
-             mode: this.mode,
 
-             noGRPCHeader: this.noGRPCHeader,
 
-             scMinPostsIntervalMs: this.scMinPostsIntervalMs,
 
-             xmux: {
 
-                 maxConcurrency: this.xmux.maxConcurrency,
 
-                 maxConnections: this.xmux.maxConnections,
 
-                 cMaxReuseTimes: this.xmux.cMaxReuseTimes,
 
-                 hMaxRequestTimes: this.xmux.hMaxRequestTimes,
 
-                 hMaxReusableSecs: this.xmux.hMaxReusableSecs,
 
-                 hKeepAlivePeriod: this.xmux.hKeepAlivePeriod,
 
-             },
 
-         };
 
-     }
 
- }
 
- class TlsStreamSettings extends CommonClass {
 
-     constructor(
 
-         serverName = '',
 
-         alpn = [],
 
-         fingerprint = '',
 
-         allowInsecure = false,
 
-         echConfigList = '',
 
-     ) {
 
-         super();
 
-         this.serverName = serverName;
 
-         this.alpn = alpn;
 
-         this.fingerprint = fingerprint;
 
-         this.allowInsecure = allowInsecure;
 
-         this.echConfigList = echConfigList;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new TlsStreamSettings(
 
-             json.serverName,
 
-             json.alpn,
 
-             json.fingerprint,
 
-             json.allowInsecure,
 
-             json.echConfigList,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             serverName: this.serverName,
 
-             alpn: this.alpn,
 
-             fingerprint: this.fingerprint,
 
-             allowInsecure: this.allowInsecure,
 
-             echConfigList: this.echConfigList
 
-         };
 
-     }
 
- }
 
- class RealityStreamSettings extends CommonClass {
 
-     constructor(
 
-         publicKey = '',
 
-         fingerprint = '',
 
-         serverName = '',
 
-         shortId = '',
 
-         spiderX = '',
 
-         mldsa65Verify = ''
 
-     ) {
 
-         super();
 
-         this.publicKey = publicKey;
 
-         this.fingerprint = fingerprint;
 
-         this.serverName = serverName;
 
-         this.shortId = shortId
 
-         this.spiderX = spiderX;
 
-         this.mldsa65Verify = mldsa65Verify;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new RealityStreamSettings(
 
-             json.publicKey,
 
-             json.fingerprint,
 
-             json.serverName,
 
-             json.shortId,
 
-             json.spiderX,
 
-             json.mldsa65Verify
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             publicKey: this.publicKey,
 
-             fingerprint: this.fingerprint,
 
-             serverName: this.serverName,
 
-             shortId: this.shortId,
 
-             spiderX: this.spiderX,
 
-             mldsa65Verify: this.mldsa65Verify
 
-         };
 
-     }
 
- };
 
- class SockoptStreamSettings extends CommonClass {
 
-     constructor(
 
-         dialerProxy = "",
 
-         tcpFastOpen = false,
 
-         tcpKeepAliveInterval = 0,
 
-         tcpMptcp = false,
 
-         penetrate = false,
 
-         addressPortStrategy = Address_Port_Strategy.NONE,
 
-     ) {
 
-         super();
 
-         this.dialerProxy = dialerProxy;
 
-         this.tcpFastOpen = tcpFastOpen;
 
-         this.tcpKeepAliveInterval = tcpKeepAliveInterval;
 
-         this.tcpMptcp = tcpMptcp;
 
-         this.penetrate = penetrate;
 
-         this.addressPortStrategy = addressPortStrategy;
 
-     }
 
-     static fromJson(json = {}) {
 
-         if (Object.keys(json).length === 0) return undefined;
 
-         return new SockoptStreamSettings(
 
-             json.dialerProxy,
 
-             json.tcpFastOpen,
 
-             json.tcpKeepAliveInterval,
 
-             json.tcpMptcp,
 
-             json.penetrate,
 
-             json.addressPortStrategy
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             dialerProxy: this.dialerProxy,
 
-             tcpFastOpen: this.tcpFastOpen,
 
-             tcpKeepAliveInterval: this.tcpKeepAliveInterval,
 
-             tcpMptcp: this.tcpMptcp,
 
-             penetrate: this.penetrate,
 
-             addressPortStrategy: this.addressPortStrategy
 
-         };
 
-     }
 
- }
 
- class StreamSettings extends CommonClass {
 
-     constructor(
 
-         network = 'tcp',
 
-         security = 'none',
 
-         tlsSettings = new TlsStreamSettings(),
 
-         realitySettings = new RealityStreamSettings(),
 
-         tcpSettings = new TcpStreamSettings(),
 
-         kcpSettings = new KcpStreamSettings(),
 
-         wsSettings = new WsStreamSettings(),
 
-         grpcSettings = new GrpcStreamSettings(),
 
-         httpupgradeSettings = new HttpUpgradeStreamSettings(),
 
-         xhttpSettings = new xHTTPStreamSettings(),
 
-         sockopt = undefined,
 
-     ) {
 
-         super();
 
-         this.network = network;
 
-         this.security = security;
 
-         this.tls = tlsSettings;
 
-         this.reality = realitySettings;
 
-         this.tcp = tcpSettings;
 
-         this.kcp = kcpSettings;
 
-         this.ws = wsSettings;
 
-         this.grpc = grpcSettings;
 
-         this.httpupgrade = httpupgradeSettings;
 
-         this.xhttp = xhttpSettings;
 
-         this.sockopt = sockopt;
 
-     }
 
-     get isTls() {
 
-         return this.security === 'tls';
 
-     }
 
-     get isReality() {
 
-         return this.security === "reality";
 
-     }
 
-     get sockoptSwitch() {
 
-         return this.sockopt != undefined;
 
-     }
 
-     set sockoptSwitch(value) {
 
-         this.sockopt = value ? new SockoptStreamSettings() : undefined;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new StreamSettings(
 
-             json.network,
 
-             json.security,
 
-             TlsStreamSettings.fromJson(json.tlsSettings),
 
-             RealityStreamSettings.fromJson(json.realitySettings),
 
-             TcpStreamSettings.fromJson(json.tcpSettings),
 
-             KcpStreamSettings.fromJson(json.kcpSettings),
 
-             WsStreamSettings.fromJson(json.wsSettings),
 
-             GrpcStreamSettings.fromJson(json.grpcSettings),
 
-             HttpUpgradeStreamSettings.fromJson(json.httpupgradeSettings),
 
-             xHTTPStreamSettings.fromJson(json.xhttpSettings),
 
-             SockoptStreamSettings.fromJson(json.sockopt),
 
-         );
 
-     }
 
-     toJson() {
 
-         const network = this.network;
 
-         return {
 
-             network: network,
 
-             security: this.security,
 
-             tlsSettings: this.security == 'tls' ? this.tls.toJson() : undefined,
 
-             realitySettings: this.security == 'reality' ? this.reality.toJson() : undefined,
 
-             tcpSettings: network === 'tcp' ? this.tcp.toJson() : undefined,
 
-             kcpSettings: network === 'kcp' ? this.kcp.toJson() : undefined,
 
-             wsSettings: network === 'ws' ? this.ws.toJson() : undefined,
 
-             grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined,
 
-             httpupgradeSettings: network === 'httpupgrade' ? this.httpupgrade.toJson() : undefined,
 
-             xhttpSettings: network === 'xhttp' ? this.xhttp.toJson() : undefined,
 
-             sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined,
 
-         };
 
-     }
 
- }
 
- class Mux extends CommonClass {
 
-     constructor(enabled = false, concurrency = 8, xudpConcurrency = 16, xudpProxyUDP443 = "reject") {
 
-         super();
 
-         this.enabled = enabled;
 
-         this.concurrency = concurrency;
 
-         this.xudpConcurrency = xudpConcurrency;
 
-         this.xudpProxyUDP443 = xudpProxyUDP443;
 
-     }
 
-     static fromJson(json = {}) {
 
-         if (Object.keys(json).length === 0) return undefined;
 
-         return new Mux(
 
-             json.enabled,
 
-             json.concurrency,
 
-             json.xudpConcurrency,
 
-             json.xudpProxyUDP443,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             enabled: this.enabled,
 
-             concurrency: this.concurrency,
 
-             xudpConcurrency: this.xudpConcurrency,
 
-             xudpProxyUDP443: this.xudpProxyUDP443,
 
-         };
 
-     }
 
- }
 
- class Outbound extends CommonClass {
 
-     constructor(
 
-         tag = '',
 
-         protocol = Protocols.VLESS,
 
-         settings = null,
 
-         streamSettings = new StreamSettings(),
 
-         sendThrough,
 
-         mux = new Mux(),
 
-     ) {
 
-         super();
 
-         this.tag = tag;
 
-         this._protocol = protocol;
 
-         this.settings = settings == null ? Outbound.Settings.getSettings(protocol) : settings;
 
-         this.stream = streamSettings;
 
-         this.sendThrough = sendThrough;
 
-         this.mux = mux;
 
-     }
 
-     get protocol() {
 
-         return this._protocol;
 
-     }
 
-     set protocol(protocol) {
 
-         this._protocol = protocol;
 
-         this.settings = Outbound.Settings.getSettings(protocol);
 
-         this.stream = new StreamSettings();
 
-     }
 
-     canEnableTls() {
 
-         if (![Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(this.protocol)) return false;
 
-         return ["tcp", "ws", "http", "grpc", "httpupgrade", "xhttp"].includes(this.stream.network);
 
-     }
 
-     //this is used for xtls-rprx-vision
 
-     canEnableTlsFlow() {
 
-         if ((this.stream.security != 'none') && (this.stream.network === "tcp")) {
 
-             return this.protocol === Protocols.VLESS;
 
-         }
 
-         return false;
 
-     }
 
-     canEnableReality() {
 
-         if (![Protocols.VLESS, Protocols.Trojan].includes(this.protocol)) return false;
 
-         return ["tcp", "http", "grpc", "xhttp"].includes(this.stream.network);
 
-     }
 
-     canEnableStream() {
 
-         return [Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(this.protocol);
 
-     }
 
-     canEnableMux() {
 
-         // Disable Mux if flow is set
 
-         if (this.settings.flow && this.settings.flow !== '') {
 
-             this.mux.enabled = false;
 
-             return false;
 
-         }
 
-         // Disable Mux if network is xhttp
 
-         if (this.stream.network === 'xhttp') {
 
-             this.mux.enabled = false;
 
-             return false;
 
-         }
 
-         // Allow Mux only for these protocols
 
-         return [
 
-             Protocols.VMess,
 
-             Protocols.VLESS,
 
-             Protocols.Trojan,
 
-             Protocols.Shadowsocks,
 
-             Protocols.HTTP,
 
-             Protocols.Socks
 
-         ].includes(this.protocol);
 
-     }
 
-     hasServers() {
 
-         return [Protocols.Trojan, Protocols.Shadowsocks, Protocols.Socks, Protocols.HTTP].includes(this.protocol);
 
-     }
 
-     hasAddressPort() {
 
-         return [
 
-             Protocols.DNS,
 
-             Protocols.VMess,
 
-             Protocols.VLESS,
 
-             Protocols.Trojan,
 
-             Protocols.Shadowsocks,
 
-             Protocols.Socks,
 
-             Protocols.HTTP
 
-         ].includes(this.protocol);
 
-     }
 
-     hasUsername() {
 
-         return [Protocols.Socks, Protocols.HTTP].includes(this.protocol);
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new Outbound(
 
-             json.tag,
 
-             json.protocol,
 
-             Outbound.Settings.fromJson(json.protocol, json.settings),
 
-             StreamSettings.fromJson(json.streamSettings),
 
-             json.sendThrough,
 
-             Mux.fromJson(json.mux),
 
-         )
 
-     }
 
-     toJson() {
 
-         var stream;
 
-         if (this.canEnableStream()) {
 
-             stream = this.stream.toJson();
 
-         } else {
 
-             if (this.stream?.sockopt)
 
-                 stream = { sockopt: this.stream.sockopt.toJson() };
 
-         }
 
-         let settingsOut = this.settings instanceof CommonClass ? this.settings.toJson() : this.settings;
 
-         return {
 
-             protocol: this.protocol,
 
-             settings: settingsOut,
 
-             // Only include tag, streamSettings, sendThrough, mux if present and not empty
 
-             ...(this.tag ? { tag: this.tag } : {}),
 
-             ...(stream ? { streamSettings: stream } : {}),
 
-             ...(this.sendThrough ? { sendThrough: this.sendThrough } : {}),
 
-             ...(this.mux?.enabled ? { mux: this.mux } : {}),
 
-         };
 
-     }
 
-     static fromLink(link) {
 
-         data = link.split('://');
 
-         if (data.length != 2) return null;
 
-         switch (data[0].toLowerCase()) {
 
-             case Protocols.VMess:
 
-                 return this.fromVmessLink(JSON.parse(Base64.decode(data[1])));
 
-             case Protocols.VLESS:
 
-             case Protocols.Trojan:
 
-             case 'ss':
 
-                 return this.fromParamLink(link);
 
-             default:
 
-                 return null;
 
-         }
 
-     }
 
-     static fromVmessLink(json = {}) {
 
-         let stream = new StreamSettings(json.net, json.tls);
 
-         let network = json.net;
 
-         if (network === 'tcp') {
 
-             stream.tcp = new TcpStreamSettings(
 
-                 json.type,
 
-                 json.host ?? '',
 
-                 json.path ?? '');
 
-         } else if (network === 'kcp') {
 
-             stream.kcp = new KcpStreamSettings();
 
-             stream.type = json.type;
 
-             stream.seed = json.path;
 
-         } else if (network === 'ws') {
 
-             stream.ws = new WsStreamSettings(json.path, json.host);
 
-         } else if (network === 'grpc') {
 
-             stream.grpc = new GrpcStreamSettings(json.path, json.authority, json.type == 'multi');
 
-         } else if (network === 'httpupgrade') {
 
-             stream.httpupgrade = new HttpUpgradeStreamSettings(json.path, json.host);
 
-         } else if (network === 'xhttp') {
 
-             stream.xhttp = new xHTTPStreamSettings(json.path, json.host, json.mode);
 
-         }
 
-         if (json.tls && json.tls == 'tls') {
 
-             stream.tls = new TlsStreamSettings(
 
-                 json.sni,
 
-                 json.alpn ? json.alpn.split(',') : [],
 
-                 json.fp,
 
-                 json.allowInsecure);
 
-         }
 
-         const port = json.port * 1;
 
-         return new Outbound(json.ps, Protocols.VMess, new Outbound.VmessSettings(json.add, port, json.id, json.scy), stream);
 
-     }
 
-     static fromParamLink(link) {
 
-         const url = new URL(link);
 
-         let type = url.searchParams.get('type') ?? 'tcp';
 
-         let security = url.searchParams.get('security') ?? 'none';
 
-         let stream = new StreamSettings(type, security);
 
-         let headerType = url.searchParams.get('headerType') ?? undefined;
 
-         let host = url.searchParams.get('host') ?? undefined;
 
-         let path = url.searchParams.get('path') ?? undefined;
 
-         let mode = url.searchParams.get('mode') ?? undefined;
 
-         if (type === 'tcp' || type === 'none') {
 
-             stream.tcp = new TcpStreamSettings(headerType ?? 'none', host, path);
 
-         } else if (type === 'kcp') {
 
-             stream.kcp = new KcpStreamSettings();
 
-             stream.kcp.type = headerType ?? 'none';
 
-             stream.kcp.seed = path;
 
-         } else if (type === 'ws') {
 
-             stream.ws = new WsStreamSettings(path, host);
 
-         } else if (type === 'grpc') {
 
-             stream.grpc = new GrpcStreamSettings(
 
-                 url.searchParams.get('serviceName') ?? '',
 
-                 url.searchParams.get('authority') ?? '',
 
-                 url.searchParams.get('mode') == 'multi');
 
-         } else if (type === 'httpupgrade') {
 
-             stream.httpupgrade = new HttpUpgradeStreamSettings(path, host);
 
-         } else if (type === 'xhttp') {
 
-             stream.xhttp = new xHTTPStreamSettings(path, host, mode);
 
-         }
 
-         if (security == 'tls') {
 
-             let fp = url.searchParams.get('fp') ?? 'none';
 
-             let alpn = url.searchParams.get('alpn');
 
-             let allowInsecure = url.searchParams.get('allowInsecure');
 
-             let sni = url.searchParams.get('sni') ?? '';
 
-             let ech = url.searchParams.get('ech') ?? '';
 
-             stream.tls = new TlsStreamSettings(sni, alpn ? alpn.split(',') : [], fp, allowInsecure == 1, ech);
 
-         }
 
-         if (security == 'reality') {
 
-             let pbk = url.searchParams.get('pbk');
 
-             let fp = url.searchParams.get('fp');
 
-             let sni = url.searchParams.get('sni') ?? '';
 
-             let sid = url.searchParams.get('sid') ?? '';
 
-             let spx = url.searchParams.get('spx') ?? '';
 
-             let pqv = url.searchParams.get('pqv') ?? '';
 
-             stream.reality = new RealityStreamSettings(pbk, fp, sni, sid, spx, pqv);
 
-         }
 
-         const regex = /([^@]+):\/\/([^@]+)@(.+):(\d+)(.*)$/;
 
-         const match = link.match(regex);
 
-         if (!match) return null;
 
-         let [, protocol, userData, address, port,] = match;
 
-         port *= 1;
 
-         if (protocol == 'ss') {
 
-             protocol = 'shadowsocks';
 
-             userData = atob(userData).split(':');
 
-         }
 
-         var settings;
 
-         switch (protocol) {
 
-             case Protocols.VLESS:
 
-                 settings = new Outbound.VLESSSettings(address, port, userData, url.searchParams.get('flow') ?? '', url.searchParams.get('encryption') ?? 'none');
 
-                 break;
 
-             case Protocols.Trojan:
 
-                 settings = new Outbound.TrojanSettings(address, port, userData);
 
-                 break;
 
-             case Protocols.Shadowsocks:
 
-                 let method = userData.splice(0, 1)[0];
 
-                 settings = new Outbound.ShadowsocksSettings(address, port, userData.join(":"), method, true);
 
-                 break;
 
-             default:
 
-                 return null;
 
-         }
 
-         let remark = decodeURIComponent(url.hash);
 
-         // Remove '#' from url.hash
 
-         remark = remark.length > 0 ? remark.substring(1) : 'out-' + protocol + '-' + port;
 
-         return new Outbound(remark, protocol, settings, stream);
 
-     }
 
- }
 
- Outbound.Settings = class extends CommonClass {
 
-     constructor(protocol) {
 
-         super();
 
-         this.protocol = protocol;
 
-     }
 
-     static getSettings(protocol) {
 
-         switch (protocol) {
 
-             case Protocols.Freedom: return new Outbound.FreedomSettings();
 
-             case Protocols.Blackhole: return new Outbound.BlackholeSettings();
 
-             case Protocols.DNS: return new Outbound.DNSSettings();
 
-             case Protocols.VMess: return new Outbound.VmessSettings();
 
-             case Protocols.VLESS: return new Outbound.VLESSSettings();
 
-             case Protocols.Trojan: return new Outbound.TrojanSettings();
 
-             case Protocols.Shadowsocks: return new Outbound.ShadowsocksSettings();
 
-             case Protocols.Socks: return new Outbound.SocksSettings();
 
-             case Protocols.HTTP: return new Outbound.HttpSettings();
 
-             case Protocols.Wireguard: return new Outbound.WireguardSettings();
 
-             default: return null;
 
-         }
 
-     }
 
-     static fromJson(protocol, json) {
 
-         switch (protocol) {
 
-             case Protocols.Freedom: return Outbound.FreedomSettings.fromJson(json);
 
-             case Protocols.Blackhole: return Outbound.BlackholeSettings.fromJson(json);
 
-             case Protocols.DNS: return Outbound.DNSSettings.fromJson(json);
 
-             case Protocols.VMess: return Outbound.VmessSettings.fromJson(json);
 
-             case Protocols.VLESS: return Outbound.VLESSSettings.fromJson(json);
 
-             case Protocols.Trojan: return Outbound.TrojanSettings.fromJson(json);
 
-             case Protocols.Shadowsocks: return Outbound.ShadowsocksSettings.fromJson(json);
 
-             case Protocols.Socks: return Outbound.SocksSettings.fromJson(json);
 
-             case Protocols.HTTP: return Outbound.HttpSettings.fromJson(json);
 
-             case Protocols.Wireguard: return Outbound.WireguardSettings.fromJson(json);
 
-             default: return null;
 
-         }
 
-     }
 
-     toJson() {
 
-         return {};
 
-     }
 
- };
 
- Outbound.FreedomSettings = class extends CommonClass {
 
-     constructor(
 
-         domainStrategy = '',
 
-         redirect = '',
 
-         fragment = {},
 
-         noises = []
 
-     ) {
 
-         super();
 
-         this.domainStrategy = domainStrategy;
 
-         this.redirect = redirect;
 
-         this.fragment = fragment;
 
-         this.noises = noises;
 
-     }
 
-     addNoise() {
 
-         this.noises.push(new Outbound.FreedomSettings.Noise());
 
-     }
 
-     delNoise(index) {
 
-         this.noises.splice(index, 1);
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new Outbound.FreedomSettings(
 
-             json.domainStrategy,
 
-             json.redirect,
 
-             json.fragment ? Outbound.FreedomSettings.Fragment.fromJson(json.fragment) : undefined,
 
-             json.noises ? json.noises.map(noise => Outbound.FreedomSettings.Noise.fromJson(noise)) : undefined,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             domainStrategy: ObjectUtil.isEmpty(this.domainStrategy) ? undefined : this.domainStrategy,
 
-             redirect: ObjectUtil.isEmpty(this.redirect) ? undefined : this.redirect,
 
-             fragment: Object.keys(this.fragment).length === 0 ? undefined : this.fragment,
 
-             noises: this.noises.length === 0 ? undefined : Outbound.FreedomSettings.Noise.toJsonArray(this.noises),
 
-         };
 
-     }
 
- };
 
- Outbound.FreedomSettings.Fragment = class extends CommonClass {
 
-     constructor(
 
-         packets = '1-3',
 
-         length = '',
 
-         interval = '',
 
-         maxSplit = ''
 
-     ) {
 
-         super();
 
-         this.packets = packets;
 
-         this.length = length;
 
-         this.interval = interval;
 
-         this.maxSplit = maxSplit;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new Outbound.FreedomSettings.Fragment(
 
-             json.packets,
 
-             json.length,
 
-             json.interval,
 
-             json.maxSplit
 
-         );
 
-     }
 
- };
 
- Outbound.FreedomSettings.Noise = class extends CommonClass {
 
-     constructor(
 
-         type = 'rand',
 
-         packet = '10-20',
 
-         delay = '10-16',
 
-         applyTo = 'ip'
 
-     ) {
 
-         super();
 
-         this.type = type;
 
-         this.packet = packet;
 
-         this.delay = delay;
 
-         this.applyTo = applyTo;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new Outbound.FreedomSettings.Noise(
 
-             json.type,
 
-             json.packet,
 
-             json.delay,
 
-             json.applyTo
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             type: this.type,
 
-             packet: this.packet,
 
-             delay: this.delay,
 
-             applyTo: this.applyTo
 
-         };
 
-     }
 
- };
 
- Outbound.BlackholeSettings = class extends CommonClass {
 
-     constructor(type) {
 
-         super();
 
-         this.type = type;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new Outbound.BlackholeSettings(
 
-             json.response ? json.response.type : undefined,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             response: ObjectUtil.isEmpty(this.type) ? undefined : { type: this.type },
 
-         };
 
-     }
 
- };
 
- Outbound.DNSSettings = class extends CommonClass {
 
-     constructor(
 
-         network = 'udp',
 
-         address = '',
 
-         port = 53,
 
-         nonIPQuery = 'reject',
 
-         blockTypes = []
 
-     ) {
 
-         super();
 
-         this.network = network;
 
-         this.address = address;
 
-         this.port = port;
 
-         this.nonIPQuery = nonIPQuery;
 
-         this.blockTypes = blockTypes;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new Outbound.DNSSettings(
 
-             json.network,
 
-             json.address,
 
-             json.port,
 
-             json.nonIPQuery,
 
-             json.blockTypes,
 
-         );
 
-     }
 
- };
 
- Outbound.VmessSettings = class extends CommonClass {
 
-     constructor(address, port, id, security) {
 
-         super();
 
-         this.address = address;
 
-         this.port = port;
 
-         this.id = id;
 
-         this.security = security;
 
-     }
 
-     static fromJson(json = {}) {
 
-         if (!ObjectUtil.isArrEmpty(json.vnext)) {
 
-             const v = json.vnext[0] || {};
 
-             const u = ObjectUtil.isArrEmpty(v.users) ? {} : v.users[0];
 
-             return new Outbound.VmessSettings(
 
-                 v.address,
 
-                 v.port,
 
-                 u.id,
 
-                 u.security,
 
-             );
 
-         }
 
-     }
 
-     toJson() {
 
-         return {
 
-             vnext: [{
 
-                 address: this.address,
 
-                 port: this.port,
 
-                 users: [{
 
-                     id: this.id,
 
-                     security: this.security
 
-                 }]
 
-             }]
 
-         };
 
-     }
 
- };
 
- Outbound.VLESSSettings = class extends CommonClass {
 
-     constructor(address, port, id, flow, encryption) {
 
-         super();
 
-         this.address = address;
 
-         this.port = port;
 
-         this.id = id;
 
-         this.flow = flow;
 
-         this.encryption = encryption;
 
-     }
 
-     static fromJson(json = {}) {
 
-         if (ObjectUtil.isEmpty(json.address) || ObjectUtil.isEmpty(json.port)) return new Outbound.VLESSSettings();
 
-         return new Outbound.VLESSSettings(
 
-             json.address,
 
-             json.port,
 
-             json.id,
 
-             json.flow,
 
-             json.encryption
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             address: this.address,
 
-             port: this.port,
 
-             id: this.id,
 
-             flow: this.flow,
 
-             encryption: this.encryption,
 
-         };
 
-     }
 
- };
 
- Outbound.TrojanSettings = class extends CommonClass {
 
-     constructor(address, port, password) {
 
-         super();
 
-         this.address = address;
 
-         this.port = port;
 
-         this.password = password;
 
-     }
 
-     static fromJson(json = {}) {
 
-         if (ObjectUtil.isArrEmpty(json.servers)) return new Outbound.TrojanSettings();
 
-         return new Outbound.TrojanSettings(
 
-             json.servers[0].address,
 
-             json.servers[0].port,
 
-             json.servers[0].password,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             servers: [{
 
-                 address: this.address,
 
-                 port: this.port,
 
-                 password: this.password,
 
-             }],
 
-         };
 
-     }
 
- };
 
- Outbound.ShadowsocksSettings = class extends CommonClass {
 
-     constructor(address, port, password, method, uot, UoTVersion) {
 
-         super();
 
-         this.address = address;
 
-         this.port = port;
 
-         this.password = password;
 
-         this.method = method;
 
-         this.uot = uot;
 
-         this.UoTVersion = UoTVersion;
 
-     }
 
-     static fromJson(json = {}) {
 
-         let servers = json.servers;
 
-         if (ObjectUtil.isArrEmpty(servers)) servers = [{}];
 
-         return new Outbound.ShadowsocksSettings(
 
-             servers[0].address,
 
-             servers[0].port,
 
-             servers[0].password,
 
-             servers[0].method,
 
-             servers[0].uot,
 
-             servers[0].UoTVersion,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             servers: [{
 
-                 address: this.address,
 
-                 port: this.port,
 
-                 password: this.password,
 
-                 method: this.method,
 
-                 uot: this.uot,
 
-                 UoTVersion: this.UoTVersion,
 
-             }],
 
-         };
 
-     }
 
- };
 
- Outbound.SocksSettings = class extends CommonClass {
 
-     constructor(address, port, user, pass) {
 
-         super();
 
-         this.address = address;
 
-         this.port = port;
 
-         this.user = user;
 
-         this.pass = pass;
 
-     }
 
-     static fromJson(json = {}) {
 
-         let servers = json.servers;
 
-         if (ObjectUtil.isArrEmpty(servers)) servers = [{ users: [{}] }];
 
-         return new Outbound.SocksSettings(
 
-             servers[0].address,
 
-             servers[0].port,
 
-             ObjectUtil.isArrEmpty(servers[0].users) ? '' : servers[0].users[0].user,
 
-             ObjectUtil.isArrEmpty(servers[0].users) ? '' : servers[0].users[0].pass,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             servers: [{
 
-                 address: this.address,
 
-                 port: this.port,
 
-                 users: ObjectUtil.isEmpty(this.user) ? [] : [{ user: this.user, pass: this.pass }],
 
-             }],
 
-         };
 
-     }
 
- };
 
- Outbound.HttpSettings = class extends CommonClass {
 
-     constructor(address, port, user, pass) {
 
-         super();
 
-         this.address = address;
 
-         this.port = port;
 
-         this.user = user;
 
-         this.pass = pass;
 
-     }
 
-     static fromJson(json = {}) {
 
-         let servers = json.servers;
 
-         if (ObjectUtil.isArrEmpty(servers)) servers = [{ users: [{}] }];
 
-         return new Outbound.HttpSettings(
 
-             servers[0].address,
 
-             servers[0].port,
 
-             ObjectUtil.isArrEmpty(servers[0].users) ? '' : servers[0].users[0].user,
 
-             ObjectUtil.isArrEmpty(servers[0].users) ? '' : servers[0].users[0].pass,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             servers: [{
 
-                 address: this.address,
 
-                 port: this.port,
 
-                 users: ObjectUtil.isEmpty(this.user) ? [] : [{ user: this.user, pass: this.pass }],
 
-             }],
 
-         };
 
-     }
 
- };
 
- Outbound.WireguardSettings = class extends CommonClass {
 
-     constructor(
 
-         mtu = 1420,
 
-         secretKey = '',
 
-         address = [''],
 
-         workers = 2,
 
-         domainStrategy = '',
 
-         reserved = '',
 
-         peers = [new Outbound.WireguardSettings.Peer()],
 
-         noKernelTun = false,
 
-     ) {
 
-         super();
 
-         this.mtu = mtu;
 
-         this.secretKey = secretKey;
 
-         this.pubKey = secretKey.length > 0 ? Wireguard.generateKeypair(secretKey).publicKey : '';
 
-         this.address = Array.isArray(address) ? address.join(',') : address;
 
-         this.workers = workers;
 
-         this.domainStrategy = domainStrategy;
 
-         this.reserved = Array.isArray(reserved) ? reserved.join(',') : reserved;
 
-         this.peers = peers;
 
-         this.noKernelTun = noKernelTun;
 
-     }
 
-     addPeer() {
 
-         this.peers.push(new Outbound.WireguardSettings.Peer());
 
-     }
 
-     delPeer(index) {
 
-         this.peers.splice(index, 1);
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new Outbound.WireguardSettings(
 
-             json.mtu,
 
-             json.secretKey,
 
-             json.address,
 
-             json.workers,
 
-             json.domainStrategy,
 
-             json.reserved,
 
-             json.peers.map(peer => Outbound.WireguardSettings.Peer.fromJson(peer)),
 
-             json.noKernelTun,
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             mtu: this.mtu ?? undefined,
 
-             secretKey: this.secretKey,
 
-             address: this.address ? this.address.split(",") : [],
 
-             workers: this.workers ?? undefined,
 
-             domainStrategy: WireguardDomainStrategy.includes(this.domainStrategy) ? this.domainStrategy : undefined,
 
-             reserved: this.reserved ? this.reserved.split(",").map(Number) : undefined,
 
-             peers: Outbound.WireguardSettings.Peer.toJsonArray(this.peers),
 
-             noKernelTun: this.noKernelTun,
 
-         };
 
-     }
 
- };
 
- Outbound.WireguardSettings.Peer = class extends CommonClass {
 
-     constructor(
 
-         publicKey = '',
 
-         psk = '',
 
-         allowedIPs = ['0.0.0.0/0', '::/0'],
 
-         endpoint = '',
 
-         keepAlive = 0
 
-     ) {
 
-         super();
 
-         this.publicKey = publicKey;
 
-         this.psk = psk;
 
-         this.allowedIPs = allowedIPs;
 
-         this.endpoint = endpoint;
 
-         this.keepAlive = keepAlive;
 
-     }
 
-     static fromJson(json = {}) {
 
-         return new Outbound.WireguardSettings.Peer(
 
-             json.publicKey,
 
-             json.preSharedKey,
 
-             json.allowedIPs,
 
-             json.endpoint,
 
-             json.keepAlive
 
-         );
 
-     }
 
-     toJson() {
 
-         return {
 
-             publicKey: this.publicKey,
 
-             preSharedKey: this.psk.length > 0 ? this.psk : undefined,
 
-             allowedIPs: this.allowedIPs ? this.allowedIPs : undefined,
 
-             endpoint: this.endpoint,
 
-             keepAlive: this.keepAlive ?? undefined,
 
-         };
 
-     }
 
- };
 
 
  |