view raw
Eliezer Broide Eliezer Broide - 6 months ago 45
Javascript Question

Mobile Phonegap applications on a local network

I've created a game using html5 and websockets that is played with both a pc and a mobile device (multiple mobile devices can also be played):

The game has a Stage - The PC or a tablet device.

And several players — Other mobile devices

The current connection between the Stage and Players is with a number (the Stage shows a number and a player can join through that number), however, I'm searching for a way that the Players can join just by being in the same local network as the Stage - meaning auto-discovery through a local network.

I've been searching WebRTC and other p2p solutions but I can't find anything. Is there something else I can use or is it completely impossible?


There's no javascript only way to the local ip address from inside a browser. There do seem to be a good number of cordova/phonegap plugins that purport to do this:

As well as the one pointed out in the comment above. It looks like it's either android or IOS. Someone should write one that works on both!

If it was me. I would probably work with the browser headers on the Stage: REMOTE_ADDR, HTTP_CLIENT_IP, etc. There are some fine points to doing this:

On a local network, you'll be able to get the real IP address of each device. Private networks fall into a particular address space:        -      -     -

So your Stage will know when its clients are connecting to it on a LAN. Does that get you where you need to go?