blob: 33a0c39e0a4d9ea4610c49b20e8dd704729adb1d [file] [log] [blame]
Matteo Scandolo63e43eb2016-12-14 14:18:53 -08001/// <reference path="../../../../typings/index.d.ts"/>
2
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08003import {Subject, Observable} from 'rxjs/Rx';
Matteo Scandolo63e43eb2016-12-14 14:18:53 -08004import {IWSEvent, IWSEventService} from '../websocket/global';
5
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08006export interface IStoreService {
7 query(): Observable<any>;
8}
9
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080010export class SynchronizerStore {
11 static $inject = ['WebSocket'];
12 private _notifications: Subject<IWSEvent> = new Subject();
13 constructor(
14 private webSocket: IWSEventService
15 ) {
16 this.webSocket.list()
17 .filter((e: IWSEvent) => {
18 return e.msg.changed_fields.indexOf('backend_status') > -1;
19 })
20 .subscribe(
21 (event: IWSEvent) => {
22 this._notifications.next(event);
23 }
24 );
25 }
26
27 query() {
28 return this._notifications.asObservable();
29 }
30}