-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (39 loc) · 1.23 KB
/
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
require('dotenv').config();
const express = require('express');
const { createServer } = require('node:http');
const app = express();
const server = createServer(app);
app.get("/", (req, res) => {
res.send("Server is running ... ")
});
const PORT = process.env.PORT || 5678;
server.listen(PORT, () => {
console.log(`Server is running on port ${process.env.PORT || 5678}`);
console.log(`http://localhost:${process.env.PORT || 5678}`);
});
const io = require('socket.io')(server, {
cors: {
origin: "*",
method: ["GET", "POST"]
}
});
io.on('connection', (socket) => {
console.log("A user connected", socket.id);
socket.on("disconnect", () => {
console.log("A user disconnected", socket.id);
});
socket.on("call-user", (data) => {
console.log("received a call-user:", socket.id, "to :", data.to);
io.to(data.to).emit("call-mode", {
from: socket.id,
signalData: data.signalData,
});
});
socket.on("call-answer", (data) => {
console.log("received a answer-user:", socket.id, "to :", data.to);
io.to(data.to).emit("answer-mode", {
// from: socket.id,
signalData: data.signalData,
});
});
});