2018-04-06 11:02:18 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
2018-05-31 12:04:52 +00:00
|
|
|
|
|
|
|
import { RPCService, RPCSubscribeService } from '@loafer/ng-rpc';
|
2018-04-06 11:02:18 +00:00
|
|
|
import {
|
2018-04-27 16:29:54 +00:00
|
|
|
DiscoverZone as MDDiscoverZone,
|
|
|
|
DiscoverHost as MDDiscoverHost,
|
|
|
|
DiscoverPort as MDDiscoverPort,
|
|
|
|
DiscoverService as MDDiscoverService,
|
2018-04-06 11:02:18 +00:00
|
|
|
Zone,
|
|
|
|
Host,
|
|
|
|
Port,
|
|
|
|
Service,
|
2018-05-02 07:23:35 +00:00
|
|
|
} from '@overflow/commons-typescript/model/discovery';
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-05-31 12:04:52 +00:00
|
|
|
import { DiscoverySubject, DiscoveryNotify } from '../core/discovery-subject';
|
|
|
|
import * as DiscoverStore from '../store/discover';
|
|
|
|
import { DiscoverySubscriber } from '../subscriber/discovery.subscriber';
|
|
|
|
|
2018-04-06 11:02:18 +00:00
|
|
|
@Injectable()
|
|
|
|
export class DiscoveryService {
|
|
|
|
|
|
|
|
public constructor(
|
2018-05-31 12:04:52 +00:00
|
|
|
private discoverySubscriber: DiscoverySubscriber,
|
2018-04-06 11:02:18 +00:00
|
|
|
private rpcService: RPCService,
|
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:04:52 +00:00
|
|
|
public discoverZone(probeID: string, discoverZone: MDDiscoverZone): Observable<DiscoveryNotify> {
|
|
|
|
const discoverySubject: DiscoverySubject = new DiscoverySubject();
|
|
|
|
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
|
|
|
|
|
2018-04-27 16:29:54 +00:00
|
|
|
this.rpcService.send('DiscoveryService.discoverZone', probeID, discoverZone);
|
2018-05-31 12:04:52 +00:00
|
|
|
|
|
|
|
return discoverySubject;
|
2018-04-06 11:02:18 +00:00
|
|
|
}
|
2018-05-31 12:04:52 +00:00
|
|
|
public discoverHost(probeID: string, zone: Zone, discoverHost: MDDiscoverHost): Observable<DiscoveryNotify> {
|
|
|
|
const discoverySubject: DiscoverySubject = new DiscoverySubject();
|
|
|
|
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
|
|
|
|
|
2018-04-27 16:29:54 +00:00
|
|
|
this.rpcService.send('DiscoveryService.discoverHost', probeID, zone, discoverHost);
|
2018-05-31 12:04:52 +00:00
|
|
|
|
|
|
|
return discoverySubject;
|
2018-04-06 11:02:18 +00:00
|
|
|
}
|
2018-05-31 12:04:52 +00:00
|
|
|
public discoverPort(probeID: string, host: Host, discoverPort: MDDiscoverPort): Observable<DiscoveryNotify> {
|
|
|
|
const discoverySubject: DiscoverySubject = new DiscoverySubject();
|
|
|
|
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
|
|
|
|
|
2018-04-27 16:29:54 +00:00
|
|
|
this.rpcService.send('DiscoveryService.discoverPort', probeID, host, discoverPort);
|
2018-05-31 12:04:52 +00:00
|
|
|
|
|
|
|
return discoverySubject;
|
2018-04-06 11:02:18 +00:00
|
|
|
}
|
2018-05-31 12:04:52 +00:00
|
|
|
public discoverService(probeID: string, port: Port, discoverService: MDDiscoverService): Observable<DiscoveryNotify> {
|
|
|
|
const discoverySubject: DiscoverySubject = new DiscoverySubject();
|
|
|
|
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
|
|
|
|
|
2018-04-27 16:29:54 +00:00
|
|
|
this.rpcService.send('DiscoveryService.discoverService', probeID, port, discoverService);
|
2018-05-31 12:04:52 +00:00
|
|
|
|
|
|
|
return discoverySubject;
|
2018-04-06 11:02:18 +00:00
|
|
|
}
|
|
|
|
}
|