2

I want to populate Lync user presence using javascript , and find some good tutorial below

http://blogs.msdn.com/b/tomholl/archive/2013/03/02/integrate-lync-into-your-intranet-sites-using-the-namectrl-plug-in.aspx

it's running fine in my computer but after i tried to run in another computer that not include "microsoft" things i got error "Error Calling Method On NPObject". I tried to install active x plugin for firefox but still got error (https://code.google.com/p/ff-activex-host/downloads/list).

below my code

<script language="javascript">

var nameCtrl = null;
var lyncUsers = {
    '1' : {
        'name' : 'david',
        'sip' : 'david@example.com',
        'img' : 'lync_photo/example.png'
    },
    '2' : {
        'name' : 'dennis',
        'sip' : 'dennis@example.com',
        'img' : 'lync_photo/example.png'
    }

};

window.onload=function(){
    try {
        if (window.ActiveXObject) {
            nameCtrl = new ActiveXObject("Name.NameCtrl");

        } else {
            nameCtrl = CreateNPApiOnWindowsPlugin("application/x-sharepoint-uc");
        }
        attachLyncPresenceChangeEvent();
        PopulateUser();
    }
    catch (ex) {alert(ex.toString()); }
};

function PopulateUser() {
    for (objVal in lyncUsers) { 
        var userName = lyncUsers[objVal].sip;
        var userElementId = getId(userName);
        var imagePath = lyncUsers[objVal].img;
        var userSection =  "<div id=\""+userElementId+"\" class=\"user\"";
        userSection += "onmouseover=\"showLyncPresencePopup('"+userName+"', this)\" onmouseout=\"hideLyncPresencePopup()\">";
        userSection += "<img class=\"img_user\"width=\"80px\" height=\"80px\" src=\""+imagePath+"\"  />";
        userSection += "</div>";

        var div = document.getElementById('users');
        div.innerHTML += userSection;
        getStatus(userName);

    }
}

function getStatus(sip)
{
    if (nameCtrl) {
            nameCtrl.GetStatus(sip, 'users');
        }       
}

function IsSupportedNPApiBrowserOnWin() {
    return true; // SharePoint does this: IsSupportedChromeOnWin() || IsSupportedFirefoxOnWin()
}

function IsNPAPIOnWinPluginInstalled(a) {
    return Boolean(navigator.mimeTypes) && navigator.mimeTypes[a] && navigator.mimeTypes[a].enabledPlugin
}

function CreateNPApiOnWindowsPlugin(b) {
    var c = null;
    if (IsSupportedNPApiBrowserOnWin())
        try {
            c = document.getElementById(b);
            if (!Boolean(c) && IsNPAPIOnWinPluginInstalled(b)) {
                var a = document.createElement("object");
                a.id = b;
                a.type = b;
                a.width = "0";
                a.height = "0";
                a.style.setProperty("visibility", "hidden", "");
                document.body.appendChild(a);
                c = document.getElementById(b)
            }
        } catch (d) {
            c = null
        }
    return c
}

function showLyncPresencePopup(userName, target) {
    if (!nameCtrl) {
        return;
    }

    //var eLeft = $(target).offset().left;
    //var x = eLeft - $(window).scrollLeft();

    //var eTop = $(target).offset().top;
    //var y = eTop - $(window).scrollTop();

    nameCtrl.ShowOOUI(userName, 0, 100, 100);
}

function hideLyncPresencePopup() {
    if (!nameCtrl) {
        return;
    }
    nameCtrl.HideOOUI();
}

function getLyncPresenceString(status) {

    switch (status) {
        case 0:
            return 'available';
            break;
        case 1:
            return 'offline';
            break;
        case 2:
        case 4:
        case 16:
            return 'away';
            break;
        case 3:
        case 5:
            return 'inacall';
            break;
        case 6:
        case 7:
        case 8:
        case 10:
            return 'busy';
            break;
        case 9:
        case 15:
            return 'donotdisturb';
            break;
        default:
            return '';
    }
}

function attachLyncPresenceChangeEvent() {
    if (!nameCtrl) {
        return;
    }
    nameCtrl.OnStatusChange = onLyncPresenceStatusChange;
}

function onLyncPresenceStatusChange(userName, status, id) {
    var presenceClass = getLyncPresenceString(status);

    var userElementId = getId(userName);
    //var userElement = $('#' + userElementId + " .img_user");
    var userElement = document.getElementById(userElementId).getElementsByClassName("img_user");
    removePresenceClasses(userElement);
    userElement[0].classList.add(presenceClass);
}

function removePresenceClasses(Obj) {
    Obj[0].classList.remove('available');
    Obj[0].classList.remove('offline');
    Obj[0].classList.remove('away');
    Obj[0].classList.remove('busy');
    Obj[0].classList.remove('donotdisturb');
    Obj[0].classList.remove('inacall');
}

function getId(userName) {
return userName.replace(/\@/g, '_').replace(/\./g, '_');
}
</script>
<style>
    .user{
        margin-bottom:20px;
        width:80px;
    }

    .img_user{
        width:80px;
        border-left: 10px solid;
    }

     .available {
        border-color: #5DD255;
    }

    .offline {
        border-color: gray;
    }

    .away {
        border-color: #FFD200;
    }

    .busy, .inacall {
        border-color: #D00E0D;
    }

    .donotdisturb {
        border-color: #C72D25;
    }
</style>

should i install spesific plugin or install spesific software to the computer?

Dika Arta Karunia
  • 476
  • 1
  • 4
  • 17
  • You'd probably need plugin source or to talk to the ones who released the plugin to track that down. The error you're getting is a generic one that tells you nothing except that something went wrong. – taxilian May 18 '14 at 22:15

1 Answers1

1

You should add your site to trusted sites in internet explorer. Even though if you are not running your application with IE you should add that particular site to the trusted sites. Then only it will work on the non IE browsers also. I also faced the similar issue, when i added to the trusted sites the problem was resolved.

Mihir
  • 8,696
  • 18
  • 56
  • 87