-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.js
31 lines (31 loc) · 1.02 KB
/
Server.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
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server)
const { v4: uuidv4 } = require('uuid');
const { ExpressPeerServer } = require('peer');
const path = require('path');
const peerServer = ExpressPeerServer(server,{
debug:true
});
app.set('view engine','ejs');
app.set('views', path.join(__dirname,'./Views'));
app.use(express.static('public'));
app.use('/peerjs',peerServer);
app.get('/',(req,res)=>{
res.redirect(`/${uuidv4()}`);
})
app.get('/:Room',(req,res)=>{
res.render('Room',{roomId: req.params.room})
})
io.on('connection',socket => {
socket.on('join-room',(roomId,userId)=>{
socket.join(roomId);
//socket.to(roomId).emit('user-connected', userId);
socket.broadcast/*.to(roomId)*/.emit('user-connected',userId);
socket.on('message',message => {
io./*to(roomId).*/emit('createMessage',message)
})
})
})
server.listen(process.env.PORT||3030);