2015-02-06 5 views

답변

0

언급 한 바와 같이, 필자는 인증 온라인에서 온라인 상태를 온라인으로 반환해야한다고 생각합니다.

var on_presence = function(presence) { 
    // do some stuff 
    return true; 
}; 

XMPP 프로토콜에 따라 수신자가 온라인 상태로 표시되어야합니다.

1

업데이트 : 컨트롤러 내부에 on_presenceon_message 함수를 넣으려고합니다. 작동합니다!

<html> 
<head> 
    <script type="text/javascript" src="bower_components/angular/angular.min.js"></script> 
    <script type="text/javascript" src="strophe.min.js"></script> 
</head> 
<body ng-app="myApp"> 
    <div ng-controller="init"> 
    </div> 

    <script type="text/javascript"> 

    BOSH_SERVICE = 'http://localhost/http-bind'; 
    xmpp_user = "user"; 
    xmpp_domain = "user.local"; 
    xmpp_userdomain = "[email protected]"; 
    xmpp_password = "userpassword"; 

    angular. 
    module('myApp', []). 
    controller('init', function(xmppAuth){ 
     xmppAuth.auth(xmpp_userdomain,xmpp_password); 

     on_presence = function (presence){ 
      console.log('presence'); 
      return true; 
     } 

     on_message = function (message){ 
      //console.log('message'); 
      console.log(message); 
      return true; 
     } 
    }). 
    service('xmppAuth', function() { 
     return { 
      auth: function(login, password) { 
       connect = new Strophe.Connection(BOSH_SERVICE); 
       connect.connect(login, password, function (status) { 
        if (status === Strophe.Status.CONNECTED) { 
         console.log("auth pass"); 

         //try send helo 
         var message = "helo"; 
         var to = "[email protected]"; 
         if(message && to){ 
          var reply = $msg({ 
           to: to, 
           type: 'chat' 
          }) 
          .cnode(Strophe.xmlElement('body', message)).up() 
          .c('active', {xmlns: "http://jabber.org/protocol/chatstates"}); 
          connect.send(reply); 
          console.log('I sent ' + to + ': ' + message); 
         } 

         //addhandler receive messg 
         connect.addHandler(onMessage, null, "message", null, null, null); 
         var onMessage = function (message){ 
          console.log('message'); 
          return true; 
         } 

        } 
       }) 
      } 
     } 
    }) 

    </script> 
</body> 
</html> 
+0

고맙습니다. – Senthil