blob: 89a860769fccad55a0d7436656da89173fb969b5 [file] [log] [blame]
Matteo Scandolo035c5932016-12-14 09:55:15 -08001import * as io from 'socket.io-client';
2import {Subject, Observable} from 'rxjs/Rx';
3import {AppConfig} from '../../config/app.config';
4
5export interface IWSEvent {
6 model: string;
7 msg: {
8 changed_fields: string[],
9 object?: any,
10 pk?: number
11 };
12}
13
14export interface IWSEventService {
15 list(): Observable<IWSEvent>;
16}
17
18export class WebSocketEvent {
19 private _events: Subject<IWSEvent> = new Subject<IWSEvent>();
20 private socket;
21 constructor() {
Matteo Scandolo035c5932016-12-14 09:55:15 -080022 this.socket = io(AppConfig.websocketClient);
23 this.socket.on('event', (data: IWSEvent): void => {
24 this._events.next(data);
25 });
26 }
27 list() {
28 return this._events.asObservable();
29 }
30}