a user login 2 device

hello,
i want to close old connection when 1 user login on 2 device
My mean is:
onAuth (options){
return true;
}

requestJoin (options: any, isNew: boolean) {
return true;
}

onJoin (client) {
if(userId in this.players){
var old_client = this.players[userId];
old_client.close();
}
this.players[userId] = client;
}
How to do this?

Hi @jack1604, you're on the right track.

You must have a way to identify users uniquely, not based on client.id or client.sessionId for that. Ideally you'd use authentication (onAuth) with an external service, which will ensure you'll have a unique id per user.

The client.id will be the same if you open multiple tabs in the same browser. You can use that for testing. Not suitable for a real scenario, though.

Having this unique id, you can create a map of player by ids (e.g. this.players), and close his previous connection, exactly as in your example:

var old_client = this.players[userId];
old_client.close();

Cheers