-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require('dotenv').config();
const { instrument } = require("@socket.io/admin-ui");
const io = require("socket.io")(process.env.PORT, {
cors: {
origin: ["https://admin.socket.io", process.env.CLIENT_URL],
credentials: true,
},
});
io.on("connection", (socket) => {
socket.on("start", (uid) => {
socket.join(uid);
console.log("Connected to socket.io " + uid);
});
socket.on("notification", ({ to, category }) => {
socket.in(to).emit("new notification", { to, category });
});
socket.on("relation change", ({ body, category }) => {
socket.in(body.to).emit("relation update", { from: body.from, category });
});
// socket.on("typing", (room) => socket.in(room).emit("typing"));
// socket.on("stop typing", (room) => socket.in(room).emit("stop typing"));
socket.on("message sent", (newMessageRecieved, to) => {
socket.in(to).emit("new message", newMessageRecieved);
});
socket.on("delete message", ({ userId, messageId, conversationId }) => {
socket
.in(userId)
.emit("deleted message", { messageId, conversationId, userId });
});
});
instrument(io, {
auth: false,
});