-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (43 loc) · 1.14 KB
/
server.js
File metadata and controls
54 lines (43 loc) · 1.14 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
47
48
49
50
51
52
53
54
/* eslint func-names: 0 */
/* eslint prefer-arrow-callback: 0 */
/* eslint no-undef: 0 */
/* eslint import/newline-after-import: 0 */
/* eslint no-console: 0 */
const express = require('express');
const app = express();
const path = require('path');
const http = require('http');
const server = http.createServer(app);
const io = require('socket.io')(server);
let numClients = 0;
io.on('connection', (socket) => {
socket.on('join', (respond) => {
numClients++;
respond(numClients);
});
socket.on('send offer', (offer) => {
socket.broadcast.emit('receive offer', offer);
});
socket.on('send answer', (answer) => {
socket.broadcast.emit('receive answer', answer);
});
socket.on('send ice candidate', (candidate) => {
socket.broadcast.emit('receive ice candidate', candidate);
});
socket.on('leave page', () => {
numClients--;
});
});
app.use(express.static(__dirname));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/index.html'));
});
server.listen(3000, () => {
console.log('listening on port 3000');
});
module.exports = {
app,
resetNumClients(num) {
numClients = num;
},
};