當試圖加入我一直在使用的twilio代碼中的一個頻道時,它出現錯誤,指出它「無法讀取屬性'getChannelByUniqueName'爲null」。該聊天工作,但當我試圖打開它在不同的瀏覽器,如Firefox而不是鉻,它說錯誤「提供唯一名稱的渠道已經存在」。任何人都可以解決這個問題嗎?無法加入聊天頻道
// Initialize the Chat client
chatClient = new Twilio.Chat.Client(data.token);
joinChannels(chatClient);
});
function joinChannels(chatClient) {
chatClient.getSubscribedChannels();
joinChannel('generalss','Generals Chat Channel');
}
function joinChannel(channelName, channelFriendlyName) {
console.log(channelName);
console.log(chatClient);
print('Attempting to join "' + channelName + '" chat channel...');
var promise = chatClient.getChannelByUniqueName(channelName);
promise.then(function(channel) {
console.log('Found ' + channelName + ' channel:');
channels[channelName] = channel;
console.log(channels);
setupChannel();
}).catch(function() {
// If it doesn't exist, let's create it
chatClient.createChannel({
uniqueName: channelName,
friendlyName: channelFriendlyName
}).then(function(channel) {
channels[channelName] = channel;
setupChannel(channelName);
});
});
}
你在哪裏設置「chatClient」?你能分享一點你的代碼來顯示你在哪裏設置客戶端以及如何調用這個函數? – philnash
@philnash我只是更新了我放在問題中的代碼,以顯示聊天客戶端 – jareds