0

I'm currently trying to make a Strophe based javascript script to get the list of available users in an OpenFire server (live refreshing needed). I don't care if I have to create a group, room or whatever it's called (anyway, the server will be running for only a small group of users, everyone connected to eachother), but I want to be able to make the server give such a list. How can I do this? I've read that I need to use muc extension, but I can't seem to find it anywhere...

1 Answer 1

3

Problem solved! I had to add the users I was working with to a group and eachtime a user leaves or enters the room OpenFire notifies the other users of the room with a presence stanza wrapped inside a body tag most of the times. This makes Strophe to not identify those presence stanzas very well, so I had to overwrite the xmlInput function from the Strophe connection to get every single xml stanza that I get from the server.

conn.xmlInput = onXmlInput;
function onXmlInput(data) {
    Strophe.forEachChild(data, "presence", function(child) {
        var from = child.getAttribute('from');
        from = from.substring(0, from.indexOf('@'));
        //'type' will contain "unavailable" when offline and no attribute 'type' when online
        if (!child.hasAttribute('type')) {
            addUser(from);
        } else {                    
            deleteUser(from);
        }
    });
}
4
  • Hi , you are creating a group and from that you are getting online users but is this having limitation for 30 user ?
    – Tiger
    Sep 12, 2014 at 8:13
  • I haven't had any trouble with limitations since I've not worked with large amounts of users... maybe you could post a question in a separate thread about this ;)
    – Gonzalo
    Sep 27, 2014 at 17:02
  • what inside adduser and deleteuser method? Aug 17, 2016 at 7:31
  • @ButaniVijay addUser and deleteUser are your custom methods to execute when a new user joins or disconnects from the server. In my case, I added and removed them from a list of connected users. Here's my addUser method: $("select#recepients").append("<option id="+from+">"+from+"</option>")
    – Gonzalo
    Aug 17, 2016 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.