Get host dynamicly
This commit is contained in:
parent
6269c3abc5
commit
ce4845d0e8
2 changed files with 38 additions and 2 deletions
30
server.js
30
server.js
|
@ -11,8 +11,34 @@ const express = require('express'),
|
|||
|
||||
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 */
|
||||
const HOST = 'http://100.119.37.224:8080/client/';
|
||||
const HOST = 'http://' + ip + ':8080/client/';
|
||||
|
||||
const players = [
|
||||
{
|
||||
|
@ -145,6 +171,8 @@ monitorNSP.on('connection', socket => {
|
|||
|
||||
socket.emit('handshake', {
|
||||
scores,
|
||||
marioURL: HOST + players[0].id,
|
||||
luigiURL: HOST + players[1].id,
|
||||
marioId: players[0].id,
|
||||
luigiId: players[1].id,
|
||||
});
|
||||
|
|
|
@ -96,7 +96,12 @@
|
|||
</head>
|
||||
<lobby>
|
||||
<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>
|
||||
<flexbox>
|
||||
<mario>
|
||||
|
@ -199,7 +204,10 @@
|
|||
document.querySelector('ol[start="1"]').innerHTML = '';
|
||||
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('mario a').href = options.marioURL;
|
||||
document.querySelector('luigi a').href = options.luigiURL;
|
||||
scores = options.scores.sort(sortHighToLow).reverse();
|
||||
offset = 0;
|
||||
console.log(scores);
|
||||
for (let i in scores) {
|
||||
if (!scores[i].name)
|
||||
|
|
Reference in a new issue