46 lines
3.4 KiB
JavaScript
46 lines
3.4 KiB
JavaScript
"use strict";
|
|
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());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const plugins = require("./smartuniverse.plugins");
|
|
const smartsocket_1 = require("smartsocket");
|
|
const url = require("url");
|
|
class UniverseClient {
|
|
constructor(optionsArg) {
|
|
this.options = optionsArg;
|
|
}
|
|
sendMessage(messageArg, payloadArg) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const requestBody = {
|
|
message: messageArg,
|
|
payload: payloadArg
|
|
};
|
|
yield plugins.smartrequest.post(this.options.serverAddress, {
|
|
requestBody
|
|
});
|
|
});
|
|
}
|
|
getMessageObservable() {
|
|
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;
|
|
}
|
|
}
|
|
exports.UniverseClient = UniverseClient;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMi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