`
iluoxuan
  • 浏览: 571217 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

strophe.js 实现web客户端..openfire

 
阅读更多

 

<body rid='2611494097' xmlns='http://jabber.org/protocol/httpbind' sid='dfd121f0'>

  <message to='wq@lijueqing' from='ljq@lijueqing' type='chat' xmlns='jabber:client'>

    <body>hello</body>

  </message>

</body>

 

发送的js:

 

$('#send').bind('click', function () {

        var msg=$('#msg').val();

        toId = $('#tojid').val();

   var reply = $msg({to: toId, from: fromId , type: 'chat'}).cnode(Strophe.xmlElement('body', '' ,msg));

   connection.send(reply.tree());

   appendToHis(new Date().toLocaleTimeString() + "  Me:  "  + msg);

   $('#msg').val('');

    });

 

 

接收的:

<body xmlns='http://jabber.org/protocol/httpbind'>

  <message xmlns='jabber:client' id='pE7U3-33' to='ljq@lijueqing/dfd121f0' from='wq@lijueqing/Spark 2.6.3' type='chat'>

    <body>hello body</body><thread>s1pmSh</thread>

      <x xmlns='jabber:x:event'>

        <offline/><composing/>

      </x>

  </message>

</body>

 

 

查找好友:

 

<body rid='2541497325' xmlns='http://jabber.org/protocol/httpbind' sid='75c736be'>

  <iq type='get' xmlns='jabber:client' id='5910:sendIQ'>

    <query xmlns='jabber:iq:roster'/>

  </iq>

</body>

 

type是get表示请求:一个成功的get查询的结果type=”result”的<iq/>元素:一个不成功的返回是一个type=”error”的<iq/>元素

 

返回的结果:

 <body xmlns='http://jabber.org/protocol/httpbind'>

   <iq xmlns='jabber:client' type='result' id='5910:sendIQ' to='ljq@lijueqing/75c736be'>

     <query xmlns='jabber:iq:roster'><item jid='wq@lijueqing' name='wq' subscription='both'>

       <group>Friends</group>

       </item>

     </query>

   </iq>

 </body>

 

 <body xmlns='http://jabber.org/protocol/httpbind'>

   <iq xmlns='jabber:client' type='result' id='5912:sendIQ' to='ljq@lijueqing/75c736be'>

     <query xmlns='jabber:iq:roster'>

       <item jid='sss@lijueqing' name='sss' subscription='to'>

         <group>Friends</group>

       </item>

       <item jid='wq@lijueqing' name='wq' subscription='both'>

         <group>Friends</group>

       </item>

     </query>

   </iq>

 </body>

 

 :js代码获取:

 $('#friends').bind('click', function () {

        var iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});

     connection.sendIQ(iq, getFriends); // getFriends是回调函数

    });

 

  function getFriends(iq){

     $(iq).find('item').each(function () {

           var jid = $(this).attr('jid');

            var name = $(this).attr('name') || jid;

     });

  }

 

退出的:

 

 <body rid='2541497375' xmlns='http://jabber.org/protocol/httpbind' sid='75c736be' type='terminate'><presence xmlns='jabber:client' type='unavailable'/></body>

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics