socketio / socket.io-p2p

MIT License
1.02k stars 180 forks source link

Bug or Feature? Double connections to all peers. #14

Closed MichielVdAnker closed 8 years ago

MichielVdAnker commented 8 years ago

I am developing a game and want to use rooms isolate the communication.

Everything works, except I receive all messages twice and see that for every numConnectedClients I get 2 readyPeers.

I am now filtering duplicate messages but would prefer less message handling.

My setup on the server looks like this in the on.('connection') block:

    // game full, setup p2p
    if(game && game.players.length === maxPlayers) {

      function joinGame(socketId,game) {
        console.log('connecting client to peers',socketId)
        var socket = clients[socketId]
        socket.join(game.name)
        p2pserver(socket,null,game)
      }

      // connect all peers
      joinGame(game.screen,game);
      game.players.forEach(function(player) {
        joinGame(player,game)
      })

      io.to(game.name).emit('game-starting',game)
    }