blob: aa25cc0f25444462a09c9fd879ad8a1d20bbe9bc [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) => {
Matteo Scandolo4e870232017-01-30 13:43:05 -080018 if (!e.msg || !e.msg.changed_fields) {
19 return false;
20 }
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080021 return e.msg.changed_fields.indexOf('backend_status') > -1;
22 })
23 .subscribe(
24 (event: IWSEvent) => {
25 this._notifications.next(event);
26 }
27 );
28 }
29
30 query() {
31 return this._notifications.asObservable();
32 }
33}