ccloquet / Quickgrid

On the field, quickly know where you are wrt to a grid or a path (eg : I am in grid B4, or I am at kilometer 2,3)
https://grid.my-poppy.eu
MIT License
4 stars 0 forks source link

transmit geoloc on demand / in real time #31

Closed ccloquet closed 6 years ago

ccloquet commented 6 years ago

This requires a more complicated infrastructure / code

Possibility 1 : P2P GEOLOC TRANSMISSION

       <script src="https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.9/peer.min.js"></script>

    // p2p broker should be hosted by poppy
    // distinguish between boss & slave in the url (like for doodle)
    // therefore, the url contains : a maphasp (+ a mapcode if boss)
    // verify if boss : hash(code) = maphash
    // code not guessable by slave
    //
    // problem : using maphash as peerid, a slave can impersonate the master
        // issue bcz it would prevent the real master to access the data
        // otherwize data might be shared, but with p2p, this would require a network with O(N²) links...
        // -> problem : not scalable
    var maphash         = null
    var mapcode         = null

    var peerjs_apikey   = 'kjhlkjhlkjh'

    // if i am a boss :
    var peer            = new Peer(maphash, {key: peerjs_apikey});

    peer.on('connection', function(conn) 
    { 
        conn.on('open', function() 
        {
            conn.on('data', function(data) 
            {
                console.log('Received', data);
                // put data on map (with indication of date/time)
                // make it disappear after a while
            });
        }); 
    });

    // if i am a slave & I push on a button
    function send_position()
    {
        var rand = Date.now() +''+ Math.random()
        var peer = new Peer(maphash + rand, {key: peerjs_apikey});
        var conn = peer.connect(maphash)

        conn.on('open', function() 
        {
            conn.send(JSON.stringify(current_coords));
            peer.destroy()
        });
    }
    $('#btn-send-position').on('click', send_position)

Possibility 2:

-> this needs :

-> the customers are isolated through their mapid

Possibility 3:

Use Twilio Sync, PubNub, ... to synchronize state through all the members of a -> requires payment / apikey -> administration ...

Possibility 4:

Using a decentralized internet solution -> to explore

ccloquet commented 6 years ago

current solution uses pubnub