tunnel/source/server/relay/TunnelRegistry.ts

29 lines
528 B
TypeScript

import { WebSocket } from 'ws';
class TunnelRegistry
{
private sockets = new Map<string, WebSocket>();
register( tunnelId: string, ws: WebSocket ): void
{
this.sockets.set( tunnelId, ws );
}
unregister( tunnelId: string ): void
{
this.sockets.delete( tunnelId );
}
get( tunnelId: string ): WebSocket | undefined
{
return this.sockets.get( tunnelId );
}
isActive( tunnelId: string ): boolean
{
return this.sockets.has( tunnelId );
}
}
export const registry = new TunnelRegistry();