Giter Site home page Giter Site logo

anonkey / socknet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leon3s/socknet

0.0 2.0 0.0 628 KB

PropTypes style for secure your socket.io application

Home Page: https://leon3s.github.io/socknet/

CSS 14.63% JavaScript 36.46% HTML 48.91%

socknet's Introduction

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'));

socknet's People

Watchers

James Cloos avatar tt rt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.