I'm storing websocket connections inside an array. These are objects. And I'd like to remove a connection from the array when the connection is closed.
Is there any way I can find which connection object matches the closing connection and unset it?
I don't think indexOf works, right? Because the value is an object...
.........................................
here's some code
var connections = [];
websocketServer.on('request', function(request) {
var connection = request.accept(null, request.origin);
connection.on('message', function(message){
if(message.type !== 'utf8')
return;
var msg = JSON.parse(message.utf8Data);
if(msg.txt == 'something'){
connections.push(connection);
}
});
connection.on('close', function(connection) {
// here remove connection object from connections array
});
});
indexOfitself should work.