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

56 lines
1.6 KiB
TypeScript
Raw Normal View History

2018-05-10 10:54:47 +00:00
import { Injectable } from '@angular/core';
2018-05-31 13:11:23 +00:00
import { Observable, Subject } from 'rxjs';
2018-05-10 10:54:47 +00:00
2018-05-24 06:44:13 +00:00
import { RPCSubscriber } from '@loafer/ng-rpc';
import { LoggerService } from '@loafer/ng-logger';
2018-05-10 10:54:47 +00:00
2018-05-31 07:38:44 +00:00
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
2018-05-10 10:54:47 +00:00
2018-05-31 07:38:44 +00:00
import * as NoAuthProbeConnectingStore from '../store/connecting';
2018-05-10 10:54:47 +00:00
2018-05-31 13:11:23 +00:00
export interface NoAuthProbeNotify {
method: string;
params: NoAuthProbe;
}
export class NoAuthProbeSubscriberSubject extends Subject<NoAuthProbeNotify> {
}
2018-05-10 10:54:47 +00:00
@Injectable()
export class NoAuthProbeSubscriber {
2018-05-31 13:11:23 +00:00
private noAuthProbeSubscriberSubject: NoAuthProbeSubscriberSubject;
2018-05-10 10:54:47 +00:00
public constructor(
private loggerService: LoggerService,
) {
2018-05-31 13:11:23 +00:00
this.noAuthProbeSubscriberSubject = null;
}
public observable(): Observable<NoAuthProbeNotify> {
if (null === this.noAuthProbeSubscriberSubject) {
this.noAuthProbeSubscriberSubject = new NoAuthProbeSubscriberSubject();
}
return this.noAuthProbeSubscriberSubject.asObservable();
}
private publish(method: string, params: any): void {
this.noAuthProbeSubscriberSubject.next({ method: method, params: params });
2018-05-10 10:54:47 +00:00
}
@RPCSubscriber({method: 'NoAuthProbeService.onConnect'})
public onConnect(noAuthProbe: NoAuthProbe): void {
this.loggerService.debug('NoAuthProbeService.onConnect noAuthProbe:', noAuthProbe);
2018-05-31 13:11:23 +00:00
this.publish('NoAuthProbeService.onConnect', noAuthProbe);
2018-05-10 10:54:47 +00:00
}
@RPCSubscriber({method: 'NoAuthProbeService.onDisconnect'})
public onDisconnect(noAuthProbe: NoAuthProbe): void {
this.loggerService.debug('NoAuthProbeService.onDisconnect noAuthProbe:', noAuthProbe);
2018-05-31 13:11:23 +00:00
this.publish('NoAuthProbeService.onDisconnect', noAuthProbe);
2018-05-10 10:54:47 +00:00
}
}