-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsocket.js
44 lines (39 loc) · 1.21 KB
/
socket.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
42
43
44
const Percakapan = require("./model/Percakapan");
const Pemateri = require("./model/Pemateri");
const DetailWorkshop = require("./model/Detail_workshop");
const Status = require("./model/Status");
const jwt = require("jsonwebtoken");
module.exports = function(io, socket) {
socket.on("percakapan", function(id_workshop) {
Percakapan.findAll({
where: { id_workshop },
include: { model: Pemateri },
order: [["id_percakapan", "ASC"]]
}).then(function(rows) {
rows.forEach(row => {
if (row.pemateri == null)
row.set("peserta", {
nama: jwt.verify(row.id_pengirim, "randomStuff")
});
});
io.sockets.emit("percakapan", rows);
});
});
socket.on("detail", function(id_workshop) {
DetailWorkshop.findAll({
where: { id_workshop },
include: { model: Status }
}).then(function(rows) {
rows.forEach(row => {
row.set("peserta", { nama: jwt.verify(row.id_peserta, "randomStuff") });
});
socket.broadcast.emit("detail", rows);
});
});
socket.on("task", function(task) {
socket.broadcast.emit("task", task);
});
socket.on("resetStatus", function() {
socket.broadcast.emit("resetStatus");
});
};