Twilio聊天事件memberUpdated和userInfoUpdated从来没有发射

问题描述:

我在找什么情况是,这些事件被解雇,我有实现它的这些代码Twilio聊天事件memberUpdated和userInfoUpdated从来没有发射

jQuery(document).ready(function() { 

    var chatChannel; 
    var chatClient; 
    var username; 
    var $input = $('#chat-input'); 

    $.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(); 
     return channel.getMembers(); 
     // $input.removeClass('.hidden') 
    }) 
    .then(function(members){ 
     members.forEach(function(member){ 
     console.log('member', member); 
     member.on('userInfoUpdated', function(){ 
      console.log('userInfoUpdated', member); 
     }) 
     }) 
    }) 
    .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('memberJoined', notifyMemberJoined); 
     chatChannel.on('memberLeft', notifyMemberLeft); 
     chatChannel.on('memberUpdated', updateMemberMessageReadStatus); 
    }); 
    chatChannel.on('messageAdded', function(message) { 
     printMessage(message.author + ": " + message.body); 
    }); 
    } 

    function updateMemberMessageReadStatus(member){ 
    console.log('memberUpdated'); 
    console.log('member.lastConsumedMessageIndex', member.lastConsumedMessageIndex); 
    console.log('member.lastConsumptionTimestamp', member.lastConsumptionTimestamp); 
    } 

    function leaveCurrentChannel() { 
    if (chatChannel) { 
     chatChannel.leave().then(function (leftChannel) { 
     console.log('left ' + leftChannel.friendlyName); 
     leftChannel.removeListener('messageAdded', function(message) { 
      printMessage(message.author + ": " + message.body); 
     }); 
     leftChannel.removeListener('typingStarted', showTypingStarted); 
     leftChannel.removeListener('typingEnded', hideTypingStarted); 
     leftChannel.removeListener('memberJoined', notifyMemberJoined); 
     leftChannel.removeListener('memberLeft', notifyMemberLeft); 
     leftChannel.removeListener('memberUpdated', updateMemberMessageReadStatus); 
     }); 
    } 
    } 

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

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

    function notifyMemberJoined(member) { 
    console.log('notifyMemberJoined'); 
    printMessage(member.identity + ' joined the channel'); 
    } 

    function notifyMemberLeft(member) { 
    console.log('notifyMemberLeft'); 
    printMessage(member.identity + ' left the channel'); 
    } 

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

    window.addEventListener("beforeunload", function (e) { 
    // var confirmationMessage = "\o/"; 

    (e || window.event).returnValue = leaveCurrentChannel(); //Gecko + IE 
    return leaveCurrentChannel();       //Webkit, Safari, Chrome 
    }); 

}); 

,我已经采取alook到控制台查看如果我的

console.log('userInfoUpdated', member); 

或这些家伙

console.log('memberUpdated'); 
console.log('member.lastConsumedMessageIndex', member.lastConsumedMessageIndex); 
console.log('member.lastConsumptionTimestamp', member.lastConsumptionTimestamp); 

,他们从未被触发,我的测试过程中聊天活动中, d我是在我要去究竟如何网上显示我如何对用户或消息的状态被读取或困惑读

所以请赐教上的情况下,在这里谢谢

Twilio开发布道者。

根据最新版本的Twilio Chat的JS文档,您需要倾听会员的事件名为'updated'。因此,倾听'userInfoUpdated'将无法​​正常工作。

我也建议此代码中:

chatChannel.join().then(function(channel) { 
    //... 
    chatChannel.on('memberUpdated', updateMemberMessageReadStatus); 
    //... 
}) 

您使用传递给回调的channel,而不是原来的chatChannel对象。像这样:

chatChannel.join().then(function(channel) { 
    //... 
    channel.on('memberUpdated', updateMemberMessageReadStatus); 
    //... 
}) 

我不知道这是否能解决问题,但我现在还想不到其他问题。