-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
47 lines (39 loc) · 1.31 KB
/
server.js
File metadata and controls
47 lines (39 loc) · 1.31 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
const express = require('express');
const http = require('http');
const app = express();
const server = http.createServer(app).listen(3001);
const io = require('socket.io').listen(server);
const os = require('os');
let broadcasterExist = false;
const ifaces = os.networkInterfaces();
app.use(express.static(__dirname + '/build'));
app.get('*', function(req, res){
res.sendFile(__dirname + '/build/index.html');
});
io.on('connection', function(socket){
socket.on('stream', function(event) {
io.emit('stream', event);
})
socket.on('caston', () => broadcasterExist = true);
socket.on('castoff', () => broadcasterExist = false);
socket.on('isAbleToBroadcast', () => {
io.emit('isAbleToBroadcast', !broadcasterExist);
});
Object.keys(ifaces).forEach(function (ifname) {
var alias = 0;
ifaces[ifname].forEach(function (iface) {
if ('IPv4' !== iface.family || iface.internal !== false) {
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
return;
}
if (alias >= 1) {
// this single interface has multiple ipv4 addresses
console.log(ifname + ':' + alias, iface.address);
} else {
// this interface has only one ipv4 adress
io.emit('joinurl', (iface.address || '').concat(':3001'))
}
++alias;
});
});
});