0

vLine API をアプリケーションに統合し始めましたが、recv:imメッセージを送信するたびにイベントが 2 回発行されるという問題があります。

チャットメッセージを送信しているテンプレート側のコードは次のとおりです。

$('#chat_room_input').bind('keypress', function(e) {

            if(e.keyCode==13){
                console.log('we send the message here');
                VlineObject.sendMessageToPerson_(remoteUserId);
            }

     });

また、ここに私のjsアプリファイルの内容があります:

VlineApp = function(serviceId, current_user, ui_local_widgets, people) {


  this.ui_local_widgets_ = ui_local_widgets;
  this.serviceId_ = serviceId;

  this.current_user_ = current_user;
  this.profile_ = current_user.profile;
  this.auth_token_ = current_user.auth_token;

  this.people_ = people;

  // the only required option is your serviceId 
  this.client_ = vline.Client.create({ serviceId: this.serviceId, "ui": true,  "uiOutgoingDialog":true, "uiIncomingDialog":true, "uiBigGreenArrow":true, "uiVideoPanel": this.ui_local_widgets_.videopanel });

  this.client_.on('login', this.onLoginUpdatePresence_, this);

  // window.PROFILE and window.AUTH_TOKEN are generated by your application server 
  // and set in a script tag in your HTML document 
  this.client_.login(this.serviceId_, this.profile_, this.auth_token_)
      .done(this.init_, this);




}

VlineApp.prototype.init_ = function(session) {

  console.log('here in init ');
  //console.log(this.people_);


  this.session_ = session;
  this.client_.on('recv:im', this.onMessage_, this);

}



VlineApp.prototype.updatePresence = function(e){

  //FUNCTION CALL WHEN THE EVENT IS FIRED
  var person = e.target;
  var presenceState = person.getPresenceState();
  var shortId = person.getShortId();

  this.updatePresenceUI(shortId, presenceState);

}

VlineApp.prototype.updatePresenceUI = function(personid, presenceState) {

  //UPDATE UI PRESENCE STATUS
  $('#'+personid+'_status').html(presenceState);

  /*
   // Show/hide the call link based on presence
   elem = document.getElementById('call-' + shortId);
   if (presenceState === "online" && shortId !== currentUserid) {
   elem.style.display = "";
   } else {
   elem.style.display = "none";
   }
   */

}

VlineApp.prototype.updatePresenceAll = function(person){

  //UPDATE PRESENCE STATUS FOR THE CURRENT PERSON AND ADD TRIGGER EVENT     
  this.updatePresence({target: person});
  person.on('change:presenceState', this.updatePresence, this);

}



VlineApp.prototype.onLoginUpdatePresence_ = function(event){


  this.session_ = event.target;

  for (var i=0; i < this.people_.length; i++)
  {
    this.session_.getPerson(this.people_[i])
        .done(this.updatePresenceAll, this);
  }
}


VlineApp.prototype.showAlertUI = function(sender_name, sender_thumb, message_body) {

  //here we should have push message to the chatroom
  $('#'+this.ui_local_widgets_.chat_room_messages).append('<div>'+sender_name+' :'+message_body+'</div>');
}

VlineApp.prototype.onMessage_ = function(event) {

  console.log('aici in on message');
  var msg = event.message, sender = msg.getSender();
  this.showAlertUI(sender.getDisplayName(), sender.getThumbnailUrl(), msg.getBody());

};

VlineApp.prototype.sendMessageToPersonObj = function(person)
{
  var message = $('#'+this.ui_local_widgets_.chat_room_input).val();
  $('#'+this.ui_local_widgets_.chat_room_input).val('');
  //$('#'+this.ui_local_widgets_.chat_room_messages).append('<div>You :'+message+'</div>');
  this.showAlertUI('You', '', message);
  person.postMessage(message);

}

VlineApp.prototype.sendMessageToPerson_ =  function(personid) {

  if (this.session_)
  {
    this.session_.getPerson(personid)
        .done(this.sendMessageToPersonObj, this);
  }
}

VlineApp.prototype.getMessagesHistoryObj = function(person){

  var messages_history = person.getMessages();
  console.log('messages_history');
  console.log(messages_history);

}

VlineApp.prototype.getMessagesHistory_ = function(personid) {
  console.log(personid);
  console.log(this.session_);
  if (this.session_)
  {
    this.session_.getPerson(personid)
        .done(this.getMessagesHistoryObj, this);
  }
}


VlineApp.prototype.callPersonObj = function(person) {

  person.startMedia();
}

VlineApp.prototype.callPerson_ =  function(personid) {

  if (this.session_)
  {
    this.session_.getPerson(personid)
        .done(this.callPersonObj, this);
  }
}

チャットの会話が、Vline からの 2 つの異なるトークンを持つ 2 人の異なるユーザー間であることを指定する必要があります。

助言がありますか?

4

1 に答える 1