Skip to content

Releases: IamLizu/sockmanage

v1.0.3

30 Oct 06:32
v1.0.3
c13c0b5
Compare
Choose a tag to compare

What's Changed

Full Changelog: v1.0.2...v1.0.3

v1.0.2

30 Oct 05:14
v1.0.2
cde7c58
Compare
Choose a tag to compare

v1.0.2

  • Refactor getSockets to return this.userSockets directly instead of using Redis.
  • Refactor getSocket to return this.userSockets.get(userId) directly instead of using Redis.

What's Changed

  • refactor: getSocket and getSockets by @IamLizu in #10
  • docs: update definitions for getSocket and getSockets by @IamLizu in #11

Full Changelog: v1.0.1...v1.0.2

v1.0.1

29 Oct 18:40
v1.0.1
f7c7a66
Compare
Choose a tag to compare

v1.0.1

  • Clean registerSocketForUser method
    • Add extractUserId method (private): Parses and validates userId from incoming data, throwing an error if userId is missing.
    • Add handleExistingConnection method (private): Checks and disconnects existing sockets for a user, ensuring only one active connection.
    • Add saveUserSocketsToRedis method (private): Manages Redis persistence of active user sockets, updating data after each connection change.
  • Add jsdoc comments to all methods
  • Add example in class documentation
  • Shortened public method names for simplicity:
    • initializeUserSockets is now initialize
    • getUserSockets is now getSockets
    • getUserSocket is now getSocket
    • registerSocketForUser is now register
    • deRegisterSocketForUser is now deregister
    • informSocket remains as inform
  • Deprecated: Original method names remain for backward compatibility but will be removed in future versions. Using these names now triggers a warning.
  • Add missing use of initialize method

What's Changed

  • docs: add history by @IamLizu in #2
  • Refactor/clean code by @IamLizu in #6
  • docs: add js doc and example in class by @IamLizu in #7
  • refactor: simplify methods and add deprecated warning for old methods by @IamLizu in #8
  • docs: add missing instruction step for initialize by @IamLizu in #9

Full Changelog: v1.0.0...v1.0.1

v1.0.0

29 Oct 12:30
v1.0.0
f950604
Compare
Choose a tag to compare

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.