From 3688ed0c981b8903a8652936b47c59997a99a269 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Thu, 22 Dec 2022 01:05:49 +0100 Subject: [PATCH] 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 --- server/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/index.js b/server/index.js index c47feb1..dcb2cf6 100644 --- a/server/index.js +++ b/server/index.js @@ -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) {