blob: 46bfbe1a422868bca69169f11cd7f35a37a23dc1 [file] [log] [blame]
Matteo Scandolo0f77c502016-12-06 16:46:00 -08001/// <reference path="../../../../typings/index.d.ts"/>
2
3import {Injectable} from '@angular/core';
Matteo Scandolo40f8fa92016-12-07 09:21:35 -08004import {Subject} from 'rxjs/Rx';
Matteo Scandolo0f77c502016-12-06 16:46:00 -08005import * as io from 'socket.io-client';
6import {AppConfig} from '../../config/app.config';
7import {IWSEvent} from '../../interfaces/ws.interface';
8
9@Injectable()
10export class GlobalEvent {
Matteo Scandolo40f8fa92016-12-07 09:21:35 -080011 private _events: Subject<IWSEvent> = new Subject<IWSEvent>();
Matteo Scandolo0f77c502016-12-06 16:46:00 -080012 private socket;
13 constructor() {
14 this.socket = io(AppConfig.websocketClient);
Matteo Scandolo40f8fa92016-12-07 09:21:35 -080015 this.socket.on('event', (data: IWSEvent): void => {
16 console.log('event', data);
Matteo Scandolo0f77c502016-12-06 16:46:00 -080017 this._events.next(data);
18 });
19 }
Matteo Scandolo0f77c502016-12-06 16:46:00 -080020 list() {
21 return this._events.asObservable();
22 }
Matteo Scandolo0f77c502016-12-06 16:46:00 -080023}