Matteo Scandolo | 0f77c50 | 2016-12-06 16:46:00 -0800 | [diff] [blame^] | 1 | /// <reference path="../../../../typings/index.d.ts"/> |
| 2 | |
| 3 | import {Injectable} from '@angular/core'; |
| 4 | import {BehaviorSubject} from 'rxjs/Rx'; |
| 5 | import * as io from 'socket.io-client'; |
| 6 | import {AppConfig} from '../../config/app.config'; |
| 7 | import {IWSEvent} from '../../interfaces/ws.interface'; |
| 8 | |
| 9 | @Injectable() |
| 10 | export class GlobalEvent { |
| 11 | private _events: BehaviorSubject<IWSEvent> = new BehaviorSubject<IWSEvent>({ |
| 12 | model: 'XOS', |
| 13 | msg: { |
| 14 | changed_fields: [] |
| 15 | } |
| 16 | }); |
| 17 | private socket; |
| 18 | constructor() { |
| 19 | this.socket = io(AppConfig.websocketClient); |
| 20 | this.socket.on('event', (data: IWSEvent) => { |
| 21 | this._events.next(data); |
| 22 | }); |
| 23 | } |
| 24 | |
| 25 | list() { |
| 26 | return this._events.asObservable(); |
| 27 | } |
| 28 | |
| 29 | } |