【发布时间】:2021-05-07 15:24:07
【问题描述】:
在我的后端服务中创建一个频道后,我试图在我的反应前端中加入这个频道,像这样的 useEffect 钩子:
const initChat = async () => {
const chatClient = await Client.create(props.token);
const channel = await chatClient.getChannelByUniqueName(props.room);
if (channel) {
if (channel.status !== "joined") {
chatClient.on("channelJoined", () => {
registerChannelListeners(channel);
});
await channel.join();
} else {
registerChannelListeners(channel);
}
setChannel(channel);
setMessages((await channel?.getMessages()).items);
}
};
}
最初导航到页面时,出现错误
upstream.js?a850:136 Uncaught (in promise) Error: Forbidden
at Upstream.actualSend (upstream.js?a850:136)
偶尔会被抛出。
在重新加载页面时,一切正常。
有问题的行似乎是:
const channel = await chatClient.getChannelByUniqueName(props.room);
因为没有进一步的代码被执行。 token 和 room 都分配了有效值。
在解码的套接字消息中,此错误消息是从 twilio 发送的:
{"method":"reply"...,"http_status":{"code":403,"status":"Forbidden"}}
{"status":403,"message":"User not member of channel","code":50400}
虽然两个参与者都是通过后端通过此功能邀请的:
inviteParticipantToChannel(participant: Participant, channelSid: string) {
this.logger.log(
`Inviting paricipant ${participant.getIdentifier()} to channel ${channelSid}`,
);
return this.twilioClient.chat
.services(process.env.TWILIO_CHAT_SERVICE_ID)
.channels(channelSid)
.invites.create({ identity: participant.getIdentifier() });
}
我需要做更多的事情来让参与者找到/加入频道吗?
【问题讨论】:
标签: node.js reactjs twilio use-effect twilio-programmable-chat