Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 1 | /// <reference path="../../../../typings/index.d.ts"/> |
| 2 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 3 | import {Subject, Observable} from 'rxjs/Rx'; |
Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 4 | import {IWSEvent, IWSEventService} from '../websocket/global'; |
| 5 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 6 | export interface IStoreService { |
| 7 | query(): Observable<any>; |
| 8 | } |
| 9 | |
Matteo Scandolo | 63e43eb | 2016-12-14 14:18:53 -0800 | [diff] [blame] | 10 | export 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 | } |