UNPKG

raas-client

Version:
56 lines 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const raas_core_1 = require("raas-core"); const common_1 = require("./common"); class Discovery { constructor(connection, emitter) { this.connection = connection; this.emitter = emitter; this.listenToDiscoveryChanges(); } listenToDiscoveryChanges() { this.connection.onNotification(raas_core_1.Messages.Client.DiscoveryPathAddedNotification.type, (discoveryPath) => { this.emitter.emit('discoveryPathAdded', discoveryPath); }); this.connection.onNotification(raas_core_1.Messages.Client.DiscoveryPathRemovedNotification.type, discoveryPath => { this.emitter.emit('discoveryPathRemoved', discoveryPath); }); } findServerInstallations(path, timeout = 2000) { return common_1.Common.sendSimpleRequest(this.connection, raas_core_1.Messages.Server.FindServerInstallationsRequest.type, { location: path }, timeout, common_1.ErrorMessages.FINDINSTALLATIONS_TIMEOUT); } addDiscoveryPathAsync(path, timeout = 2000) { return common_1.Common.sendSimpleRequest(this.connection, raas_core_1.Messages.Server.AddDiscoveryPathRequest.type, { location: path }, timeout, common_1.ErrorMessages.ADDPATH_TIMEOUT); } addDiscoveryPathSync(path, timeout = 2000) { const discoveryPath = { location: path }; const listener = (param) => { return param.location === discoveryPath.location; }; return common_1.Common.sendRequestSync(this.connection, raas_core_1.Messages.Server.AddDiscoveryPathRequest.type, discoveryPath, this.emitter, 'discoveryPathAdded', listener, timeout, common_1.ErrorMessages.ADDPATH_TIMEOUT); } removeDiscoveryPathAsync(path, timeout = 2000) { if (typeof (path) === 'string') { path = { location: path }; } return common_1.Common.sendSimpleRequest(this.connection, raas_core_1.Messages.Server.RemoveDiscoveryPathRequest.type, path, timeout, common_1.ErrorMessages.REMOVEPATH_TIMEOUT); } removeDiscoveryPathSync(path, timeout = 2000) { let discoveryPath; if (typeof (path) === 'string') { discoveryPath = { location: path }; } else { discoveryPath = path; } const listener = (param) => { return param.location === discoveryPath.location; }; return common_1.Common.sendRequestSync(this.connection, raas_core_1.Messages.Server.RemoveDiscoveryPathRequest.type, discoveryPath, this.emitter, 'discoveryPathRemoved', listener, timeout, common_1.ErrorMessages.REMOVEPATH_TIMEOUT); } getDiscoveryPaths(timeout = 2000) { return common_1.Common.sendSimpleRequest(this.connection, raas_core_1.Messages.Server.GetDiscoveryPathsRequest.type, null, timeout, common_1.ErrorMessages.GETPATHS_TIMEOUT); } } exports.Discovery = Discovery; //# sourceMappingURL=discovery.js.map