Twilio 聊天成员在线状态始终为空

Twilio chat member online status is always null

在我的聊天应用程序中,我想知道频道成员是否在线,但是 'userInfoUpdated' 永远不会在新成员到来时触发,并且 member.userInfo.online 总是空的,只要我想得到它。我做错了什么?

更新: 这里代码暂停在成员 "updated" 甚至,成员的 userInfo.online 字段仍然是 null

UPD2: 现在我从 documentaion

中找到了这一行

Extended user information Note that UserInfo#online and UserInfo#notifiable properties are eligible to use only if reachability function enabled. You may check if it is enabled by reading value of Client~reachabilityEnabled docs

最后在后端设置 reachabilityEnabled 解决了我的问题

这里是 Twilio 开发人员布道者。

根据您的评论,您说您的代码是:

client.getChannelByUniqueName(uniqueName).then(channel => {
  channel.getMembers().forEach(member => {
    member.on('userInfoUpdated', ()=>{ //nothing happening })
  })
})

我想我明白了。 channel.getMembers() returns a Promise 将异步解析 Member 对象数组。您只是在 Promise 本身上调用 forEach。尝试类似的东西:

client.getChannelByUniqueName(uniqueName).then(channel => {
  return channel.getMembers()
}).then(members => {
  members.forEach(member => {
    member.on('userInfoUpdated', ()=>{ // something happening? })
  })
})

如果有帮助请告诉我。

在后端设置 reachabilityEnabled 解决了我的问题

是的,如果您没有在客户端启动时同步聊天客户端,成员将为空。

因此您需要覆盖此回调并确保在使用聊天客户端方法(如 getChannels 或 getMessages)之前完成客户端同步。

override fun onClientSynchronization(status: ChatClient.SynchronizationStatus?) {
        if (status == ChatClient.SynchronizationStatus.COMPLETED) {
            // You can use chat client now
        }
    }

You will receive an event to the client's listener or delegate via the synchronizationStatusUpdated method with a value of StatusCompleted. This is your indication the client is ready for business, and all User Channels have been obtained and subscribed to.

更多详情请查看:Initializing SDK Clients