Socknet
socknet.io
Take a look at our get started and documentation onOverview
socknet.io enables real-time bidirectional modular and secure event-based communication.
It's inspired by react component declaration style for event creation focusing on lisibility, modularity and security. Fully compatible with socket.io client it works on every platform, browser or device, focusing equally on reliability, and speed.
How to use
Installing
$ npm install --save socknet
Basic usage
server.js
const socknet = 80; socknet; socknet;
client.js
const socket = ; socket;
Socknet api
on(Object)
On method create your event base on Object param it can contain the following attributes
const myEvent = // Event configuration config: route: '/route' // Name of the event args: {} // Argument of your event for payload verification with ArgTypes requireSession: false // Socket must be authenticated for call this event { // hook if you want to modify payload before passing it to on method } { // main function bind to event } { // hook if you want to modify payload after on method }; socknet;
session(Function)
Session method if you need authentication
socknet;
listen(Callback)
Enable events added with on method
socknet;
ArgTypes
const ArgTypes = ArgTypes ArgTypesinteger // Arg must be a integer or nullArgTypesintegerisRequired // Arg must be a integer non nullArgTypesstring // Arg must be a string or nullArgTypesstringisRequired // Arg must be a string non nullArgTypes // Arg must be an object or nullArgTypesisRequired // Arg must be an object non nullArgTypes // Arg must be an array or nullArgTypesisRequired // Arg must be an array non null
Full exemple es6
; const port = processenvPORT || 1337; const socknet = ; config = return: true route: '/test' args: arg1: ArgTypesstring // the event callback an error if type if not a string null or undefined { console; argsaddedByBefore = 'hello world'; ; } { console; // your argument // argument added by before hook console; // -> show 'hello world' ; // your response } { // response is the data send by on callback console; // show -> { code: 200, response: { message: 'request done' }} ; // override response send by On } // Bind event to socknet instancesocknet; // Start listeningsocknet;