npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

socknet.io

v1.0.27

Published

socket.io library with hook and argument validations

Downloads

4

Readme

Build Status Dependency Status NPM version npm

NPM

Take a look at our get started and documentation on socknet.io

Overview

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 = require('socknet')(80);

socknet.on({
  config: {
    route: '/route',
    args: {},
  }
  on(socket, args, callback) {
    callback(null, 'hello world !')
  }
});

socknet.listen(() => console.log('socknet server is ready'));

client.js

const socket = io();

socket.emit('/route', {}, function(data) {
  console.log('server response', data)
});

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
  }
  before(socket, args, next) {
    // hook if you want to modify payload before passing it to on method
  }
  on(socket, args, next) {
    // main function bind to event
  }
  after(socket, args, next) {
    // hook if you want to modify payload after on method
  }
};

socknet.on(myEvent);
session(Function)

Session method if you need authentication

socknet.session((socket, callback) => {
  // DO DATABASE REQUEST
  // callback error user if unregistered so he can't access to private event
  // callback session the session will be bind to the socket
  callback(null, session);
});
listen(Callback)

Enable events added with on method

socknet.listen(() => {
  console.log(`Server started on port ${port}`);
});

ArgTypes

const ArgTypes = require('socknet').ArgTypes

ArgTypes.integer // Arg must be a integer or null
ArgTypes.integer.isRequired // Arg must be a integer non null
ArgTypes.string // Arg must be a string or null
ArgTypes.string.isRequired // Arg must be a string non null
ArgTypes.objectOf() // Arg must be an object or null
ArgTypes.objectOf().isRequired // Arg must be an object non null
ArgTypes.arrayOf() // Arg must be an array or null
ArgTypes.arrayOf().isRequired // Arg must be an array non null

Full exemple es6

import Socknet, { ArgTypes } from 'socknet';

const port = process.env.PORT || 1337;

const socknet = Socknet(port);

class Event {
  config = {
    return: true,
    route: '/test',
    args: {
      arg1: ArgTypes.string, // the event callback an error if type if not a string null or undefined
    },
  }

  before(socket, args, next) {
    console.log('Im called before on !');
    args.addedByBefore = 'hello world';
    next();
  }

  on(socket, args, next) {
    console.log(args.arg1); // your argument
    // argument added by before hook
    console.log(args.addedByBefore); // -> show 'hello world'
    next(null, { code: 200, response: { message: 'request done' }}); // your response
  }

  after(socket, response, next) {
    // response is the data send by on callback
    console.log(response); // show -> { code: 200, response: { message: 'request done' }}
    next(null, 'new data'); // override response send by On
  }
}

// Bind event to socknet instance
socknet.on(new Event);

// Start listening
socknet.listen(() => {
  console.log(`Server is listening on ${port}`)
});