Docs
About
Socketry allows for an easy way to set up websocket servers and clients. It is built to allow anybody to easily set up websockets without any hastle.
-
Use
Socketry has an easy way to access all of the clients connected to the server.
const Socket = ;const server = 8080; console; // array
You can filter through these clients to target the current client as well, since each client has their own unique id. You can find it by just using client.id
.
-
Basic server file
To start using socketry, you will need a server file.
const Socket = ;// Create a new server on port `8080`const server = 8080;// Create a room that messages will be sent to (can have multiple rooms)const room = 'foo';const room2 = 'bar'; // Fires when a client connects to the serverserver;
This is just the barebones of a server. It just receives the websockets, and sends them out again to each client.
-
Basic client file
You will also need a way to communicate to the server. You can do this in node by using another barebones file.
const Socket = ;// Create a client that connects to localhost, on port `8080`const socket = 'ws://localhost:8080'; // Fires when connected to a serversocket;
Rooms
The websockets are split into rooms. This means that you can have something that acts as two or more servers, when it's really just one! This means you can host the socket server on one node process. The server can do whatever it wants with the rooms messages. When a message is recieved, the server can send it to all teh clients in the room, just a few clients, or to every room. This would be good for if you wan't to make announcements to every room about an event or such.
.send()
When sending with the client, you send an object. You can have any property inside the object, as long as the server will accept it.