-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (40 loc) · 1.08 KB
/
server.js
File metadata and controls
46 lines (40 loc) · 1.08 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
36
37
38
39
40
41
42
43
44
45
46
import express from 'express';
import { createServer } from 'http';
import { Server } from 'socket.io';
import cors from 'cors';
const app = express();
app.use(cors({
origin: [
'https://click2call.ai',
'https://www.click2call.ai',
// Add any other domains that need to connect
],
methods: ['GET', 'POST'],
credentials: true
}));
const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origin: [
'https://click2call.ai',
'https://www.click2call.ai'
],
methods: ['GET', 'POST'],
credentials: true
}
});
io.on("connection", (socket) => {
console.log("Client connected:", socket.id);
socket.on("signal", (data) => {
console.log("Signal received:", data);
// Broadcast to all other clients
socket.broadcast.emit("signal", data);
});
socket.on("disconnect", () => {
console.log("Client disconnected:", socket.id);
});
});
const PORT = process.env.PORT || 3000;
httpServer.listen(PORT, () => {
console.log(`Socket.io server running on port ${PORT} in ${process.env.NODE_ENV || 'development'} mode`);
});