-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (33 loc) · 1.12 KB
/
Copy pathserver.js
File metadata and controls
35 lines (33 loc) · 1.12 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
require("dotenv").config();
const express = require("express");
const http = require("http");
const app = express();
const server = http.createServer(app);
const socket = require("socket.io");
const io = socket(server);
const path=require("path");
if(process.env.NODE_ENV==="production"){
app.use(express.static(path.join(__dirname,'./video-chat/build')));
app.get('*',(req,res)=>{
res.sendFile(path.join(__dirname,'./video-chat/build/index.html'));
});
}
const users = {};
io.on('connection', socket => {
if (!users[socket.id]) {
users[socket.id] = socket.id;
}
socket.emit("yourID", socket.id);
io.sockets.emit("allUsers", users);
socket.on('disconnect', () => {
delete users[socket.id];
})
socket.on("callUser", (data) => {
io.to(data.userToCall).emit('hey', {signal: data.signalData, from: data.from});
})
socket.on("acceptCall", (data) => {
io.to(data.to).emit('callAccepted', data.signal);
})
});
var server_port = process.env.YOUR_PORT || process.env.PORT || 5000;
server.listen(server_port, () => console.log('server is running on port 5000'));