"use strict"; const plugins = require("./smartsocket.plugins"); // import classes const smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.socketconnection"); const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest"); class SmartsocketClient { constructor(optionsArg) { this.alias = optionsArg.alias; this.role = optionsArg.role; this.serverUrl = optionsArg.url; this.serverPort = optionsArg.port; this.serverPassword = optionsArg.password; } ; /** * connect the client to the server */ connect() { let done = plugins.q.defer(); plugins.beautylog.log("trying to connect..."); let socketUrl = `${this.serverUrl}:${this.serverPort}`; this.socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({ alias: this.alias, authenticated: false, role: undefined, socket: plugins.socketIoClient(socketUrl, { multiplex: false }) }); this.socketConnection.socket.on("requestAuth", () => { console.log("server requested authentication"); this.socketConnection.socket.emit("dataAuth", { role: this.role, password: this.serverPassword, alias: this.alias }); this.socketConnection.socket.on("authenticated", () => { console.log("client is authenticated"); done.resolve(); }); }); return done.promise; } ; disconnect() { let done = plugins.q.defer(); this.socketConnection.socket.disconnect(); this.socketConnection = undefined; plugins.beautylog.ok("disconnected!"); done.resolve(); return done.promise; } serverCall(functionNameArg, dataArg) { let done = plugins.q.defer(); 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; } ; } exports.SmartsocketClient = SmartsocketClient; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXRjbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFN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