A simple client and server side library to simplify handling rooms in socket.io.
- Easily Join and Leave rooms.
- Room restrictions (Limited Room sizes, passwords)
- Broadcast messages within room
- and more...
- Initialize socket.io server:
const { Server } = require("socket.io");
const io = new Server(/* Ensure the options here are set correct for socket.io work */);
View socket.io docs for socket.io server initialization.
- Provide Socket-Rooms with initialized socket.io instace:
const { SocketRoomsServer } = require('socket-rooms');
SocketRoomsServer.init(io);
- Initialize socket.io:
import { io } from 'socket.io-client';
- Initialize socket-rooms:
import { SocketRoomsClient } from 'socket-rooms';
SocketRoomsClient.init(io()).then(() => {
// Can now perform socket-rooms functions
});
<script src="/socket-rooms/Client.js"></script>
SocketRoomsClient.init(io()).then(() => {
// Can now perform socket-rooms functions
});
Usage: SocketRoomsServer.<methodName>()
Initializes Socket-Rooms for server
socket_IO_Instance object
: a socket.io instance, see Server Setup part of this doc.
Creates a room with a user provided ID.
roomId string
: an ID for the room
capacity number
: max capacity for the room (Needs Implementation Still)
Usage: SocketRoomsClient.<methodName>()
Initializes Socket-Rooms for client
socket_IO_Instance object
: a socket.io instance, see Server Setup part of this doc.
Adds client to room. Returns a promise which resolves/rejects based on if client was able to join the room.
roomId string
: ID for the room to join
responseCallback Function
: a callback function that will execute where an event is sent to this room
Add/Update callback for a specific room. Will only call if user has privously joined room
roomId string
: ID for the room to join
responseCallback Function
: a callback function that will execute where an event is sent to this room
Send a message to room
roomId string
: ID of room to send message to
message any
: the payload that should be sent to the room
Returns list of rooms client has joined.