socket.io assigning custom socket.id
<p>I keep track the list of every users connected in the array.
So if there is a new connection, it will check whether the user is already on the list or not, if he was already on the list, then assign their socket.id with the corresponding socket.id on the list, otherwise just add them to the list.</p>

<p>It's for preventing same user counted as 2 user while he attempt to do multi-login.</p>

<pre><code>Object.keys(client).forEach(function (key) {
    if (client[key].id == data.id){
        is_connected = true;
        socket.id = key;
    }
});
</code></pre>

<p>I have no problem handling the messages/chat that was sent/received by the user who attempt multi-login.</p>

<pre><code>socket.on('chat', function(msg){
    var data = {"name": client[socket.id].name, "message": msg};
    io.emit('chat', data);
});
</code></pre>

<p>The io.emit for the chat message was succesfully sent to the user who attempting multi-login.</p>

<p>The problem I got was whenever the user decide to logout/disconnect from the server.</p>

<pre><code>io.emit('user_leave', client[socket.id].id);
</code></pre>

<p>[Multi-Login Case] -> Multi-User and Dual-User are same user attempting Multi-Login</p>

<p>Whenever the Main-User disconnected from the server, the Dual-User received 'user_leave' sent by the server, because io.emit supposed to send it to all sockets. </p>

<p>But not otherwise, while the Sub-User disconnected from the server, the Main-user do not receive 'user_leave' emitted by the server.</p>

<p>*Note: Main-User is login first, then the Dual-User. So the Main-User information was saved directly in the array, while the Sub-User socket.id was assigned with the Main-User socket.id</p>

<p><strong>[Update]</strong></p>

<p><a href="https://i.stack.imgur.com/SXTFi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SXTFi.png" alt="Explanation"></a></p>

<p>B2 socket.id was assigned with B1 socket.id, the io.emit for chat work perfectly while io.emit for disconnect only emitted to All except Dual-User(B2)</p>