smartsocket/dist/smartsocket.classes.smartsocketclient.js

56 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-08-07 16:59:39 +00:00
"use strict";
2016-08-09 09:42:21 +00:00
const plugins = require("./smartsocket.plugins");
// import classes
const smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.socketconnection");
2016-08-09 21:37:25 +00:00
const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest");
2016-08-07 16:59:39 +00:00
class SmartsocketClient {
2016-08-09 21:37:25 +00:00
constructor(optionsArg) {
this.serverUrl = optionsArg.url;
this.serverPort = optionsArg.port;
this.serverPassword = optionsArg.password;
}
;
// authenticates the socket against the server
_handleSocketConnection() {
let done = plugins.q.defer();
let socketUrl = `${this.serverUrl}:${this.serverPort}`;
this.socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({
authenticated: false,
socket: plugins.socketIoClient(this.serverUrl, {})
});
this.socketConnection.socket.on("requestAuth", function () {
console.log("server requested authentication");
this.socketConnection.socket.emit("dataAuth", {
role: "coreflowContainer",
password: "somePassword",
alias: "coreflow1"
});
this.socketConnection.socket.on("authenticated", () => {
console.log("client is authenticated");
done.resolve();
});
});
return done.promise;
2016-08-09 09:42:21 +00:00
}
;
2016-08-09 21:37:25 +00:00
serverCall(functionNameArg, dataArg) {
let done = plugins.q.defer();
2016-08-09 21:37:25 +00:00
let socketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({
side: "requesting",
originSocketConnection: this.socketConnection,
shortId: plugins.shortid.generate(),
funcCallData: {
funcName: functionNameArg,
funcDataArg: dataArg
}
});
socketRequest.dispatch()
.then(() => {
done.resolve();
});
return done.promise;
2016-08-09 21:37:25 +00:00
}
;
2016-08-07 16:59:39 +00:00
}
exports.SmartsocketClient = SmartsocketClient;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiO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