我正在尝试使用组通道在2个sendbird用户之间创建通道。到目前为止,我的实现是
<script type="text/javascript">
function chatInit(){
var sb = new SendBird({
appId: 'my app id'
});
sb.connect('test user','access token of user', function(user, error) {
console.log(error);
});
var userIds = ['another user'];
var name ="name of channel";
sb.GroupChannel.createChannelWithUserIds(userIds, true, name ,'', '', function(channel, error) {
if (error) {
console.error(error);
return;
}
});
}
</script>
我在控制台上看到以下错误
SendBird.min.js:6 Uncaught TypeError: Cannot read property 'userId' of null
at Function.GroupChannel.createChannelWithUserIds 如果我遗漏了什么,请指导我完成这个过程。任何和所有的帮助将不胜感激。
发布于 2017-10-11 23:01:00
之所以会得到错误响应,是因为在编写代码时,连接尚未运行完成
sb.GroupChannel.createChannelWithUserIds()就是运行。
您需要在sb.connect()的回调函数中添加该代码块,如下所示:
function chatInit(){
var sb = new SendBird({
appId: 'my app id'
});
var userIds = ['another user'];
sb.connect('test user','access token of user', function(user, error) {
console.log(error);
if(user){
var name ="name of channel";
sb.GroupChannel.createChannelWithUserIds(userIds, true, name ,'', '', function(channel, error) {
if (error) {
console.error(error);
return;
}
});
}
}
}https://stackoverflow.com/questions/45998835
复制相似问题