Provides easy and secure websocket communication mechanisms, including server and client implementation, function call routing, connection management, and tagging.
Go to file
2016-08-16 04:48:47 +02:00
dist now authenticating sockets by checking the password hash 2016-08-16 04:48:42 +02:00
test now authenticating sockets by checking the password hash 2016-08-16 04:48:42 +02:00
ts now authenticating sockets by checking the password hash 2016-08-16 04:48:42 +02:00
.gitignore update structure 2016-08-07 14:58:20 +02:00
.gitlab-ci.yml initial 2016-08-06 23:27:53 +02:00
npmextra.json reconnect is now working 2016-08-14 22:17:55 +02:00
package.json 1.1.2 2016-08-16 04:48:47 +02:00
README.md update README 2016-08-15 03:47:32 +02:00

smartsocket

easy and secure websocket communication, Typescript ready

Status

build status

Usage

We recommend the use of typescript. Under the hood we use socket.io and shortid for managed data exchange.

Serverside

import * as smartsocket from "smartsocket";

let mySmartsocket = new smartsocket.Smartsocket({
    port: 3000 // the port smartsocket will listen on
});

let mySocketRole = new smartsocket.SocketRole({
    name: "someRoleName",
    passwordHash: "someHashedString"
});

let testSocketFunction1 = new smartsocket.SocketFunction({
    funcName:"testSocketFunction1",
    funcDef:(data) => {
        
    }, // the function to execute
    allowedRoles:[mySocketRole] // all roles that have access to a specific function
});

mySmartsocket.clientCall("","restart",data,someTargetConnection)
    .then((responseData) => {

    });

Client side

import * as smartsocket from "smartsocket";

let testSmartsocketClient = new smartsocket.SmartsocketClient({
    port: testConfig.port,
    url: "http://localhost",
    password: "testPassword",
    alias: "testClient1",
    role: "testRole1"
});
testSmartsocketClient.connect()
    .then(() => {
        done();
    });

let testSocketFunction2 = new smartsocket.SocketFunction({
    funcName: "testSocketFunction2",
    funcDef: (data) => {}, // the function to execute, has to return promise
    allowedRoles:[]
});

let functionCalldata = {
    funcName: "",
    funcData: {
        someKey:"someValue"
    }
}

mySmartsocketClient.serverCall("function",functionCallData)
    .then((functionResponseData) => { // the functionResponseData comes from the server... awesome, right?
        
    });;

NOTE:
you can easily chain dependent requests on either the server or client side with promises.
data is always a js object that you can design for your specific needs.
It supports buffers for large binary data network exchange.