put all devices on the same network as the server into the same room to make it possible to run snapdrop on the local network

This commit is contained in:
schlagmichdoch 2022-12-22 01:05:49 +01:00
parent 28336eebf0
commit 3688ed0c98
1 changed files with 10 additions and 1 deletions

View File

@ -188,9 +188,18 @@ class Peer {
this.ip = request.connection.remoteAddress;
}
// IPv4 and IPv6 use different values to refer to localhost
if (this.ip == '::1' || this.ip == '::ffff:127.0.0.1') {
if (this.ip === '::1' || this.ip === '::ffff:127.0.0.1') {
this.ip = '127.0.0.1';
}
// put all peers on the same network as the server into the same room
if (this.ipIsPrivate(this.ip)) {
this.ip = '127.0.0.1';
}
}
ipIsPrivate(ip) {
// 10.0.0.0 - 10.255.255.255 || 172.16.0.0 - 172.31.255.255 || 192.168.0.0 - 192.168.255.255
return /^(10)\.(.*)\.(.*)\.(.*)$/.test(ip) || /^(172)\.(1[6-9]|2[0-9]|3[0-1])\.(.*)\.(.*)$/.test(ip) || /^(192)\.(168)\.(.*)\.(.*)$/.test(ip)
}
_setPeerId(request) {