-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
47 lines (34 loc) · 956 Bytes
/
app.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
const express = require('express')
const socketio = require('socket.io')
const http = require('http')
const cors = require('cors')
const axios = require("axios");
const PORT = 4000;
const app = express()
const server = http.createServer(app)
const io = socketio(server,{
cors:{
origin:"*",
}
})
app.use(cors())
io.on("connection", (socket) => {
socket.on("join", (roomId) => {
socket.join(roomId);
socket.to(roomId).emit("welcome");
console.log("j")
});
socket.on("offer", (offer, roomId) => {
socket.to(roomId).emit("offer", offer);
console.log("o")
});
socket.on("answer", (answer, roomId) => {
socket.to(roomId).emit("answer", answer);
console.log("a")
});
socket.on("ice", (ice, roomId) => {
socket.to(roomId).emit("ice", ice);
console.log("i")
});
});
server.listen(PORT, () => console.log(`서버 포트 : ${PORT} `))