import io from 'socket.io-client' ; import { ChatMessage } from './types' ; import { fromEvent , Observable } from 'rxjs' ; export class SocketService { private socket : SocketIOClient . Socket = { } as SocketIOClient . Socket ; public init ( ) { console . log ( 'initiating socket service' ) ; this . socket = io ( 'localhost:8080' ) ; return this ; } public send ( message ) { console . log ( 'emitting message: ' + message ) ; this . socket . emit ( 'message' , message ) ; } public onMessage ( ) { return fromEvent ( this . socket , 'message' ) ; } public disconnect ( ) { this . socket . disconnect ( ) ; } }