简体   繁体   中英

Counting number of available users for Lync

I've got the below code for displaying Lync presences on my site, but what I am looking to do is count the number of users of a particular status, eg Available: 3, Away: 4, Meeting: 2 etc. Is there a function in the API that would return me the status as a number, so I could use a for loop to count them up and display in HTML?

<script>
var nameCtrl = new ActiveXObject('Name.NameCtrl.1');
function getStatus(sipUri) {
    if (nameCtrl.PresenceEnabled)
{
    nameCtrl.OnStatusChange = onStatusChange;
    nameCtrl.GetStatus(sipUri, "1");
}
}
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);
var lyncpresencecolor = "gray";
switch (status) {
    case 0:
        document.getElementById(name).style.borderLeftColor = "#5DD255";
        break;
    case 1:
        document.getElementById(name).style.borderLeftColor = "#B6CFD8";
        break;
    case 2:
        document.getElementById(name).style.borderLeftColor = "#FFD200";
        break;
    case 3:
        document.getElementById(name).style.borderLeftColor = "#D00E0D";
        break;
    case 4:
        document.getElementById(name).style.borderLeftColor = "#FFD200";
        break;
    case 5:
        document.getElementById(name).style.borderLeftColor = "#D00E0D";
        break;
    case 6:
        document.getElementById(name).style.borderLeftColor = "#D00E0D";
        break;
    case 7:
        document.getElementById(name).style.borderLeftColor = "#D00E0D";
        break;
    case 8:
        document.getElementById(name).style.borderLeft = "dashed";
        document.getElementById(name).style.borderLeftWidth = "10px";
        document.getElementById(name).style.borderLeftColor = "#E57A79";
        break;
    case 9:
        document.getElementById(name).style.borderLeftColor = "#D00E0D";
        break;
    case 15:
        document.getElementById(name).style.borderLeftColor = "#D00E0D";
        break;
    case 16:
        document.getElementById(name).style.borderLeftColor = "#FFD200";
        break;
    default:
        document.getElementById(name).style.borderLeftColor = "#B6CFD8";
        break;
}
}
function ShowOOUI(sipUri)
{
nameCtrl.ShowOOUI(sipUri, 0, 15, 15);
}
function HideOOUI()
{
nameCtrl.HideOOUI();
}
</script>

<span id="sip@domain.com" onmouseover="ShowOOUI('sip@domain.com')" onmouseout="HideOOUI()" style="border-left-style:solid; border-left-width: 10px;"> User Name</span>
<script type="text/javascript">
  getStatus('sip@domain.com');
</script>

Thanks

No, there isn't, but if you set or add some simple class tag on your status change, eg.

document.getElementById(name).className = 'LyncStatus' + status;

Then you could count them easily by calling:

function getNumberOfUserByStatus(status) {
    return document.getElementsByClassName('LyncStatus' + status ).length;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM