mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-10 18:34:18 +08:00
24 lines
667 B
TypeScript
24 lines
667 B
TypeScript
import type { ProxyNode } from '../../../module/luci'
|
|
import type { Outbound } from '../models'
|
|
|
|
export interface SingBoxProtocol {
|
|
readonly type: string
|
|
build(config: ProxyNode): Outbound
|
|
}
|
|
|
|
export class SingBoxProtocolRegistry {
|
|
private readonly protocols = new Map<string, SingBoxProtocol>()
|
|
|
|
register(p: SingBoxProtocol): 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 sing-box protocol: ${type}`)
|
|
return p.build(config)
|
|
}
|
|
}
|
|
|
|
export const singboxRegistry = new SingBoxProtocolRegistry()
|