环信SDK 踩坑记webIM篇(一)

来源:互联网 发布:ubuntu安装软件 编辑:程序博客网 时间:2024/05/20 04:46

(一)处理添加好友

问题:添加好友时,一直返回none,就是对方拒绝添加的意思,可是在代码里明明就是有同意添加 的代码:

onPresence: function (message) {    switch (message.type) {        case 'subscribe': // 对方请求添加好友            console.log(message.from+'请求添加好友... 并对你说:'+message.status);            // 同意对方添加好友                    document.getElementById('agreeFriends').onclick = function (message) {                conn.subscribed({                   to: message.from,                   message: "[resp:true]"                });            // 拒绝对方添加好友document.getElementById('rejectFriends').onclick = function (message) {                conn.unsubscribed({                    to: message.from,                    message: "rejectAddFriend"                  // 拒绝添加好友回复信息                });            };            break;

这是部分代码,中间有两个按钮,当有添加好友请求的时候,会给这两个按钮绑定事件:同意添加和拒绝添加,然而,一直发起请求的那边显示discription为none,discription有4个值:both,form,to,none, 显示none则表示拒绝,但显示好友列表的时候里面有;而“拒绝”的那一方,显示好友列表则多了一个undefined好友。
一切根源都来自那个按钮,这个绑定事件导致了添加好友出错,去掉事件,就好了,所以在配置回调函数的时候慎用事件绑定,最好在外面定义事件。

原创粉丝点击