Integrate Microsoft Communicator in web application

I have recently integrated Microsoft Communicator in one of the web based project. Initially it sounds a bit complicated but here is it :

Add reference to following assembly

using CommunicatorAPI;
using CommunicatorPrivate;
using System.Runtime.InteropServices;
// object initialization  MyCommunicator comm = new MyCommunicator();          Response.Write(string.Format("Your status :{0}",comm.GetCommStatus()));
Options 2
add below Js code in your web page and call functions wherever you want 
function ShowUserName(cntrlname,cntrlvalue) {alert(cntrlname);
}
function togglePannelStatus(content) {     var expand = (content.style.display == "none");     content.style.display = (expand ? "block" : "none");     var chevron = content.parentNode             .firstChild.childNodes[0].childNodes[0];     chevron.src = chevron.src             .split(expand ? "expand.gif" : "collapse.gif")             .join(expand ? "collapse.gif" : "expand.gif");
}
 
//show communicator status 
var ns4 = (navigator.appName.indexOf("Netscape") >= 0           && parseFloat(navigator.appVersion) >= 4           && parseFloat(navigator.appVersion) < 5) ? true : false;
var ns6 = (parseFloat(navigator.appVersion) >= 5           && navigator.appName.indexOf("Netscape") >= 0) ? true : false;
var ns = (document.layers) ? true : false;
var ie = (document.all) ? true : false;
function getElLeft(el) {     if (ns4) { return el.pageX; }     else {         xPos = el.offsetLeft;         tempEl = el.offsetParent;         while (tempEl != null) {             xPos += tempEl.offsetLeft;             tempEl = tempEl.offsetParent;         }         return xPos;     }
}
function getElTop(el) {     if (ns4) { return el.pageY; }     else {         yPos = el.offsetTop;         tempEl = el.offsetParent;         while (tempEl != null) {             yPos += tempEl.offsetTop;             tempEl = tempEl.offsetParent;         }         return yPos;     }
}
var sipUri //= "emailaddress
var nameCtrl;
function ShowOOUI(sipURI, obj) {     nameCtrl = new ActiveXObject('Name.NameCtrl.1');     if (nameCtrl.PresenceEnabled) {         nameCtrl.OnStatusChange = onStatusChange;         nameCtrl.GetStatus(sipURI, "1");     }     var oouiX = getElLeft(obj); oouiY = getElTop(obj);     nameCtrl.ShowOOUI(sipURI, 0, oouiX, oouiY);
}
function HideOOUI() { nameCtrl.HideOOUI(); }
function onStatusChange(name, status, id) {     // This function is fired when the contacts presence status changes.  
    // In a real world solution, you would want to update an image to reflect the users presence 
    //alert(name + ", " + status + ", " + id); 
}

Get total number of users accessing web application

In my application , we have to display the total number of users who were accessign the hosted web application at any point of time . To implement this requirement , i have made some changes in the Global.Asax file of the application . Here is the code snippet.Hope this will help  you .

<%@ Application %>

<script RunAt=”server”>

void Application_Start(object sender, EventArgs e)

{

// Code that runs on application startup

Application.Add(“ActiveUsers”, 0);

}

void Application_End(object sender, EventArgs e)

{

// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)

{

// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)

{

// Code that runs when a new session is started

Application.Lock();

Application[“ActiveUsers”] = System.Convert.ToInt32(Application[“ActiveUsers”]) + 1;

Application.UnLock();

}

void Session_End(object sender, EventArgs e)

{

// Code that runs when a session ends.

// Note: The Session_End event is raised only when the sessionstate mode

// is set to InProc in the Web.config file. If session mode is set to StateServer

// or SQLServer, the event is not raised.

Application.Lock();

Application[“ActiveUsers”] = System.Convert.ToInt32(Application[“ActiveUsers”]) – 1;

Application.UnLock();

}

</script>

 Now you can retrieve number of active users     —  Application.Get(“ActiveUsers”).ToString()