无法加入聊天频道 [英] Unable to join chat channel

查看:32
本文介绍了无法加入聊天频道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试加入我一直在使用的 twilio 代码中的频道时,它出现错误,指出它无法读取 null 的属性 'getChannelByUniqueName'".聊天有效,但是当我尝试在不同的浏览器上打开它时,比如 firefox 而不是 chrome,它显示错误提供的唯一名称的频道已经存在".有人可以帮忙解决这个问题吗?

When trying to join a channel in the twilio code I've been working with, it comes up with the error saying that it "Cannot read property 'getChannelByUniqueName' of null". The chat works but when I try to open it up on a different browser, like firefox instead of chrome, it says the error "Channel with provided unique name already exist". Can anyone help with this problem?

    // 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);
      });
    });
  }

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

在我看来,您没有将 chatClient 传递给您的 joinChannel 方法(其次,客户端可能尚未完全初始化).

It looks to me like you aren't passing the chatClient to your joinChannel method (and secondly that the client might not be fully initialised yet).

我将使用以下内容初始化客户端,该方法使用 create 方法返回一个承诺,该承诺在客户端准备好时解析.

I would initialise the client with the following, which uses the create method that returns a promise that resolves when the Client is ready.

  // Initialize the Chat client
  new Twilio.Chat.Client.create(data.token).then(function(chatClient) {
    joinChannels(chatClient);
  });
});

然后,确保将客户端传递给 joinChannel 方法:

Then, make sure you pass the client through to the joinChannel method:

function joinChannels(chatClient) {
  chatClient.getSubscribedChannels();
  joinChannel(chatClient, 'generalss','Generals Chat Channel');
}

function joinChannel(chatClient, channelName, channelFriendlyName) {
  // the rest...
}

让我知道这是否有帮助.

Let me know if that helps at all.

这篇关于无法加入聊天频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆