-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (38 loc) · 990 Bytes
/
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
42
43
44
45
46
47
48
49
50
import express from 'express'
import cors from 'cors'
import { createServer } from 'http'
import { Server } from 'socket.io'
const app = express()
app.use(cors())
app.use(express.json())
app.use(
express.urlencoded({
extended: true,
})
)
const httpServer = createServer(app)
const io = new Server(httpServer, {
cors: {
origin: '*',
},
path: '/kishan/video',
})
const PORT = process.env.PORT || 7000
app.get("/", (req, res) => {
res.send(`Server running on ${PORT}`)
})
io.on("connection", (socket) => {
socket.emit('me', socket.id)
socket.on('disconnect', () => {
socket.broadcast.emit("callended")
})
socket.on("calluser", ({ userToCall, signalData, from, name}) => {
io.to(userToCall).emit("calluser", {signal:signalData,from,name})
})
socket.on("answercall", (data)=> {
io.to(data.to).emit("callaccepted", data.signal)
})
});
httpServer.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`)
})