import { EnvironmentService } from './environment.service' ; import { Subject } from 'rxjs/Subject' ; import { PlatformService } from './platform.service' ; import { Injectable } from '@angular/core' ; import { WebSocketSubject , WebSocketSubjectConfig } from 'rxjs/observable/dom/WebSocketSubject' ; @ Injectable ( ) export class WebSocketService { private readonly source = this . ps . isBrowser && typeof window !== 'undefined' && ( window as any ) . WebSocket && this . es . config . endpoints && this . es . config . endpoints . websocketServer ? new WebSocketSubject ( { url : this . es . config . endpoints . websocketServer } as WebSocketSubjectConfig ) : new Subject ( ) ; public readonly messageBus$ = this . source . asObservable ( ) ; constructor ( private ps , private es ) { } send ( obj ) { this . source . next ( JSON . stringify ( obj ) ) ; } }