updated structure

This commit is contained in:
Philipp Kunz 2016-08-14 03:25:26 +02:00
parent 8dfc39be75
commit 7b2b2bd151
12 changed files with 115 additions and 39 deletions

View File

@ -12,7 +12,7 @@ class Smartsocket {
*/ */
this.startServer = () => { this.startServer = () => {
this.io = plugins.socketIo(this.options.port); this.io = plugins.socketIo(this.options.port);
this.io.on('connection', (socketArg) => { this.io.on("connection", (socketArg) => {
this._handleSocketConnection(socketArg); this._handleSocketConnection(socketArg);
}); });
}; };
@ -32,7 +32,9 @@ class Smartsocket {
*/ */
_handleSocketConnection(socketArg) { _handleSocketConnection(socketArg) {
let socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({ let socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({
alias: undefined,
authenticated: false, authenticated: false,
role: undefined,
socket: socketArg socket: socketArg
}); });
plugins.beautylog.log("Socket connected. Trying to authenticate..."); plugins.beautylog.log("Socket connected. Trying to authenticate...");
@ -47,4 +49,4 @@ class Smartsocket {
} }
} }
exports.Smartsocket = Smartsocket; exports.Smartsocket = Smartsocket;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFHakQsVUFBVTtBQUNWLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQUdoQyx1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUt6RSxDQUFDO0FBRUY7SUFJSSxZQUFZLFVBQTBDO1FBRHRELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQW9CLENBQUM7UUFtQmhEOztXQUVHO1FBRUgsZ0JBQVcsR0FB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@ -8,15 +8,22 @@ import { SocketConnection } from "./smartsocket.classes.socketconnection";
export interface ISmartsocketClientOptions { export interface ISmartsocketClientOptions {
port: number; port: number;
url: string; url: string;
alias?: string; alias: string;
role: string;
password: string; password: string;
} }
export declare class SmartsocketClient { export declare class SmartsocketClient {
alias: string;
role: string;
socketConnection: SocketConnection; socketConnection: SocketConnection;
serverUrl: string; serverUrl: string;
serverPort: number; serverPort: number;
serverPassword: string; serverPassword: string;
constructor(optionsArg: ISmartsocketClientOptions); constructor(optionsArg: ISmartsocketClientOptions);
private _handleSocketConnection(); /**
* connect the client to the server
*/
connect(): plugins.q.Promise<{}>;
disconnect(): plugins.q.Promise<{}>;
serverCall(functionNameArg: string, dataArg: ISocketFunctionCall): plugins.q.Promise<{}>; serverCall(functionNameArg: string, dataArg: ISocketFunctionCall): plugins.q.Promise<{}>;
} }

View File

@ -5,25 +5,32 @@ const smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.so
const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest"); const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest");
class SmartsocketClient { class SmartsocketClient {
constructor(optionsArg) { constructor(optionsArg) {
this.alias = optionsArg.alias;
this.role = optionsArg.role;
this.serverUrl = optionsArg.url; this.serverUrl = optionsArg.url;
this.serverPort = optionsArg.port; this.serverPort = optionsArg.port;
this.serverPassword = optionsArg.password; this.serverPassword = optionsArg.password;
} }
; ;
// authenticates the socket against the server /**
_handleSocketConnection() { * connect the client to the server
*/
connect() {
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.beautylog.log("trying to connect...");
let socketUrl = `${this.serverUrl}:${this.serverPort}`; let socketUrl = `${this.serverUrl}:${this.serverPort}`;
this.socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({ this.socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({
alias: this.alias,
authenticated: false, authenticated: false,
socket: plugins.socketIoClient(this.serverUrl, {}) role: undefined,
socket: plugins.socketIoClient(socketUrl, {})
}); });
this.socketConnection.socket.on("requestAuth", function () { this.socketConnection.socket.on("requestAuth", () => {
console.log("server requested authentication"); console.log("server requested authentication");
this.socketConnection.socket.emit("dataAuth", { this.socketConnection.socket.emit("dataAuth", {
role: "coreflowContainer", role: this.role,
password: "somePassword", password: this.serverPassword,
alias: "coreflow1" alias: this.alias
}); });
this.socketConnection.socket.on("authenticated", () => { this.socketConnection.socket.on("authenticated", () => {
console.log("client is authenticated"); console.log("client is authenticated");
@ -33,6 +40,13 @@ class SmartsocketClient {
return done.promise; return done.promise;
} }
; ;
disconnect() {
let done = plugins.q.defer();
this.socketConnection.socket.disconnect();
plugins.beautylog.ok("disconnected!");
done.resolve();
return done.promise;
}
serverCall(functionNameArg, dataArg) { serverCall(functionNameArg, dataArg) {
let done = plugins.q.defer(); let done = plugins.q.defer();
let socketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({ let socketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({
@ -53,4 +67,4 @@ class SmartsocketClient {
; ;
} }
exports.SmartsocketClient = SmartsocketClient; exports.SmartsocketClient = SmartsocketClient;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXRjbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUl6QixDQUFDLENBSitDO0FBT2hELGlCQUFpQjtBQUNqQix1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUUxRSxvREFBOEIscUNBQXFDLENBQUMsQ0FBQTtBQVdwRTtJQUtJLFlBQVksVUFBb0M7UUFDNUMsSUFBSSxDQUFDLFNBQVMsR0FBRyxVQUFVLENBQUMsR0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SxhQUFhLEdBQUcsSUFBSSxpREFBYSxDQUFDO1lBQ2xDLElBQUksRUFBQyxZQUFZO1lBQ2pCLHNCQUFzQixFQUFDLElBQUksQ0FBQyxnQkFBZ0I7WUFDNUMsT0FBTyxFQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsUUFBUSxFQUFFO1lBQ2xDLFlBQVksRUFBQztnQkFDVCxRQUFRLEVBQUUsZUFBZTtnQkFDekIsV0FBVyxFQUFDLE9BQU87YUFDdEI7U0FDSixDQUFDLENBQUM7UUFDSCxhQUFhLENBQUMsUUFBUSxFQUFFO2FBQ25CLElBQUksQ0FBQztZQUNGLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztRQUNuQixDQUFDLENBQUMsQ0FBQztRQUNQLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7O0FBRUwsQ0FBQztBQW5FWSx5QkFBaUIsb0JBbUU3QixDQUFBIn0=

View File

@ -7,10 +7,10 @@ import { SocketRole } from "./smartsocket.classes.socketrole";
* interface for constructor of class SocketConnection * interface for constructor of class SocketConnection
*/ */
export interface ISocketConnectionConstructorOptions { export interface ISocketConnectionConstructorOptions {
alias?: string; alias: string;
authenticated: boolean; authenticated: boolean;
role?: SocketRole; role: SocketRole;
socket?: SocketIO.Socket | SocketIOClient.Socket; socket: SocketIO.Socket | SocketIOClient.Socket;
} }
/** /**
* interface for authentication data * interface for authentication data
@ -24,9 +24,9 @@ export interface ISocketConnectionAuthenticationObject {
* class SocketConnection represents a websocket connection * class SocketConnection represents a websocket connection
*/ */
export declare class SocketConnection { export declare class SocketConnection {
alias?: string; alias: string;
authenticated: boolean; authenticated: boolean;
role?: SocketRole; role: SocketRole;
socket: SocketIO.Socket | SocketIOClient.Socket; socket: SocketIO.Socket | SocketIOClient.Socket;
constructor(optionsArg: ISocketConnectionConstructorOptions); constructor(optionsArg: ISocketConnectionConstructorOptions);
/** /**

View File

@ -13,7 +13,12 @@ class SocketConnection {
this.authenticated = optionsArg.authenticated; this.authenticated = optionsArg.authenticated;
this.role = optionsArg.role; this.role = optionsArg.role;
this.socket = optionsArg.socket; this.socket = optionsArg.socket;
// standard behaviour that is always true
this.socket.on("disconnect", () => {
plugins.beautylog.info(`Client ${this.alias} disconnected`);
});
} }
;
// authenticating -------------------------- // authenticating --------------------------
/** /**
* authenticate the socket * authenticate the socket
@ -82,4 +87,4 @@ class SocketConnection {
} }
exports.SocketConnection = SocketConnection; exports.SocketConnection = SocketConnection;
; ;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSx1QkFBdUIsQ0FBQyxDQUFBO0FBQ2pELE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFJakQsb0RBQTJFLHFDQUFxQyxDQUFDLENBQUE7QUFhaEgsQ0FBQztBQVdGLGlCQUFpQjtBQUVqQjs7R0FFRztBQUNIO0lBS0ksWUFBWSxVQUErQztRQUN2RCxJQUFJLENBQUMsS0FBSyxHQUFHLFVBQVUsQ0FBQyxLQUFLLENBQUM7UUFDOUIsSUFBSSxDQUFDLGFBQWEsR0FBRyxVQUFVLENBQUMsYUFBYSxDQUFDO1FBQzlDLElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQztRQUM1QixJQUFJLENBQUMsTUFBTSxHQUFHLFVBQVUsQ0FBQyxNQUFNLENBQUM7SUFDcEMsQ0FBQztJQUVELDRDQUE0QztJQUU1Qzs7T0FFRztJQUNILFlBQVk7UUFDUixJQUFJLElBQUksR0FBRy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QU8sQ0FBQztJQUN4QixDQUFDOztBQUlMLENBQUM7QUFoRlksd0JBQWdCLG1CQWdGNUIsQ0FBQTtBQUFBLENBQUMifQ==

View File

@ -1,11 +1,11 @@
import { SocketFunction } from "./smartsocket.classes.socketfunction"; import { SocketFunction } from "./smartsocket.classes.socketfunction";
import { SocketRequest } from "./smartsocket.classes.socketrequest"; import { SocketRequest, TSocketRequestSide } from "./smartsocket.classes.socketrequest";
import { SocketRole } from "./smartsocket.classes.socketrole"; import { SocketRole } from "./smartsocket.classes.socketrole";
export declare let getSocketFunctionByName: (functionNameArg: string) => SocketFunction; export declare let getSocketFunctionByName: (functionNameArg: string) => SocketFunction;
/** /**
* get corresponding Socketrequest instance by shortId * get corresponding Socketrequest instance by shortId
*/ */
export declare let getSocketRequestById: (shortIdArg: string, requestSide?: "requesting" | "responding") => SocketRequest; export declare let getSocketRequestById: (shortIdArg: string, requestSide?: TSocketRequestSide) => SocketRequest;
/** /**
* get corresponding SocketRole instance by name * get corresponding SocketRole instance by name
*/ */

View File

@ -32,7 +32,7 @@
}, },
"devDependencies": { "devDependencies": {
"npmts-g": "^5.2.8", "npmts-g": "^5.2.8",
"should": "^10.0.0", "should": "^11.0.0",
"typings-test": "^1.0.1" "typings-test": "^1.0.1"
} }
} }

View File

@ -17,7 +17,7 @@ describe("smartsocket", function () {
it("should start listening when .started is called", function () { it("should start listening when .started is called", function () {
testSmartsocket.startServer(); testSmartsocket.startServer();
}); });
it("should react to a new websocket connection", function (done) { it("should react to a new websocket connection from client", function (done) {
this.timeout(10000); this.timeout(10000);
testSmartsocketClient = new smartsocket.SmartsocketClient({ testSmartsocketClient = new smartsocket.SmartsocketClient({
port: testConfig.port, port: testConfig.port,
@ -25,9 +25,21 @@ describe("smartsocket", function () {
password: "testPassword", password: "testPassword",
alias: "testClient1" alias: "testClient1"
}); });
testSmartsocketClient.connect()
.then(() => {
done();
});
});
it("client should disconnect and reconnect", function (done) {
this.timeout(10000);
testSmartsocketClient.disconnect()
.then(testSmartsocketClient.connect)
.then(() => {
done();
});
}); });
it("should close the server", function () { it("should close the server", function () {
testSmartsocket.closeServer(); testSmartsocket.closeServer();
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixNQUFPLFdBQVcsV0FBVyxlQUFlLENBQUMsQ0FBQztBQUU5QyxJQUFJLGVBQXdDLENBQUM7QUFDN0MsSUFBSSxxQkFBb0QsQ0FBQztBQUV6RCxJQUFJLFVBQVUsR0FBRztJQUNiLElBQUksRUFBQyxJQUFJO0NBQ1osQ0FBQTtBQUVELFFBQVEsQ0FBQyxhQUFhLEVBQUU7SUFDcEIsRUFBRSxDQUFDLGlDQUFpQyxFQUFFO1FBQ2xDLGVBQWUsR0FBRyxJQUFJLFdBQVcsQ0FBQyxXQUFXLENBQUMsRUFBRSxJQUFJLEVBQUUsVUFBVSxDQUFDLElBQUksRUFBRSxDQUFDLENBQUM7UUFDekUsZUFBZSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFdBQVcsQ0FBQyxXQUFXLENBQUMsQ0FBQztJQUNsRSxDQUFDLENBQUMsQ0FBQztJQUNILEVBQUUsQ0FBQyxnQ0FBZ0MsRUFBRTtJQUVyQyxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyxnREFBZ0QsRUFBRTtRQUNqRCxlQUFlLENBQUMsV0FBVyxFQUFFLENBQUM7SUFDbEMsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsNENBQTRDLEVBQUUsVUFBVSxJQUFJO1FBQzNELElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyx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xDLENBQUMsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFDLENBQUMifQ==

View File

@ -21,7 +21,7 @@ describe("smartsocket", function () {
it("should start listening when .started is called", function () { it("should start listening when .started is called", function () {
testSmartsocket.startServer(); testSmartsocket.startServer();
}) })
it("should react to a new websocket connection", function (done) { it("should react to a new websocket connection from client", function (done) {
this.timeout(10000); this.timeout(10000);
testSmartsocketClient = new smartsocket.SmartsocketClient({ testSmartsocketClient = new smartsocket.SmartsocketClient({
port: testConfig.port, port: testConfig.port,
@ -29,6 +29,18 @@ describe("smartsocket", function () {
password:"testPassword", password:"testPassword",
alias: "testClient1" alias: "testClient1"
}); });
testSmartsocketClient.connect()
.then(() => {
done();
});
});
it("client should disconnect and reconnect", function (done) {
this.timeout(10000);
testSmartsocketClient.disconnect()
.then(testSmartsocketClient.connect)
.then(() => {
done();
});
}); });
it("should close the server", function () { it("should close the server", function () {
testSmartsocket.closeServer(); testSmartsocket.closeServer();

View File

@ -25,7 +25,9 @@ export class Smartsocket {
*/ */
private _handleSocketConnection(socketArg) { private _handleSocketConnection(socketArg) {
let socketConnection: SocketConnection = new SocketConnection({ let socketConnection: SocketConnection = new SocketConnection({
alias:undefined,
authenticated:false, authenticated:false,
role:undefined,
socket:socketArg socket:socketArg
}); });
plugins.beautylog.log("Socket connected. Trying to authenticate...") plugins.beautylog.log("Socket connected. Trying to authenticate...")
@ -40,7 +42,7 @@ export class Smartsocket {
startServer = () => { startServer = () => {
this.io = plugins.socketIo(this.options.port); this.io = plugins.socketIo(this.options.port);
this.io.on('connection', (socketArg) => { this.io.on("connection", (socketArg) => {
this._handleSocketConnection(socketArg); this._handleSocketConnection(socketArg);
}); });
} }

View File

@ -15,35 +15,45 @@ import { SocketRequest } from "./smartsocket.classes.socketrequest";
export interface ISmartsocketClientOptions { export interface ISmartsocketClientOptions {
port: number; port: number;
url: string; url: string;
alias?:string; // an alias makes ir easier to identify this client in a multo client environment alias:string; // an alias makes it easier to identify this client in a multo client environment
role:string;
password: string; // by setting a password access to functions can be limited password: string; // by setting a password access to functions can be limited
} }
export class SmartsocketClient { export class SmartsocketClient {
alias:string;
role:string;
socketConnection:SocketConnection; socketConnection:SocketConnection;
serverUrl:string; serverUrl:string;
serverPort:number; serverPort:number;
serverPassword:string; serverPassword:string;
constructor(optionsArg:ISmartsocketClientOptions){ constructor(optionsArg:ISmartsocketClientOptions){
this.alias = optionsArg.alias;
this.role = optionsArg.role;
this.serverUrl = optionsArg.url this.serverUrl = optionsArg.url
this.serverPort = optionsArg.port; this.serverPort = optionsArg.port;
this.serverPassword = optionsArg.password this.serverPassword = optionsArg.password
}; };
// authenticates the socket against the server /**
private _handleSocketConnection() { * connect the client to the server
*/
connect(){
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.beautylog.log("trying to connect...");
let socketUrl = `${this.serverUrl}:${this.serverPort}`; let socketUrl = `${this.serverUrl}:${this.serverPort}`;
this.socketConnection = new SocketConnection({ this.socketConnection = new SocketConnection({
alias:this.alias,
authenticated:false, authenticated:false,
socket: plugins.socketIoClient(this.serverUrl,{}) role:undefined,
socket: plugins.socketIoClient(socketUrl,{})
}); });
this.socketConnection.socket.on("requestAuth", function () { this.socketConnection.socket.on("requestAuth", () => {
console.log("server requested authentication"); console.log("server requested authentication");
this.socketConnection.socket.emit("dataAuth", { this.socketConnection.socket.emit("dataAuth", {
role: "coreflowContainer", role: this.role,
password: "somePassword", password: this.serverPassword,
alias: "coreflow1" alias: this.alias
}); });
this.socketConnection.socket.on("authenticated",() => { this.socketConnection.socket.on("authenticated",() => {
console.log("client is authenticated"); console.log("client is authenticated");
@ -52,6 +62,13 @@ export class SmartsocketClient {
}); });
return done.promise; return done.promise;
}; };
disconnect(){
let done = plugins.q.defer();
this.socketConnection.socket.disconnect();
plugins.beautylog.ok("disconnected!");
done.resolve();
return done.promise;
}
serverCall(functionNameArg:string,dataArg:ISocketFunctionCall){ serverCall(functionNameArg:string,dataArg:ISocketFunctionCall){
let done = plugins.q.defer(); let done = plugins.q.defer();
let socketRequest = new SocketRequest({ let socketRequest = new SocketRequest({

View File

@ -12,10 +12,10 @@ import { SocketRole } from "./smartsocket.classes.socketrole";
* interface for constructor of class SocketConnection * interface for constructor of class SocketConnection
*/ */
export interface ISocketConnectionConstructorOptions { export interface ISocketConnectionConstructorOptions {
alias?: string; alias: string;
authenticated: boolean; authenticated: boolean;
role?: SocketRole; role: SocketRole;
socket?: SocketIO.Socket | SocketIOClient.Socket; socket: SocketIO.Socket | SocketIOClient.Socket;
}; };
/** /**
@ -33,16 +33,21 @@ export interface ISocketConnectionAuthenticationObject {
* class SocketConnection represents a websocket connection * class SocketConnection represents a websocket connection
*/ */
export class SocketConnection { export class SocketConnection {
alias?: string; alias: string;
authenticated: boolean; authenticated: boolean;
role?: SocketRole; role: SocketRole;
socket: SocketIO.Socket | SocketIOClient.Socket; socket: SocketIO.Socket | SocketIOClient.Socket;
constructor(optionsArg: ISocketConnectionConstructorOptions) { constructor(optionsArg: ISocketConnectionConstructorOptions) {
this.alias = optionsArg.alias; this.alias = optionsArg.alias;
this.authenticated = optionsArg.authenticated; this.authenticated = optionsArg.authenticated;
this.role = optionsArg.role; this.role = optionsArg.role;
this.socket = optionsArg.socket; this.socket = optionsArg.socket;
}
// standard behaviour that is always true
this.socket.on("disconnect", () => {
plugins.beautylog.info(`Client ${this.alias} disconnected`);
});
};
// authenticating -------------------------- // authenticating --------------------------