尝试填充 Lync Presence 时在 NPObject 上调用方法时出错
Posted
技术标签:
【中文标题】尝试填充 Lync Presence 时在 NPObject 上调用方法时出错【英文标题】:Error Calling Method On NPObject While Tried To Populate Lync Presence 【发布时间】:2014-05-12 09:53:24 【问题描述】:我想使用 javascript 填充 Lync 用户状态,并在下面找到一些好的教程
http://blogs.msdn.com/b/tomholl/archive/2013/03/02/integrate-lync-into-your-intranet-sites-using-the-namectrl-plug-in.aspx
它在我的计算机上运行良好,但在我尝试在另一台不包含“microsoft”的计算机上运行后,我收到错误“NPObject 上的错误调用方法”。我尝试为 firefox 安装 active x 插件,但仍然出现错误 (https://code.google.com/p/ff-activex-host/downloads/list)。
在我的代码下面
<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>
我应该在电脑上安装特殊插件还是安装特殊软件?
【问题讨论】:
您可能需要插件源或与发布插件的人交谈以追踪它。你得到的错误是一个通用的错误,除了出现问题之外什么都不告诉你。 【参考方案1】:您应该将您的站点添加到 Internet Explorer 中的受信任站点。 即使您没有使用 IE 运行您的应用程序,您也应该将该特定站点添加到受信任站点。然后只有它也适用于非 IE 浏览器。我也遇到了类似的问题,当我添加到受信任的站点时,问题得到了解决。
【讨论】:
以上是关于尝试填充 Lync Presence 时在 NPObject 上调用方法时出错的主要内容,如果未能解决你的问题,请参考以下文章