I’m making a message exchange system, and I need to make sure that the message sent by a user was sent via websocket.
Below is the socket code and after creating the message within the database.
socket.emit("send-msg", {
content,
friendsId,
userId,
receiverId,
});
const message = prisma.message.create({
data: {
content,
friendsId,
userId,
},
});
I need to make sure that socket.emit has worked, to prevent a message from being created but not sent over the socket.
This is the main action performed with it:
if (receiverUser !== undefined) {
io.to(receiverUser.socketId).emit("msg-recieve", {
userId,
friendsId,
content,
});
}