Webrtc vLine:recv:im触发两次

Webrtc vLine:recv:im触发两次,webrtc,vline,Webrtc,Vline,我已经开始将vLine API集成到我的应用程序中,但是遇到了一个问题,我发送的每一条消息都会发出两次recv:im事件 这是我发送聊天信息的模板端的代码: $('chat#u room_input').bind('keypress',函数(e){ 如果(e.keyCode==13){ log(“我们在这里发送消息”); VlineObject.sendMessageToPerson(remoteUserId); } }); 还有我的js应用程序文件内容: VlineApp=function(

我已经开始将vLine API集成到我的应用程序中,但是遇到了一个问题,我发送的每一条消息都会发出两次
recv:im
事件

这是我发送聊天信息的模板端的代码:

$('chat#u room_input').bind('keypress',函数(e){
如果(e.keyCode==13){
log(“我们在这里发送消息”);
VlineObject.sendMessageToPerson(remoteUserId);
}
});
还有我的js应用程序文件内容:

VlineApp=function(serviceId、当前用户、ui\u本地小部件、人员){
this.ui\u local\u widgets=ui\u local\u widgets;
this.serviceId=serviceId;
this.current_user=当前_用户;
this.profile u=当前用户.profile;
this.auth\u token=当前用户.auth\u token;
这是人;
//唯一需要的选项是您的serviceId
this.client vline.client.create({serviceId:this.serviceId,“ui”:true,“uiOutgoingDialog”:true,“uiIncomingDialog”:true,“uibigfreenarrow”:true,“uiVideoPanel”:this.ui\u local\u widgets\uu.videopanel});
this.client_u.on('login',this.onLoginUpdatePresence',this);
//window.PROFILE和window.AUTH_令牌由应用程序服务器生成
//并在HTML文档中设置脚本标记
this.client\uu.login(this.serviceId\uu、this.profile\uu、this.auth\u令牌)
.done(this.init_,this);
}
VlineApp.prototype.init函数(会话){
log('herein init');
//console.log(this.people_);
this.session=session;
this.client.on('recv:im',this.onMessage',this);
}
VlineApp.prototype.updatePresence=函数(e){
//触发事件时的函数调用
var person=e.target;
var presenceState=person.getPresenceState();
var shortId=person.getShortId();
this.updatePresenceUI(shortId,presenceState);
}
VlineApp.prototype.updatePresenceUI=函数(personid,presenceState){
//更新用户界面状态
$(“#”+personid+“#u status”).html(presenceState);
/*
//根据状态显示/隐藏呼叫链接
elem=document.getElementById('call-'+shortId);
if(presenceState==“online”&&shortId!==currentUserid){
elem.style.display=“”;
}否则{
elem.style.display=“无”;
}
*/
}
VlineApp.prototype.updatePresenceAll=函数(个人){
//更新当前人员的状态并添加触发事件
this.updatePresence({target:person});
person.on('change:presenceState',this.updatePresence,this);
}
VlineApp.prototype.onLoginUpdatePresence=函数(事件){
this.session=event.target;
for(var i=0;i
我必须指定聊天对话是在两个不同的用户之间进行的,他们使用来自Vline的两个不同令牌


有什么建议吗?

您似乎无意中登录了两次,并为同一用户获得了两个单独的会话,每个会话都在生成
'recv:im'
事件。这在一定程度上是我们这边的一个bug(我们不应该让你以同一个用户的身份登录两次),但是你可以解决它。您最终登录两次的原因是,如果上一个会话可用,我们会自动从本地存储恢复它。如果您已经调用了一次,然后再次点击页面,则当前会恢复上一个会话,然后在调用
client.login()
时会创建一个新会话

要解决此问题,您可以使用查看在调用
client.login()之前是否已自动登录:

if(this.client..isLoggedIn()){
var session=this.client_u2;.getDefaultSession();
这是第一次会议;
this.onLoginUpdatePresence_uz({“target”:session});
}否则{
this.client_u.on('login',this.onLoginUpdatePresence',this);
//window.PROFILE和window.AUTH_令牌由应用程序服务器生成
//并在HTML文档中设置脚本标记
this.client\uu.login(this.serviceId\uu、this.profile\uu、this.auth\u令牌)
.done(this.init_,this);
}