Reputation: 1
When i restart my js code, it emits the games and
socket.on('getgames', function (data) {
socket.emit('updategames', {games:games});
});
This is supposed to make a div class="game-:gameid", it works fine until either theres a connection error or i restart my js code. Then it will make duplicate divs and emit it twice, i dont want duplicate.
Upvotes: 0
Views: 110
Reputation: 4696
This problem will occur then you call on:
socket.on('getgames', function (data) {
socket.emit('updategames', {games:games});
});
multiple times. This will course socket.io to subscribe to your event 'getgames' multiple times.
My guess is that you call this code every time you restart your game. To fix it you either unsubscribe from the event or just call the code one time.
Upvotes: 0