Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (41 loc) · 1.38 KB
/
Copy pathindex.js
File metadata and controls
59 lines (41 loc) · 1.38 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// const express = require("express");
const express = require('express');
const app = express();
const handlebars = require("express-handlebars");
const http = require("http").Server(app);
const io = require("socket.io")(http);
//To holding users information
const socketsStatus = {};
//config and set handlebars to express
const customHandlebars = handlebars.create({ layoutsDir: "./views" });
app.engine("handlebars", customHandlebars.engine);
app.set("view engine", "handlebars");
//enable user access to public folder
app.use(express.static("public"));
app.get("/home" , (req , res)=>{
res.render("index");
});
io.on("connection", function (socket) {
const socketId = socket.id;
socketsStatus[socket.id] = {};
console.log("connect");
socket.on("voice", function (data) {
var newData = data.split(";");
newData[0] = "data:audio/ogg;";
newData = newData[0] + newData[1];
for (const id in socketsStatus) {
if (id != socketId && !socketsStatus[id].mute && socketsStatus[id].online)
socket.broadcast.to(id).emit("send", newData);
}
});
socket.on("userInformation", function (data) {
socketsStatus[socketId] = data;
io.sockets.emit("usersUpdate",socketsStatus);
});
socket.on("disconnect", function () {
delete socketsStatus[socketId];
});
});
http.listen(3000, () => {
console.log("the app is run in port 3000!");
});