2017-06-22 6 views
0

が動作していない、それはタイピング機能がトリガされていないようですTwilioチャットタイピングは、()しかし、私は()関数を.typing上の問題を抱えて、私は成功したJavaScriptのtwilioチャットAPIを統合しています

は「typingStarted」と 'typingEnded'、私はいくつかのアドバイスがありますか?ここ

コードは大丈夫だった私の悪いが、しかし、私は間違ったユースケースを試してみましたこのバージョンのAPI

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

+0

確認するには、別のユーザーとしてログインして入力を開始したときに、入力イベントが1人のユーザーに対して発生していないことを確認していますか? – philnash

+1

はい、あなたは正しいです、私たちのチャットウィンドウではなく、他のチャットユーザーからテストする必要があります –

答えて

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

イムで、我々はテストする必要がありますそれは私たちのチャットウィンドウではなく、チャットユーザーの反対側からです

歓声

関連する問題