Twilio聊天打字()不工作

问题描述:

我正在成功地集成于JavaScript的twilio聊天API,但是我对.typing()函数有问题,这似乎打字功能不触发Twilio聊天打字()不工作

“typingStarted”和'打字',我可以有一些建议吗?

这里是我的代码使用这个版本的API

https://media.twiliocdn.com/sdk/js/chat/v1.0/twilio-chat.js

+0

只是为了确认,当您以不同的用户身份登录并开始输入时,是否发现打字事件不会为一名用户开火? – philnash

+1

是的你是对的,它应该从其他聊天用户进行测试,而不是在我们自己的聊天窗口中进行测试 –

我不好,代码还行,但是我试图用一个错误的使用情况下,我们需要测试

var chatChannel; 
    var chatClient; 
    var username; 

    $.post("/tokens", function(data) { 
    username = data.username; 
    chatClient = new Twilio.Chat.Client(data.token); 
    chatClient.getSubscribedChannels().then(createOrJoinGeneralChannel); 
    }); 

    function createOrJoinGeneralChannel() { 
    // Get the general chat channel, which is where all the messages are 
    // sent in this simple application 
    // print('Attempting to join "general" chat channel...'); 
    var promise = chatClient.getChannelByUniqueName("#{params[:chat_channel]}"); 
    promise.then(function(channel) { 
     chatChannel = channel; 
     console.log("#{params[:chat_channel]} is exist"); 
     console.log(chatChannel); 
     setupChannel(); 
    }).catch(function() { 
     // If it doesn't exist, let's create it 
     console.log("creating #{params[:chat_channel]} channel"); 
     chatClient.createChannel({ 
      uniqueName: "#{params[:chat_channel]}", 
      friendlyName: 'General Chat Channel' 
     }).then(function(channel) { 
      console.log("Created #{params[:chat_channel]} channel:"); 
      console.log(channel); 
      chatChannel = channel; 
      setupChannel(); 
     }); 
    }); 
    } 

    function setupChannel() { 
    chatChannel.join().then(function(channel) { 
     printMessage(username + ' joined the chat.'); 
     chatChannel.on('typingStarted', showTypingStarted); 
     chatChannel.on('typingEnded', hideTypingStarted); 
    }); 
    chatChannel.on('messageAdded', function(message) { 
     printMessage(message.author + ": " + message.body); 
    }); 
    } 

    function showTypingStarted(member) { 
    console.log('somebody is typing'); 
    $('#is_typing').html(member.identity + ' is typing...') 
    } 

    function hideTypingStarted(member) { 
    $('#is_typing').html(''); 
    } 

    var $input = $('#chat-input'); 
    $input.on('keydown', function(e) { 
    if (e.keyCode == 13) { 
     chatChannel.sendMessage($input.val()); 
     $input.val(''); 
    } else { 
     //console.log('typing'); 
     chatChannel.typing(); 
    } 
    }); 

IM它来自聊天用户的另一边,而不是我们自己的聊天窗口

欢呼声