2018-03-13 05:15:40 +00:00
|
|
|
"use strict";
|
2018-03-15 00:16:16 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
2018-03-13 05:15:40 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2018-03-15 00:05:13 +00:00
|
|
|
const plugins = require("./smartuniverse.plugins");
|
2018-03-20 07:16:54 +00:00
|
|
|
const smartsocket_1 = require("smartsocket");
|
|
|
|
const url = require("url");
|
2018-03-13 05:15:40 +00:00
|
|
|
class UniverseClient {
|
2018-03-15 00:05:13 +00:00
|
|
|
constructor(optionsArg) {
|
|
|
|
this.options = optionsArg;
|
|
|
|
}
|
2018-03-15 00:16:16 +00:00
|
|
|
sendMessage(messageArg, payloadArg) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
const requestBody = {
|
|
|
|
message: messageArg,
|
|
|
|
payload: payloadArg
|
|
|
|
};
|
|
|
|
yield plugins.smartrequest.post(this.options.serverAddress, {
|
2018-03-20 07:16:54 +00:00
|
|
|
requestBody
|
2018-03-15 00:16:16 +00:00
|
|
|
});
|
2018-03-15 00:05:13 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
getMessageObservable() {
|
2018-03-20 07:16:54 +00:00
|
|
|
if (!this.socketClient && !this.observableIntake) {
|
|
|
|
const parsedURL = url.parse(this.options.serverAddress);
|
|
|
|
this.socketClient = new smartsocket_1.SmartsocketClient({
|
|
|
|
alias: process.env.SOCKET_ALIAS || 'someclient',
|
|
|
|
password: 'UniverseClient',
|
|
|
|
port: parseInt(parsedURL.port, 10),
|
|
|
|
role: 'UniverseClient',
|
|
|
|
url: parsedURL.hostname,
|
|
|
|
});
|
|
|
|
this.observableIntake = new plugins.smartrx.ObservableIntake();
|
|
|
|
this.socketClient.connect();
|
|
|
|
}
|
|
|
|
return this.observableIntake.observable;
|
2018-03-15 00:05:13 +00:00
|
|
|
}
|
2018-04-04 15:39:48 +00:00
|
|
|
close() {
|
|
|
|
this.socketClient.disconnect();
|
|
|
|
}
|
2018-03-13 05:15:40 +00:00
|
|
|
}
|
|
|
|
exports.UniverseClient = UniverseClient;
|
2018-04-04 15:39:48 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSxtREFBbUQ7QUFJbkQsNkNBQTZEO0FBQzdELDJCQUEyQjtBQVkzQjtJQUtFLFlBQVksVUFBMEI7UUFDcEMsSUFBSSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUM7SUFDNUIsQ0FBQztJQUVZLFdBQVcsQ0FBQyxVQUFVLEVBQUUsVUFBVTs7WUFDN0MsTUFBTSxXQUFXLEdBQUc7Z0JBQ2xCLE9BQU8sRUFBRSxVQUFVO2dCQUNuQixPQUFPLEVBQUUsVUFBVTthQUNwQixDQUFDO1lBQ0YsTUFBTSxPQUFPLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLGFBQWEsRUFBRTtnQkFDMUQsV0FBVzthQUNaLENBQUMsQ0FBQztRQUNMLENBQUM7S0FBQTtJQUVNL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