Releases: IamLizu/sockmanage
Releases · IamLizu/sockmanage
v1.0.3
v1.0.2
v1.0.2
- Refactor
getSockets
to returnthis.userSockets
directly instead of using Redis. - Refactor
getSocket
to returnthis.userSockets.get(userId)
directly instead of using Redis.
What's Changed
- refactor:
getSocket
andgetSockets
by @IamLizu in #10 - docs: update definitions for
getSocket
andgetSockets
by @IamLizu in #11
Full Changelog: v1.0.1...v1.0.2
v1.0.1
v1.0.1
- Clean
registerSocketForUser
method- Add
extractUserId
method (private): Parses and validatesuserId
from incoming data, throwing an error ifuserId
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
- Add jsdoc comments to all methods
- Add example in class documentation
- Shortened public method names for simplicity:
initializeUserSockets
is nowinitialize
getUserSockets
is nowgetSockets
getUserSocket
is nowgetSocket
registerSocketForUser
is nowregister
deRegisterSocketForUser
is nowderegister
informSocket
remains asinform
- 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
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.