I’m using an ActiveXObject to handle lync status changes and show presence via the javascript below
var Instant = {
sipUri: "name@address.com", // Change this to the user's SIP URI you want to chat with
nameCtl: new ActiveXObject('Name.NameCtrl.1'),
onStatusChange: function (name, status, id) {
alert(name + " " + status + " " +id);
},
showOOUI: function () {
var oouiX = 0, oouiY = 0;
oouiX += pawn_icon.offsetLeft + pawn_icon.clientLeft - pawn_icon.scrollLeft;
oouiY += pawn_icon.offsetTop + pawn_icon.clientTop - pawn_icon.scrollTop;
Instant.nameCtl.ShowOOUI(Instant.sipUri, 0, oouiX, oouiY);
},
hideOOUI: function () {
Instant.nameCtl.HideOOUI();
}
}
And this html/javascript to actually register the event handler to the event:
<head>
<title>Lync Presence Test</title>
<!-- le JS -->
<script type="text/javascript">
if (Instant.nameCtl.PresenceEnabled) {
Instant.nameCtl.OnStatusChange = Instant.onStatusChange;
Instant.nameCtl.GetStatus(Instant.sipUri, "1");
}
</script>
</head>
<body>
<div id="presence" onmouseover="Instant.showOOUI()" onmouseout="Instant.hideOOUI()">Name<img id="pawn" name="pawn_icon" src="Styles/images/LyncStatus/imnon.png" alt="Available"> </div>
</body>
</html>
As the title states, if I load the page, I get the event fires and I get the status code like one would expect. However, if I change my status, two events fire. The first contains the right status code and the second contains the old status code. The issue here is that I want to change to the new status, but the stale one is the last event to fire, so it overwrites the new change. The event also fires 6 times when I mouse over the person’s name.
Microsoft’s documentation of the Name.NameCtrl object is pretty sparse, but as I understand the getstatus method and onstatuschange property, they’re exactly what I’m looking for.
So, is there a reason that the statuschange event fires twice, and is there a way to either preempt this or switch the order of the events returned? Also, why does the event fire if you mouse over the name, as no status change has occurred? I’d like to find out more about the specific status change event, but I can’t find anything. I also don’t have access to the lync server, so I have to do client-side set up.
Name.NameCtrl documentation: http://msdn.microsoft.com/en-us/library/bb802706(v=office.14).aspx
Where I got the code for the presence functionality: http://blog.instant-tech.com/2012/05/web-client-for-microsoft-lync-2010.html
Many events fire; however, the alerts do not provide an accurate understanding of which event fired last. The events were firing in the right order. I just added a switch statement to the code to handle changing the picture bas