redesigned websocket messages

sends messages in JSON now
posts are more responsive
This commit is contained in:
Mystikfluu
2022-07-10 16:37:23 +02:00
parent 83655ad6d1
commit 61eb7a6ee2
2 changed files with 31 additions and 6 deletions
+16 -1
View File
@@ -667,8 +667,23 @@ router.post("/api/post", async function(req,res) {
con.query(sql, values, function (err, result) {
if (err) throw err;
if(req.body.receiver == "everyone") {
let post_obj = {
post_user_name: encodeURIComponent(res.locals.username),
post_text: req.body.message,
post_time: Date.now(),
post_special_text: "",
post_receiver_name: "everyone",
post_from_bot: res.locals.isbot,
post_reply_id: reply_id
}
let message = {
message: "new_post",
data: post_obj
}
let messagestr = JSON.stringify(message)
wss.clients.forEach(function(ws) {
ws.send(`new_post ${res.locals.username} ${req.body.message}`)
ws.send(messagestr)
});
}
res.json({"success":"successfully posted message"})