Archived
4
1
Fork 0

Get host dynamicly

This commit is contained in:
Simon Giesel 2018-04-27 14:38:19 +02:00
parent 6269c3abc5
commit ce4845d0e8
2 changed files with 38 additions and 2 deletions

View file

@ -11,8 +11,34 @@ const express = require('express'),
const scores = JSON.parse(fs.readFileSync('scores.json', 'utf8')); const scores = JSON.parse(fs.readFileSync('scores.json', 'utf8'));
// Detect local IP
let os = require('os');
let ifaces = os.networkInterfaces();
let ip;
Object.keys(ifaces).forEach(function (ifname) {
let 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
console.log(ifname, iface.address);
ip = iface.address;
}
++alias;
});
});
/** CONSTANTS */ /** CONSTANTS */
const HOST = 'http://100.119.37.224:8080/client/'; const HOST = 'http://' + ip + ':8080/client/';
const players = [ const players = [
{ {
@ -145,6 +171,8 @@ monitorNSP.on('connection', socket => {
socket.emit('handshake', { socket.emit('handshake', {
scores, scores,
marioURL: HOST + players[0].id,
luigiURL: HOST + players[1].id,
marioId: players[0].id, marioId: players[0].id,
luigiId: players[1].id, luigiId: players[1].id,
}); });

View file

@ -96,7 +96,12 @@
</head> </head>
<lobby> <lobby>
<h1>Super <h1>Super
<span style="color:#E53935;">M</span><span style="color:#4CAF50;">A</span><span style="color:#FFC107;">R</span><span style="color:#3F51B5;">I</span><span style="color:#4CAF50;">O</span></h1> <span style="color:#E53935;">M</span>
<span style="color:#4CAF50;">A</span>
<span style="color:#FFC107;">R</span>
<span style="color:#3F51B5;">I</span>
<span style="color:#4CAF50;">O</span>
</h1>
<h2 style="opacity:1;">QR-Code scannen um zu spielen</h2> <h2 style="opacity:1;">QR-Code scannen um zu spielen</h2>
<flexbox> <flexbox>
<mario> <mario>
@ -199,7 +204,10 @@
document.querySelector('ol[start="1"]').innerHTML = ''; document.querySelector('ol[start="1"]').innerHTML = '';
document.querySelector('mario a img').src = 'assets/mario.qr.png?' + options.marioId; document.querySelector('mario a img').src = 'assets/mario.qr.png?' + options.marioId;
document.querySelector('luigi a img').src = 'assets/luigi.qr.png?' + options.luigiId; document.querySelector('luigi a img').src = 'assets/luigi.qr.png?' + options.luigiId;
document.querySelector('mario a').href = options.marioURL;
document.querySelector('luigi a').href = options.luigiURL;
scores = options.scores.sort(sortHighToLow).reverse(); scores = options.scores.sort(sortHighToLow).reverse();
offset = 0;
console.log(scores); console.log(scores);
for (let i in scores) { for (let i in scores) {
if (!scores[i].name) if (!scores[i].name)