member_webapp/@overflow/discovery/service/discovery.service.ts
crusader 4ff5eead18 ing
2018-05-31 21:04:52 +09:00

63 lines
2.2 KiB
TypeScript

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { RPCService, RPCSubscribeService } from '@loafer/ng-rpc';
import {
DiscoverZone as MDDiscoverZone,
DiscoverHost as MDDiscoverHost,
DiscoverPort as MDDiscoverPort,
DiscoverService as MDDiscoverService,
Zone,
Host,
Port,
Service,
} from '@overflow/commons-typescript/model/discovery';
import { DiscoverySubject, DiscoveryNotify } from '../core/discovery-subject';
import * as DiscoverStore from '../store/discover';
import { DiscoverySubscriber } from '../subscriber/discovery.subscriber';
@Injectable()
export class DiscoveryService {
public constructor(
private discoverySubscriber: DiscoverySubscriber,
private rpcService: RPCService,
) {
}
public discoverZone(probeID: string, discoverZone: MDDiscoverZone): Observable<DiscoveryNotify> {
const discoverySubject: DiscoverySubject = new DiscoverySubject();
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
this.rpcService.send('DiscoveryService.discoverZone', probeID, discoverZone);
return discoverySubject;
}
public discoverHost(probeID: string, zone: Zone, discoverHost: MDDiscoverHost): Observable<DiscoveryNotify> {
const discoverySubject: DiscoverySubject = new DiscoverySubject();
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
this.rpcService.send('DiscoveryService.discoverHost', probeID, zone, discoverHost);
return discoverySubject;
}
public discoverPort(probeID: string, host: Host, discoverPort: MDDiscoverPort): Observable<DiscoveryNotify> {
const discoverySubject: DiscoverySubject = new DiscoverySubject();
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
this.rpcService.send('DiscoveryService.discoverPort', probeID, host, discoverPort);
return discoverySubject;
}
public discoverService(probeID: string, port: Port, discoverService: MDDiscoverService): Observable<DiscoveryNotify> {
const discoverySubject: DiscoverySubject = new DiscoverySubject();
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
this.rpcService.send('DiscoveryService.discoverService', probeID, port, discoverService);
return discoverySubject;
}
}