-
Notifications
You must be signed in to change notification settings - Fork 0
Message socket
This is the message socket, this socket as the name suggests sends a message by emitting it to the clients and storing it in the database by using the 'server-message' event. As I mentioned before, we are NOT using the default websockets, we are using the socket.io library for web sockets. Anyways, this socket excepts a 'message' argument for the message to be sent (This argument contains an object which contains id, user(The sender), content, room(Room of the message).), a 'key' argument for the API key and a 'token' for the response token.
If you would like to listen for a message, you can listen to the 'client-message' this event will return the message sent when a new message is sent with the 'server-message'. There is an example below on how to use it.
A response token is a token to send a request to if an error occurs.
const io = require("socket.io");
const socket = io("<URL>", { transports: ["websocket"] });
const message = {
id: "<ID>",
user: "<SENDER>",
content: "<CONTENT>",
room: "<ROOM>",
};
// Send to server
socket.emit("server-message", message, "<API_KEY>", "<TOKEN>");
socket.on("client-message:room(<ROOM>)", (message) => {
/* This will run when a message of the same room is sent */
console.log(message);
});
- Home
- Login endpoint
- Block user endpoint
- Create room endpoint
- Delete user endpoint
- Get all rooms endpoint
- Get GIF endpoint
- Get messages endpoint
- Get public rooms endpoint
- Get user info endpoint
- Get users info endpoint (Deprecated)
- Join room endpoint
- Signup endpoint
- Report room endpoint
- Remove room endpoint
- Update description endpoint
- Follow user endpoint
- Unfollow user endpoint
- Update icon color endpoint
- Upload content endpoint
- Upload content endpoint (Deprecated)
- Verify client endpoint
- Upload token endpoint
- Chill&chat websockets
- Message socket
- Keyboard socket
- Delete message socket
- User content
- Final words&thoughts
- Run API