Extensor
Extend functions to the socket.io.
Currently implemented:
- Handler authentication;
- Grant unique connections;
- Made easy the serialization with schemapack.
Next:
- Serialization in acknowledge
PR's are welcome.
Contents
Install
npm install extensor
Examples
Binary serialization with schemapack
; // create a schema mapconst parser schemas = parsers; // On both, server and client// initialize socketio with the extensor generated parserconst io = ; // You can encode an object, if you need, like this:const binary = schemasmessage;console; // => { content: "hi": ts: 159798894154 }
- All emitted "message" events are binary, according with the schema;
- Here we not use 2 packets like in socket.io-parser binary event.
- For the events that not in list, JSON parser is used.
Schemapack are the smallest JavaScript object serialization library.
schemapack
All supported types and more info, you find atAuthentication
Server
;; const io = ; auth; io;
Client
; const socket = ; socket;
Blocking multiple connections
To use in a cluster, you need an external storage, current have adapters for redis and ioredis modules.
Server
; ... ;
To catch a multiple attemp on client:
socket;
API
parsers.schemapack( map: Object ): { parser: { Encoder, Decoder }, schemas, idmap }
Create a schemapack parser for both Socket.io server and client.
auth.server( io: SocketIO.Server, handler({ socket, data, done })[, options: Extensor.Options ]): void
Create a server middleware to handle authentication
auth.client( io: SocketIOClient.Socket, data[, callback(error?: string)]): Promise | void
Send credential to server
unique( io: SocketIO.Server [, options: ExtensorOptions ] )
Create a step on the server to force a single connection
License
MIT