« New parachute team photos - all was going well until disaster... | Main| Do you have a Sametime SIP connector setup and would like to show the users presence on a web page »

Have you ever wanted to put a Stlinks place awareness list on a page?

Category
Only to realize when you do that the STLinks place awareness code is loaded in it's own popup window, and if you try putting it in an iframe you get a bunch of JavaScript error messages as the applet is talking directly to the place awareness list with the expectation that it's in it's own popup window? Well I have, and it's been a pain I can tell you. Recently LotusUserGroup.org came to me asking them to help add Sametime awareness to their website. So I decided it was time to figure out an easy way around this STLinks out of the box limitation.

At first I just tried to tweak the STLinks JavaScript code to get rid of the Javascript errors, but this proved to be a real pain in the arse, then a bright light came before me and I had an idea, why not build my own awareness list using the functions

STLinksEnterPlace - Enters the user in a specified place
STLinksUserEnteredPlace - The event when a person enters a place
STLinksUserLeftPlace - The event called when a user leaves a place

An important part of being able to do this is knowing that the eventSTLinksUserEnteredPlace is called for every user in a place, even for the ones that were there before you got there. The thing that's nice about this solution is that it requires no changes to the stlinks server code. SO no hacking JavaScript etc. it just uses the plain out of the box STLinks code.

So knowing that you get an alert for every person in a place when you enter it, it is easy to build up an array that contains the information for all the users in a place. The array used for tracking the local list of users in a place is users and users are added/removed from it through the addUser and userLeft JavaScript functions.

The user in a place is written a DIV, in this case a DIV called stplacelist by the function refreshDIVList which is called every time a user enters or leaves the place.

Click on Read More to see the code and download the htm file if you want it.
<html>
<head>
<SCRIPT>
</SCRIPT>
    <LINK REL=STYLESHEET HREF="http://<<STSERVERNAME>>/sametime/stlinks/stlinks.css" TYPE="text/css">
    <SCRIPT src="http://<<STSERVERNAME>>/sametime/stlinks/stlinks.js"></SCRIPT>
    <SCRIPT>
        setSTLinksURL("http://<<STSERVERNAME>>/sametime/stlinks");
    </SCRIPT>
    <SCRIPT>
        writeSTLinksApplet("","",false);
    </SCRIPT>
    <SCRIPT>
    var users = new Array();
    function compareUsers(user1,user2)
    {
        if (user1.name.toLowerCase() < user2.name.toLowerCase())
            return -1;
        else if (user2.name.toLowerCase() < user1.name.toLowerCase())
            return 1;
        else
            return 0;
    }

    function addUser(newName,newId)
    {
        var newUser = new Object();
        newUser.id = newId;

        newUser.name = newName;
        users[users.length] = newUser;
        users.sort(compareUsers);
    }

    function userLeft(userId)
    {
        var found = false;
        for (var i = 0; i < users.length; i ++)
        {
            if (users[i].id == userId)
                found = true;
            else if (found)
                users[i-1] = users[i];
        }
        if (found)
            users.length -= 1;
        refreshDIVList();
    }

    function userJoined(userId,userName)
    {
        addUser(userName,userId);
        refreshDIVList();
    }
    function    STLinksAppletStarted(){
        //This function is called when the STLinks Applet has loaded successfully
        //Remove comments on next line to see applet started message
        //alert("ST Links Applet Started successfully");
    }
    function    STLinksLoggedIn(myUserId, myUserName){
        //This function is called when the user has logged in successfully.
        //Remove comments on next line to see Logged in message
        //alert("ST Links Applet Logged in with UserID " + myUserId + " and the display name " + myUserName);
        // We are now logged in so enter the LotusUserGroup Place
        STLinksEnterPlace("LotusUserGroup", true)
    }
    function STLinksUserEnteredPlace(userId, displayName, placeName){
        //This function is called when a user enters the place
        //Remove comments on next line to see entered place messages
        //alert("User entered place " + placeName + " with userId " + userId + " and the display name " + displayName);    
        //Track users in place
        userJoined(userId,displayName)
    }

    function STLinksUserLeftPlace(userId, displayName, placeName){
            //Remove comments on next line to see left place messages
            //alert("User left place " + placeName + " with userId " + userId + " and the display name " + displayName);
        //Track users leaving the place
        userLeft(userId)
    }

    function refreshDIVList(){

        var str="";
        stlinkscontent = document.getElementById("stplacelist");
        for (var ind in users)
        {
            //If only one person in the list do not prepend with a break tag
            if(ind > 0){str+='<br>';}        
            str+=prepareSametimeLink(users[ind].id,users[ind].name,false);
        }
        stlinkscontent.innerHTML = (str);
    }
    </SCRIPT>
</head>
<body>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent rutrum magna vitae sapien. Donec commodo. Fusce aliquet, massa non egestas blandit, libero neque varius urna, a hendrerit mi quam vel massa. Morbi feugiat consectetuer nibh. Integer mattis porttitor nunc. Maecenas vitae mauris.
<DIV id=stplacelist></DIV>
<br>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent rutrum magna vitae sapien. Donec commodo. Fusce aliquet, massa non egestas blandit, libero neque varius urna, a hendrerit mi quam vel massa. Morbi feugiat consectetuer nibh. Integer mattis porttitor nunc. Maecenas vitae mauris.
</body>
</html>


Download HTML file

Comments

Gravatar Image1 - what language is being used in the <body> area of the html code? I can't translate it....sorry.

Sounds very cool, I'm going to give it a try.

Thanks,
Tim

Gravatar Image2 - Download the zip file and get the HTM file from there. The lt and gt are the less than and greater than, that is so that it can display on the page and not be interpreted as real HTML.

Gravatar Image3 - Carl,
Last year you made mention of your canoe stabilizers. Any chance on getting your plans or better pictures of your setup? Great idea by the way! Thanks

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::rolleyes:;-)