import { ExtendedSocket } from 'extendedsocket' ; export class ActiveConnections { public static Singleton ( ) { if ( ActiveConnections . instance == null ) { ActiveConnections . instance = new ActiveConnections ( ) ; } return ActiveConnections . instance ; } private static instance : ActiveConnections ; private connections : ExtendedSocket [ ] ; private constructor ( ) { this . connections = [ ] ; } public FindByOwnerId ( ownerId ) { for ( const conn of this . connections ) { if ( conn . session . user . id === ownerId ) { return conn ; } } return null ; } public FindByPlayerName ( targetName ) { for ( const conn of this . connections ) { if ( conn . session . user . playername === targetName ) { return conn ; } } return null ; } public Add ( conn ) { this . connections . push ( conn ) ; } public Remove ( conn ) { this . connections . splice ( this . connections . indexOf ( conn ) , 1 ) ; } }