blob: ee62c120df5e6255eb7074666c4f31567c122540 [file] [log] [blame]
Matteo Scandolo0f77c502016-12-06 16:46:00 -08001/// <reference path="../../../../typings/index.d.ts"/>
2
3import {Injectable} from '@angular/core';
4import {BehaviorSubject} from 'rxjs/Rx';
5import * as io from 'socket.io-client';
6import {AppConfig} from '../../config/app.config';
7import {IWSEvent} from '../../interfaces/ws.interface';
8
9@Injectable()
10export 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}