-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (56 loc) · 1.76 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const express = require('express');
const app = express();
const cors = require('cors');
const { createServer } = require('http');
const { Server } = require('socket.io');
const httpServer = createServer();
const io = new Server(httpServer, {
cors: {
origin: '*',
},
});
app.use(
cors({
origin: '*',
})
);
app.use('/health', () => {
return 'ok';
});
app.get('/', (req, res) => {
res.send('Hello World');
});
io.on('connection', (socket) => {
socket.emit('Hi sockets established');
socket.on('join room', (roomId) => {
console.log('socket room *' + roomId + '* created...');
socket.join(roomId);
});
// socket.on('triggering', (payload) => {
// console.warn('triggering');
// io.to(payload.room).emit('triggered', payload);
// });
// //emit recevied message to specified room
// socket.on('sending signal', (payload) => {
// console.log('sending signal coming:' + payload);
// io.to(payload.room).emit('received signal', payload.signal);
// });
// socket.on('returning signal', (payload) => {
// console.log('receiving signal coming:' + payload);
// io.to(payload.room).emit('returned signal', payload.signal);
// });
socket.on('send offer', (payload) => {
console.warn('payload', payload);
io.to(payload.room).emit('send offer', payload.offer);
});
socket.on('send answer', (payload) => {
console.warn('payload', payload);
io.to(payload.room).emit('send answer', payload.answer);
});
});
// Comment the below 2 lines if you are pushing for Heroku
// io.listen(3000);
// console.log(`Signaling Sever Started at Port 3000`);
//Uncomment below lines if you are pushing for Heroku
io.listen(process.env.PORT || 5000);
console.log(`Signaling Sever Started at Port ${process.env.PORT || 5000}`);