updated tests. Data now flows correctly between socket endpoints

This commit is contained in:
Philipp Kunz 2016-08-15 01:38:28 +02:00
parent 24310b6709
commit 7f0fff0bf4
13 changed files with 107 additions and 32 deletions

View File

@ -40,7 +40,12 @@ class Smartsocket {
plugins.beautylog.log("Socket connected. Trying to authenticate..."); plugins.beautylog.log("Socket connected. Trying to authenticate...");
this.openSockets.add(socketConnection); this.openSockets.add(socketConnection);
socketConnection.authenticate() socketConnection.authenticate()
.then(socketConnection.listenToFunctionRequests); .then(() => {
return socketConnection.listenToFunctionRequests();
})
.catch((err) => {
console.log(err);
});
} }
; ;
// communication // communication
@ -49,4 +54,4 @@ class Smartsocket {
} }
} }
exports.Smartsocket = Smartsocket; exports.Smartsocket = Smartsocket;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFHakQsVUFBVTtBQUNWLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQUdoQyx1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUt6RSxDQUFDO0FBRUY7SUFJSSxZQUFZLFVBQTBDO1FBRHRELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQW9CLENBQUM7UUFxQmhEOztXQUVHO1FBRUgsZ0JBQVcsR0FBRztZQUNWLElBQUksQ0FBQyxFQUFFLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzlDLElBQUksQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLFlBQVksRUFBRSxDQ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BVyxjQXFEdkIsQ0FBQSJ9

View File

@ -1,6 +1,5 @@
/// <reference types="q" /> /// <reference types="q" />
import * as plugins from "./smartsocket.plugins"; import * as plugins from "./smartsocket.plugins";
import { ISocketFunctionCall } from "./smartsocket.classes.socketfunction";
import { SocketConnection } from "./smartsocket.classes.socketconnection"; import { SocketConnection } from "./smartsocket.classes.socketconnection";
/** /**
* interface for class SmartsocketClient * interface for class SmartsocketClient
@ -25,5 +24,5 @@ export declare class SmartsocketClient {
*/ */
connect(): plugins.q.Promise<{}>; connect(): plugins.q.Promise<{}>;
disconnect(): plugins.q.Promise<{}>; disconnect(): plugins.q.Promise<{}>;
serverCall(functionNameArg: string, dataArg: ISocketFunctionCall): plugins.q.Promise<{}>; serverCall(functionNameArg: string, dataArg: any): plugins.q.Promise<{}>;
} }

View File

@ -34,6 +34,8 @@ class SmartsocketClient {
}); });
this.socketConnection.socket.on("authenticated", () => { this.socketConnection.socket.on("authenticated", () => {
console.log("client is authenticated"); console.log("client is authenticated");
this.socketConnection.authenticated = true;
this.socketConnection.listenToFunctionRequests();
done.resolve(); done.resolve();
}); });
}); });
@ -60,12 +62,12 @@ class SmartsocketClient {
} }
}); });
socketRequest.dispatch() socketRequest.dispatch()
.then(() => { .then((dataArg) => {
done.resolve(); done.resolve(dataArg.funcDataArg);
}); });
return done.promise; return done.promise;
} }
; ;
} }
exports.SmartsocketClient = SmartsocketClient; exports.SmartsocketClient = SmartsocketClient;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXRjbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUl6QixDQUFDLENBSitDO0F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RQUM3QixJQUFJLGFBQWEsR0FBRyxJQUFJLGlEQUFhLENBQUM7WUFDbEMsSUFBSSxFQUFDLFlBQVk7WUFDakIsc0JBQXNCLEVBQUMsSUFBSSxDQUFDLGdCQUFnQjtZQUM1QyxPQUFPLEVBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxRQUFRLEVBQUU7WUFDbEMsWUFBWSxFQUFDO2dCQUNULFFBQVEsRUFBRSxlQUFlO2dCQUN6QixXQUFXLEVBQUMsT0FBTzthQUN0QjtTQUNKLENBQUMsQ0FBQztRQUNILGFBQWEsQ0FBQyxRQUFRLEVBQUU7YUFDbkIsSUFBSSxDQUFDLENBQUMsT0FBMkI7WUFDOUIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7UUFDdEMsQ0FBQyxDQUFDLENBQUM7UUFDUCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDOztBQUVMLENBQUM7QUF0RVkseUJBQWlCLG9CQXNFN0IsQ0FBQSJ9

View File

@ -9,6 +9,7 @@ const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socke
*/ */
class SocketConnection { class SocketConnection {
constructor(optionsArg) { constructor(optionsArg) {
this.authenticated = false;
this.alias = optionsArg.alias; this.alias = optionsArg.alias;
this.authenticated = optionsArg.authenticated; this.authenticated = optionsArg.authenticated;
this.role = optionsArg.role; this.role = optionsArg.role;
@ -37,6 +38,7 @@ class SocketConnection {
done.resolve(this); done.resolve(this);
} }
else { else {
this.authenticated = false;
this.socket.disconnect(); this.socket.disconnect();
done.reject("not authenticated"); done.reject("not authenticated");
} }
@ -55,10 +57,12 @@ class SocketConnection {
if (this.authenticated) { if (this.authenticated) {
this.socket.on("function", (dataArg) => { this.socket.on("function", (dataArg) => {
// check if requested function is available to the socket's scope // check if requested function is available to the socket's scope
plugins.beautylog.log("function request received");
let referencedFunction = this.role.allowedFunctions.find((socketFunctionArg) => { let referencedFunction = this.role.allowedFunctions.find((socketFunctionArg) => {
return socketFunctionArg.name === dataArg.funcCallData.funcName; return socketFunctionArg.name === dataArg.funcCallData.funcName;
}); });
if (referencedFunction !== undefined) { if (referencedFunction !== undefined) {
plugins.beautylog.ok("function in access scope");
let localSocketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({ let localSocketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({
side: "responding", side: "responding",
originSocketConnection: this, originSocketConnection: this,
@ -73,12 +77,17 @@ class SocketConnection {
; ;
}); });
this.socket.on("functionResponse", (dataArg) => { this.socket.on("functionResponse", (dataArg) => {
plugins.beautylog.info(`received response for request with id ${dataArg.shortId}`);
let targetSocketRequest = helpers.getSocketRequestById(dataArg.shortId); let targetSocketRequest = helpers.getSocketRequestById(dataArg.shortId);
targetSocketRequest.handleResponse(dataArg); targetSocketRequest.handleResponse(dataArg);
}); });
plugins.beautylog.log(`now listening to function requests for ${this.alias}`);
done.resolve(this);
} }
else { else {
done.reject("socket needs to be authenticated first"); let errMessage;
plugins.beautylog.error(errMessage);
done.reject(errMessage);
} }
; ;
return done.promise; return done.promise;
@ -87,4 +96,4 @@ class SocketConnection {
} }
exports.SocketConnection = SocketConnection; exports.SocketConnection = SocketConnection;
; ;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSx1QkFBdUIsQ0FBQyxDQUFBO0FBQ2pELE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFJakQsb0RBQTJFLHFDQUFxQyxDQUFDLENBQUE7QUFhaEgs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VUFBVSxDQUFDLENBQUM7WUFDcEMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxVQUFVLENBQUMsQ0FBQztRQUM1QixDQUFDO1FBQUEsQ0FBQztRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7O0FBSUwsQ0FBQztBQXhGWSx3QkFBZ0IsbUJBd0Y1QixDQUFBO0FBQUEsQ0FBQyJ9

View File

@ -39,7 +39,11 @@ class SocketFunction {
if (dataArg.funcName === this.name) { if (dataArg.funcName === this.name) {
this.funcDef(dataArg.funcDataArg) this.funcDef(dataArg.funcDataArg)
.then((resultData) => { .then((resultData) => {
done.resolve(resultData); let funcResponseData = {
funcName: this.name,
funcDataArg: resultData
};
done.resolve(funcResponseData);
}); });
} }
else { else {
@ -50,4 +54,4 @@ class SocketFunction {
; ;
} }
exports.SocketFunction = SocketFunction; exports.SocketFunction = SocketFunction;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFFakQsaUJBQWlCO0FBQ2pCLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQVkvQixDQUFDO0FBUUQsQ0FBQztBQVNGLGlCQUFpQjtBQUNOLDBCQUFrQixHQUFHLElBQUksZUFBUyxFQUFrQixDQUFDO0FBRWhFLGlCQUFpQjtBQUVqQjs7R0FFRztBQUNIO0lBS0k7O09BRUc7SUFDSCxZQUFZLFVBQTZDO1FBQ3JELElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSxDQUFDLFFBQV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0FBQyxhQUF3QjtRQUN4QyxhQUFhLENBQUMsaUJBQWlCLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDMUMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsTUFBTSxDQUFDLE9BQTJCO1FBQzlCLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDN0IsRUFBRSxDQUFBLENBQUMsT0FBTyxDQUFDLFFBQVEsS0FBSyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUEsQ0FBQztZQUMvQixJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUM7aUJBQzVCLElBQUksQ0FBQyxDQUFDLFVBQWM7Z0JBQ2pCLElBQUksZ0JBQWdCLEdBQXVCO29CQUN2QyxRQUFRLEVBQUMsSUFBSSxDQUFDLElBQUk7b0JBQ2xCLFdBQVcsRUFBQyxVQUFVO2lCQUN6QixDQUFBO2dCQUNELElBQUksQ0FBQyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztZQUNuQyxDQUFDLENBQUMsQ0FBQztRQUVYLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLE1BQU0sSUFBSSxLQUFLLENBQUMsK0RBQStELENBQUMsQ0FBQztRQUNyRixDQUFDO1FBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFFTCxDQUFDO0FBOUNZLHNCQUFjLGlCQThDMUIsQ0FBQSJ9

View File

@ -15,6 +15,7 @@ class SocketRequest {
this.side = optionsArg.side; this.side = optionsArg.side;
this.shortid = optionsArg.shortId; this.shortid = optionsArg.shortId;
this.funcCallData = optionsArg.funcCallData; this.funcCallData = optionsArg.funcCallData;
this.originSocketConnection = optionsArg.originSocketConnection;
exports.allSocketRequests.add(this); exports.allSocketRequests.add(this);
} }
; ;
@ -35,7 +36,8 @@ class SocketRequest {
* handles the response that is received by the requesting side * handles the response that is received by the requesting side
*/ */
handleResponse(responseDataArg) { handleResponse(responseDataArg) {
this.done.resolve(responseDataArg); plugins.beautylog.log("handling response!");
this.done.resolve(responseDataArg.funcCallData);
exports.allSocketRequests.remove(this); exports.allSocketRequests.remove(this);
} }
// responding -------------------------- // responding --------------------------
@ -44,8 +46,10 @@ class SocketRequest {
*/ */
createResponse() { createResponse() {
let targetSocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName); let targetSocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName);
plugins.beautylog.info(`invoking ${targetSocketFunction.name}`);
targetSocketFunction.invoke(this.funcCallData) targetSocketFunction.invoke(this.funcCallData)
.then((resultData) => { .then((resultData) => {
plugins.beautylog.log("got resultData. Sending it to requesting party.");
let requestData = { let requestData = {
funcCallData: resultData, funcCallData: resultData,
shortId: this.shortid shortId: this.shortid
@ -57,4 +61,4 @@ class SocketRequest {
} }
exports.SocketRequest = SocketRequest; exports.SocketRequest = SocketRequest;
; ;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSx1QkFBdUIsQ0FBQyxDQUFBO0FBQ2pELE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFLakQsaUJBQWlCO0FBQ2pCLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQWdCL0IsQ0FBQztBQVNELENBQUM7QUFFRixnQkFBZ0I7QUFDTCx5QkFBaUIsR0FBRyxJQUFJLGVBQVMsRUFBaUIsQ0FBQztBQUU5RCxpQkFBaUI7QUFDakI7SUFPSSxZQUF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SSxvQkFBb0IsR0FBbUIsT0FBTyxDQUFDLHVCQUF1QixDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsUUFBUSxDQUFDLENBQUM7UUFDdkcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsWUFBWSxvQkFBb0IsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxDQUFDO1FBQ2hFLG9CQUFvQixDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDO2FBQ3pDLElBQUksQ0FBQyxDQUFDLFVBQVU7WUFDYixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxpREFBaUQsQ0FBQyxDQUFBO1lBQ3hFLElBQUksV0FBVyxHQUE2QjtnQkFDeEMsWUFBWSxFQUFFLFVBQVU7Z0JBQ3hCLE9BQU8sRUFBRSxJQUFJLENBQUMsT0FBTzthQUN4QixDQUFDO1lBQ0YsSUFBSSxDQUFDLHNCQUFzQixDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsa0JBQWtCLEVBQUMsV0FBVyxDQUFDLENBQUM7WUFDeEUseUJBQWlCLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxDQUFDO1FBQ25DLENBQUMsQ0FBQyxDQUFDO0lBQ1gsQ0FBQztBQUNMLENBQUM7QUF6RFkscUJBQWEsZ0JBeUR6QixDQUFBO0FBQUEsQ0FBQyJ9

View File

@ -5,6 +5,7 @@ const smartsocket = require("../dist/index");
const q = require("q"); const q = require("q");
let testSmartsocket; let testSmartsocket;
let testSmartsocketClient; let testSmartsocketClient;
let testSocketRole1;
let testSocketFunction1; let testSocketFunction1;
let testConfig = { let testConfig = {
port: 3000 port: 3000
@ -20,16 +21,21 @@ describe("smartsocket", function () {
}); });
}); });
describe("class SocketRole", function () { describe("class SocketRole", function () {
testSocketRole1 = new smartsocket.SocketRole({
name: "testRole1",
passwordHash: "somehash"
});
}); });
describe("class SocketFunction", function () { describe("class SocketFunction", function () {
it("should register a new Function", function () { it("should register a new Function", function () {
testSocketFunction1 = new smartsocket.SocketFunction({ testSocketFunction1 = new smartsocket.SocketFunction({
funcName: "testFunction1", funcName: "testFunction1",
funcDef: () => { funcDef: (dataArg) => {
let done = q.defer(); let done = q.defer();
done.resolve(dataArg);
return done.promise; return done.promise;
}, },
allowedRoles: [] allowedRoles: [testSocketRole1]
}); });
}); });
}); });
@ -41,7 +47,7 @@ describe("smartsocket", function () {
url: "http://localhost", url: "http://localhost",
password: "testPassword", password: "testPassword",
alias: "testClient1", alias: "testClient1",
role: undefined role: "testRole1"
}); });
testSmartsocketClient.connect() testSmartsocketClient.connect()
.then(() => { .then(() => {
@ -65,6 +71,15 @@ describe("smartsocket", function () {
}); });
it("2 clients should connect in parallel", function () { it("2 clients should connect in parallel", function () {
}); });
it("should be able to make a functionCall", function (done) {
this.timeout(5000);
testSmartsocketClient.serverCall("testFunction1", {
value1: "hello"
}).then((dataArg) => {
console.log(dataArg);
done();
});
});
}); });
describe("terminating smartsocket", function () { describe("terminating smartsocket", function () {
it("should close the server", function () { it("should close the server", function () {
@ -72,4 +87,4 @@ describe("smartsocket", function () {
}); });
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixNQUFPLFdBQVcsV0FBVyxlQUFlLENBQUMsQ0FBQztBQUM5QyxNQUFPLENBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUV4QixJQUFJLGVBQXdDLENBQUM7QUFDN0MsSUFBSSxxQkFBb0QsQ0FBQztBQUN6RCxJQUFJLG1CQUE4QyxDQUFDO0FBRW5ELElBQUksVUFBVSxHQUFHO0lBQ2IsSUFBSS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SUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUNuQixxQkFBcUIsQ0FBQyxVQUFVLENBQUMsZUFBZSxFQUFDO2dCQUM3QyxNQUFNLEVBQUMsT0FBTzthQUNqQixDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsT0FBTztnQkFDWixPQUFPLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFDO2dCQUNyQixJQUFJLEVBQUUsQ0FBQztZQUNYLENBQUMsQ0FBQyxDQUFDO1FBQ1AsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQztJQUNILFFBQVEsQ0FBQyx5QkFBeUIsRUFBRTtRQUNoQyxFQUFFLENBQUMseUJBQXlCLEVBQUU7WUFDMUIsZUFBZSxDQUFDLFdBQVcsRUFBRSxDQUFDO1FBQ2xDLENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQyJ9

View File

@ -6,6 +6,7 @@ import q = require("q");
let testSmartsocket: smartsocket.Smartsocket; let testSmartsocket: smartsocket.Smartsocket;
let testSmartsocketClient: smartsocket.SmartsocketClient; let testSmartsocketClient: smartsocket.SmartsocketClient;
let testSocketRole1: smartsocket.SocketRole;
let testSocketFunction1:smartsocket.SocketFunction; let testSocketFunction1:smartsocket.SocketFunction;
let testConfig = { let testConfig = {
@ -23,17 +24,21 @@ describe("smartsocket", function () {
}); });
}); });
describe("class SocketRole", function(){ describe("class SocketRole", function(){
testSocketRole1 = new smartsocket.SocketRole({
name:"testRole1",
passwordHash:"somehash"
})
}) })
describe("class SocketFunction", function () { describe("class SocketFunction", function () {
it("should register a new Function", function () { it("should register a new Function", function () {
testSocketFunction1 = new smartsocket.SocketFunction({ testSocketFunction1 = new smartsocket.SocketFunction({
funcName:"testFunction1", funcName:"testFunction1",
funcDef: () => { funcDef: (dataArg) => {
let done = q.defer(); let done = q.defer();
done.resolve(dataArg);
return done.promise; return done.promise;
}, },
allowedRoles:[] allowedRoles:[testSocketRole1]
}); });
}); });
}); });
@ -45,7 +50,7 @@ describe("smartsocket", function () {
url: "http://localhost", url: "http://localhost",
password: "testPassword", password: "testPassword",
alias: "testClient1", alias: "testClient1",
role: undefined role: "testRole1"
}); });
testSmartsocketClient.connect() testSmartsocketClient.connect()
.then(() => { .then(() => {
@ -70,6 +75,15 @@ describe("smartsocket", function () {
it("2 clients should connect in parallel", function () { it("2 clients should connect in parallel", function () {
}); });
it("should be able to make a functionCall",function(done){
this.timeout(5000);
testSmartsocketClient.serverCall("testFunction1",{
value1:"hello"
}).then((dataArg) => {
console.log(dataArg);
done();
});
})
}); });
describe("terminating smartsocket", function () { describe("terminating smartsocket", function () {
it("should close the server", function () { it("should close the server", function () {

View File

@ -33,7 +33,12 @@ export class Smartsocket {
plugins.beautylog.log("Socket connected. Trying to authenticate...") plugins.beautylog.log("Socket connected. Trying to authenticate...")
this.openSockets.add(socketConnection); this.openSockets.add(socketConnection);
socketConnection.authenticate() socketConnection.authenticate()
.then(socketConnection.listenToFunctionRequests); .then(() => {
return socketConnection.listenToFunctionRequests();
})
.catch((err) => {
console.log(err);
});
}; };
/** /**

View File

@ -57,6 +57,8 @@ export class SmartsocketClient {
}); });
this.socketConnection.socket.on("authenticated",() => { this.socketConnection.socket.on("authenticated",() => {
console.log("client is authenticated"); console.log("client is authenticated");
this.socketConnection.authenticated = true;
this.socketConnection.listenToFunctionRequests();
done.resolve(); done.resolve();
}); });
}); });
@ -70,7 +72,7 @@ export class SmartsocketClient {
done.resolve(); done.resolve();
return done.promise; return done.promise;
} }
serverCall(functionNameArg:string,dataArg:ISocketFunctionCall){ serverCall(functionNameArg:string,dataArg:any){
let done = plugins.q.defer(); let done = plugins.q.defer();
let socketRequest = new SocketRequest({ let socketRequest = new SocketRequest({
side:"requesting", side:"requesting",
@ -82,8 +84,8 @@ export class SmartsocketClient {
} }
}); });
socketRequest.dispatch() socketRequest.dispatch()
.then(() => { .then((dataArg:ISocketFunctionCall) => {
done.resolve(); done.resolve(dataArg.funcDataArg);
}); });
return done.promise; return done.promise;
}; };

View File

@ -34,7 +34,7 @@ export interface ISocketConnectionAuthenticationObject {
*/ */
export class SocketConnection { export class SocketConnection {
alias: string; alias: string;
authenticated: boolean; authenticated: boolean = false;
role: SocketRole; role: SocketRole;
socket: SocketIO.Socket | SocketIOClient.Socket; socket: SocketIO.Socket | SocketIOClient.Socket;
constructor(optionsArg: ISocketConnectionConstructorOptions) { constructor(optionsArg: ISocketConnectionConstructorOptions) {
@ -67,6 +67,7 @@ export class SocketConnection {
plugins.beautylog.ok(`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`); plugins.beautylog.ok(`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`);
done.resolve(this); done.resolve(this);
} else { } else {
this.authenticated = false;
this.socket.disconnect(); this.socket.disconnect();
done.reject("not authenticated"); done.reject("not authenticated");
}; };
@ -85,10 +86,12 @@ export class SocketConnection {
if(this.authenticated){ if(this.authenticated){
this.socket.on("function", (dataArg:ISocketRequestDataObject) => { this.socket.on("function", (dataArg:ISocketRequestDataObject) => {
// check if requested function is available to the socket's scope // check if requested function is available to the socket's scope
plugins.beautylog.log("function request received");
let referencedFunction:SocketFunction = this.role.allowedFunctions.find((socketFunctionArg) => { let referencedFunction:SocketFunction = this.role.allowedFunctions.find((socketFunctionArg) => {
return socketFunctionArg.name === dataArg.funcCallData.funcName; return socketFunctionArg.name === dataArg.funcCallData.funcName;
}); });
if(referencedFunction !== undefined){ if(referencedFunction !== undefined){
plugins.beautylog.ok!("function in access scope");
let localSocketRequest = new SocketRequest({ let localSocketRequest = new SocketRequest({
side:"responding", side:"responding",
originSocketConnection:this, originSocketConnection:this,
@ -101,11 +104,16 @@ export class SocketConnection {
}; };
}); });
this.socket.on("functionResponse", (dataArg:ISocketRequestDataObject) => { this.socket.on("functionResponse", (dataArg:ISocketRequestDataObject) => {
plugins.beautylog.info(`received response for request with id ${dataArg.shortId}`);
let targetSocketRequest = helpers.getSocketRequestById(dataArg.shortId); let targetSocketRequest = helpers.getSocketRequestById(dataArg.shortId);
targetSocketRequest.handleResponse(dataArg); targetSocketRequest.handleResponse(dataArg);
}) });
plugins.beautylog.log(`now listening to function requests for ${this.alias}`);
done.resolve(this);
} else { } else {
done.reject("socket needs to be authenticated first"); let errMessage: "socket needs to be authenticated first";
plugins.beautylog.error(errMessage);
done.reject(errMessage);
}; };
return done.promise; return done.promise;
}; };

View File

@ -71,7 +71,11 @@ export class SocketFunction {
if(dataArg.funcName === this.name){ if(dataArg.funcName === this.name){
this.funcDef(dataArg.funcDataArg) this.funcDef(dataArg.funcDataArg)
.then((resultData:any) => { .then((resultData:any) => {
done.resolve(resultData); let funcResponseData:ISocketFunctionCall = {
funcName:this.name,
funcDataArg:resultData
}
done.resolve(funcResponseData);
}); });
} else { } else {

View File

@ -47,6 +47,7 @@ export class SocketRequest {
this.side = optionsArg.side; this.side = optionsArg.side;
this.shortid = optionsArg.shortId; this.shortid = optionsArg.shortId;
this.funcCallData = optionsArg.funcCallData; this.funcCallData = optionsArg.funcCallData;
this.originSocketConnection = optionsArg.originSocketConnection;
allSocketRequests.add(this); allSocketRequests.add(this);
}; };
@ -68,7 +69,8 @@ export class SocketRequest {
* handles the response that is received by the requesting side * handles the response that is received by the requesting side
*/ */
handleResponse(responseDataArg: ISocketRequestDataObject) { handleResponse(responseDataArg: ISocketRequestDataObject) {
this.done.resolve(responseDataArg); plugins.beautylog.log("handling response!");
this.done.resolve(responseDataArg.funcCallData);
allSocketRequests.remove(this); allSocketRequests.remove(this);
} }
@ -79,12 +81,14 @@ export class SocketRequest {
*/ */
createResponse() { createResponse() {
let targetSocketFunction: SocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName); let targetSocketFunction: SocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName);
plugins.beautylog.info(`invoking ${targetSocketFunction.name}`);
targetSocketFunction.invoke(this.funcCallData) targetSocketFunction.invoke(this.funcCallData)
.then((resultData) => { .then((resultData) => {
plugins.beautylog.log("got resultData. Sending it to requesting party.")
let requestData: ISocketRequestDataObject = { let requestData: ISocketRequestDataObject = {
funcCallData: resultData, funcCallData: resultData,
shortId: this.shortid shortId: this.shortid
} };
this.originSocketConnection.socket.emit("functionResponse",requestData); this.originSocketConnection.socket.emit("functionResponse",requestData);
allSocketRequests.remove(this); allSocketRequests.remove(this);
}); });