import { Service , Inject } from 'typedi' ; import winston from 'winston' ; import { Connection } from 'sockjs' ; import { SockMessage } from '../data/sock' ; @ Service ( ) export default class SockService { private clients : Connection [ ] = [ ] ; constructor ( @ Inject ( 'logger' ) private logger ) { } public getClients ( ) { return this . clients ; } public addClient ( conn ) { if ( this . clients . indexOf ( conn ) === - 1 ) { this . clients . push ( conn ) ; } } public removeClient ( conn ) { const index = this . clients . indexOf ( conn ) ; if ( index !== - 1 ) { this . clients . splice ( index , 1 ) ; } } public sendMessage ( msg ) { this . clients . forEach ( ( x ) => { x . write ( JSON . stringify ( msg ) ) ; } ) ; } }