member_webapp/@overflow/probe/subscriber/probe.subscriber.ts

51 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2018-06-04 10:03:59 +00:00
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { RPCSubscriber } from '@loafer/ng-rpc';
import { LoggerService } from '@loafer/ng-logger';
import { Probe } from '@overflow/commons-typescript/model/probe';
export interface ProbeNotify {
method: string;
params: Probe;
}
export class ProbeSubscriberSubject extends Subject<ProbeNotify> {
}
@Injectable()
export class ProbeSubscriber {
private probeSubscriberSubject: ProbeSubscriberSubject;
public constructor(
private loggerService: LoggerService,
) {
2018-06-20 07:00:24 +00:00
this.probeSubscriberSubject = new ProbeSubscriberSubject();
2018-06-04 10:03:59 +00:00
}
public observable(): Observable<ProbeNotify> {
return this.probeSubscriberSubject.asObservable();
}
private publish(method: string, params: any): void {
this.probeSubscriberSubject.next({ method: method, params: params });
}
2018-06-20 07:00:24 +00:00
@RPCSubscriber({ method: 'ProbeService.onConnect' })
2018-06-04 10:03:59 +00:00
public onConnect(probe: Probe): void {
this.loggerService.debug('ProbeService.onConnect probe:', probe);
this.publish('ProbeService.onConnect', probe);
}
2018-06-20 07:00:24 +00:00
@RPCSubscriber({ method: 'ProbeService.onDisconnect' })
2018-06-04 10:03:59 +00:00
public onDisconnect(probe: Probe): void {
this.loggerService.debug('ProbeService.onDisconnect noAuthProbe:', probe);
this.publish('ProbeService.onDisconnect', probe);
}
}