member_webapp/@overflow/probe/subscriber/probe.subscriber.ts
crusader c47bb4fad5 ing
2018-06-04 19:03:59 +09:00

54 lines
1.4 KiB
TypeScript

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,
) {
this.probeSubscriberSubject = null;
}
public observable(): Observable<ProbeNotify> {
if (null === this.probeSubscriberSubject) {
this.probeSubscriberSubject = new ProbeSubscriberSubject();
}
return this.probeSubscriberSubject.asObservable();
}
private publish(method: string, params: any): void {
this.probeSubscriberSubject.next({ method: method, params: params });
}
@RPCSubscriber({method: 'ProbeService.onConnect'})
public onConnect(probe: Probe): void {
this.loggerService.debug('ProbeService.onConnect probe:', probe);
this.publish('ProbeService.onConnect', probe);
}
@RPCSubscriber({method: 'ProbeService.onDisconnect'})
public onDisconnect(probe: Probe): void {
this.loggerService.debug('ProbeService.onDisconnect noAuthProbe:', probe);
this.publish('ProbeService.onDisconnect', probe);
}
}