GitHub | Documentation | Become a Patron

Question on login from second device and close first device login



  • Hi I tried to remove the previous login client at requestJoin part by matching client Id and I can successfully remove the previous login client. But If the client is the last person in the room, the room will get disposed and new room will be created for the second login client. And this will cause a remoteroom call promised error. Is there better way for kick out first login client instead of detecting at requestJoin? Please advise please.

    requestJoin (options) {

    console.log("request join!", options);
    
    for(var id in this.clients)
    {
      if(options.clientId == this.clients[id].id)
      {
        this.clients[id].close();
      }
    }
    return true;
    

    }


  • administrators

    Hi @soh-sea-kiat,

    You can store the user identifier on the client instance, and then search for it when the second joins.

    Example:

    onJoin (client, options) {
      var alreadyJoined = this.clients.find(client => {
        return client.userId === options.userId;
      });
    
      if (alreadyJoined) {
        alreadyJoined.close();
      }
    
      client.userId = options.userId; // just an example
    }
    

    Keep in mind I haven't tested this code, but it should work. I'm using Array.find method to get the first client matching the same userId, which is assigned whenever the user joins the room.

    Hope this helps! Cheers!



  • Solve it. Need to check for sessionId also. Thanks for help ! cheers !