Skip to content

Instantly share code, notes, and snippets.

@aslamanver
Last active July 5, 2020 14:29
Show Gist options
  • Save aslamanver/0f92539db8077cd39db5387a54b9918e to your computer and use it in GitHub Desktop.
Save aslamanver/0f92539db8077cd39db5387a54b9918e to your computer and use it in GitHub Desktop.
Simple Usage | Socket.IO Session Handler for Node.js
const app = require('express')()
const http = require('http').Server(app)
const io = require('socket.io')(http)
// Initialization
const session_handler = require('io-session-handler').from(io)
/**
* Connection returns - Token, ID and the Status (1 - connected, 0 - Disconnected)
*
* { id: '123', token: '5200cc4a59795529', status: 1 }
*
**/
session_handler.connectionListener((connection) => {
console.log(connection)
})
http.listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment