snapdrop icon indicating copy to clipboard operation
snapdrop copied to clipboard

Browser on another laptop is not detected

Open jrichardsz opened this issue 4 years ago • 3 comments

I tried on two different browsers (localhost:8080) on the same laptop and it works.

But when I open it on another laptop in the same network (of course using its ip), devices are not detected.

There are no logs on nginx nor nodejs app.

How can I configure it to use it on any device on the same network?

Thanks

jrichardsz avatar Dec 05 '21 18:12 jrichardsz

When you visit your website on LAN, the server can only get your devices' LAN IP. Each device has different LAN IP, so the server can't recognize that they are in same network. To solve this problem you need modify index.js _setIP(request) function, add a judgment, if ip start with, let's say your LAN is 192.168.1. , just take 192.168.1 as this.ip, ignore the last section of the ip address.

yjmp14 avatar Dec 06 '21 09:12 yjmp14

@yjmp14

When you visit your website on LAN, the server can only get your devices' LAN IP. Each device has different LAN IP, so the server can't recognize that they are in same network. To solve this problem you need modify index.js _setIP(request) function, add a judgment, if ip start with, let's say your LAN is 192.168.1. , just take 192.168.1 as this.ip, ignore the last section of the ip address.

Did you mean this way?

    _setIP(request) {
        if (request.headers['x-forwarded-for']) {
            this.ip = request.headers['x-forwarded-for'].split(/\s*,\s*/)[0];
        } else {
            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') {
            this.ip = '127.0.0.1';
        }
        if (this.ip.startsWith('192.168.0.') {
            this.ip = '192.168.0';
        }
    }

Does not seem to work for me. Can you help?

just take 192.168.1 as this.ip, ignore the last section of the ip address.

I could not understand this part.

VedderPradhan avatar Jan 02 '22 09:01 VedderPradhan

@jrichardsz

https://github.com/RobinLinus/snapdrop/issues/159#issuecomment-691678186 This solved the issue for me!

https://github.com/RobinLinus/snapdrop/issues/159#issuecomment-685751010 The reason for the devices on the same LAN not being detected seems to be this.

Hope it helps.

VedderPradhan avatar Jan 04 '22 14:01 VedderPradhan