Files
op-packages/luci-app-hijpass/ts-src/core/xray/protocols/protocol.ts
T

24 lines
645 B
TypeScript

import type { ProxyNode } from '../../../module/luci'
import type { Outbound } from '../models'
export interface XrayProtocol {
readonly type: string
build(config: ProxyNode): Outbound
}
export class XrayProtocolRegistry {
private readonly protocols = new Map<string, XrayProtocol>()
register(p: XrayProtocol): void {
this.protocols.set(p.type, p)
}
build(type: string, config: ProxyNode): Outbound {
const p = this.protocols.get(type)
if (!p) throw new Error(`Unsupported xray protocol: ${type}`)
return p.build(config)
}
}
export const xrayRegistry = new XrayProtocolRegistry()