Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

socknet

3.0.4 • Public • Published

Socknet

Build Status Dependency Status NPM version npm

NPM

Overview

Socknet hook any socket.io like library that allow you to use joi validation schema before calling your all your events.

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

You can replace socket.io by socknet

server.js

const { ArgTypes } = require('socknet');
const socknet = require('socknet')(1337);
 
function testEvent(args, callback) {
  callback(null, args);
};
 
// To see all posibility refer to https://github.com/hapijs/joi/blob/v13.3.0/API.md
testEvent.argTypes = [
  ArgTypes.object({
    string: ArgTypes.string(),
  }),
]
 
// To see all posibility refer to https://socket.io/docs/
socknet.on('connection', (socket) => {
  // event /test now have arguments protection
  socket.on('/test', testEvent);
});

Or you can just require socknet before socket.io it's will work too

server.js

require('socknet');
const io = require('socket.io');

anyware.js

const joi = require('joi');
 
function testEvent(args, callback) {
  callback(null, args);
};
 
// To see all posibility refer to https://github.com/hapijs/joi/blob/v13.3.0/API.md
testEvent.argTypes = [
  joi.object({
    string: joi.string(),
  }),
  joi.func().isRequired(),
]
 
io.on('connection', (socket) => {
  socket.on('/test', testEvent);
});
 
io.listen(() => console.log('socknet server is ready'));

install

npm i socknet

Downloadsweekly downloads

5

version

3.0.4

license

ISC

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability