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

io-session-handler

v1.0.74

Published

Socket session handler for Socket.IO

Downloads

94

Readme

Pure JavaScript Module for Session Handling | NPM

IO

Socket session handler for Socket.IO

NPM Version NPM Downloads Linux Build

Simple Implementation

const app = require('express')()
const http = require('http').Server(app)
const io = require('socket.io')(http)

const session_handler = require('io-session-handler').from(io)

/**
 * Connection returns - Token, ID and the Status (1 - connected, 0 - Disconnected)
 * 
 * { id: 'm3aEHZZK2f8WfG3uAAAA', token: '5200cc4a59795529', status: 1 }
 * 
 **/
session_handler.connectionListener((connection) => {
    console.log(connection)
})

http.listen(3000)

This array contains all the concurrent sessions session_handler.sessions

session_handler.sessions

The response will be

[
  {
    "token": "5200cc4a59795529",
    "connections": [
      "I_XzAcQOeIKw8EeMAAAA"
    ],
    "data": {
      "lat": 6.836772412061691,
      "lon": 79.87546253018081
    }
  }
]

Disconnect timeout can be changed using the from method options.

const session_handler = require('io-session-handler').from(io, { timeout: 5000 })

Client Connection

You can connect from Web-Client, iOS or Android

HTML / JavaScript

const socket = io({ query: { token: 'client-token' } })

Java

public Socket connect(String token) {
    IO.Options opts = new IO.Options();
    opts.query = "token=" + token
    Socket mSocket = IO.socket("http://127.0.0.1:3000", opts);
    mSocket.connect();
    return mSocket;
}

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 0.10 or higher is required.

Installation is done using the

$ npm i io-session-handler

Sample Project - Demo

This is a demo project.

Advanced Usage | Push & Broadcast Messages

You can send broadcast message to all client sessions at once.

session_handler.broadcastMessage(data)

The push method is capable of sending a push message to only a specific client session and this method returns a boolean value when the session is identified as valid.

let sent = session_handler.pushMessage(client_token, data)

Once the message is delivered to the client, onMessageDelivered method will be triggered with the token of the client and the data it received.

session_handler.onMessageDelivered((data) => {
    console.log(data)
})

The data onMessageDelivered contains;

{
   "token":"Token-1",
   "data":"Some awesome data I received"
}

Client Implementation | Push & Broadcast Messages

Once the client received the push message it should emit to push_message_delivery with the data it receives and the token to let the server understand it's delivered to a certain client.

{
   "token":"client_token",
   "data":"Some awesome data I received"
}

The client should on the push_message event to receive push messages from server

Android client library is available at SCM - SCMessaging

License

MIT