1.2.0 • Published 5 years ago

@kiyasov/sticky-session v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

stickySession

A simple performant way to use socket.io with a cluster.

Installation

npm install @kiyasov/sticky-session --save-dev

Usage

import http from "http";
import cluster from "cluster";
import StickySession from "../lib";
import SocketIO from "socket.io";
import express from "express";
import SocketIORedis from "socket.io-redis";

let stickySession = new StickySession({
  listen: [3000, '127.0.0.1'],
  workers: 4
});

const app = express();
const server = http.Server(app);
const socket = SocketIO(server);

socket.adapter(SocketIORedis({ host: '127.0.0.1', port: 6379 }));

if (!stickySession.listen(server)) {
  // Master code
  server.once("listening", () => console.log("server started on 3000 port"));
} else {
  socket.on("connection", client => {
      console.log('a user connected');
      
      client.on("disconnect", client => {
        console.log('a user disconnect');
      });
  });
}

Simple

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago