Skip to content

v1.0.0

Compare
Choose a tag to compare
@IamLizu IamLizu released this 29 Oct 12:30
· 25 commits to master since this release
v1.0.0
f950604

v1.0.0 - Initial Release

SockManage is now live! This initial release offers essential tools for managing single active WebSocket connections per user, providing efficient connection handling for scalable applications.

Key Features:

  • Single Active Connection per User: Maintains one active WebSocket connection per user, automatically disconnecting any prior connections.
  • Redis-Powered Persistence: Uses Redis to persist active user sockets, ensuring consistent connection management across distributed servers.
  • User Socket Management:
    • Register and Deregister Sockets: Easily register and deregister user-specific sockets.
    • Retrieve User Socket: Fetch the active socket ID for any user.
  • Emit Events to Specific Users: Target specific users with messages or events.
  • Flexible Namespace Support: Optionally configure namespaces for precise connection management.

Usage Example

import { createClient } from "redis";
import { Server as SocketIOServer } from "socket.io";
import { SockManage } from "sockmanage";

const redisClient = createClient();
const io = new SocketIOServer(server);

const sockManage = new SockManage({ redis: redisClient });
sockManage.setup({ io });

io.on("connection", (socket) => {
    const userId = socket.handshake.query.userId;
    sockManage.registerSocketForUser(socket, JSON.stringify({ userId }));

    socket.on("disconnect", () => {
        sockManage.deRegisterSocketForUser(socket);
    });
});

Notes:

  • Ensure Redis is properly configured to enable persistence across server instances.
  • Compatible with Node.js 20 and Socket.IO environments.

Thank you for using SockManage! We look forward to your feedback and contributions to help make WebSocket management scalable and efficient.