Question

I am trying to detect when a user joins a room. I read the docs and I came up with the following code. I'm using it as an event that is triggered when the user presses ENTER inside a textfield.

var url = 'https://goinstant.net/ACCOUNT/APP'; // actual account and app values omitted
var userDefaults = {
                displayName: $(this).val(),
};

goinstant.connect(url, {user: userDefaults}, function(err, connection, room) {   
                console.log("Joined room "+ room.name); //Joined room lobby
                room.on('join', function (userData) {
                    console.log('user' + userData.displayName +  'joined the lobby!');
                });   
});

This code is not working and I cannot figure out why.

The console outputs "Joined room lobby" when the user connects, but it does not output "user {name} joined the lobby" when other user joins the lobby.

It may be a just something silly that I missed from the docs.

Was it helpful?

Solution

Is your second user in another tab in the same browser? guest user identity is tied to a browser, rather than a tab. The second connection will just appear as the same guest and not trigger a join, as the user is already in the room. Try running the second instance in an incognito session.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top