2012-12-25 41 views
-1

我正在開發一個需要包含會話附件的XMPP Web應用程序。我正在使用Openfire XMPP服務器。我已經成功實現了創建會話的服務器端附件,並獲得了sid並刪除了會話。不幸的是,我陷入了下一部分。Strophe會話附件 - 403禁止

據我所知,得到SID和RID後,我需要使用Strophe.Connection.attach()來strphe連接到現有會話。之後,我正在發出一個IQ請求,從服務器獲得正確的響應。不過,我的狀態沒有發生任何變化,即應用程序既不連接也不附連,因此我無法做任何事情。 IQ請求後,服務器按正常消息按時響應,然後在下一個請求中,我得到一個403禁止的錯誤,連接終止。

下面是代碼:

var BOSH_SERVICE = 'http://localhost/cosys-rtw/'; 
var connection = null; 
var sid = ""; 
var rid = 0; 
function notifyUser(msg) 
{ 
    if (msg.getAttribute('from') == "[email protected]/pingstream") { 
     var elems = msg.getElementsByTagName('body'); 
     var body = elems[0]; 
     $('#notifications').append(Strophe.getText(body)); 
} 
return true; 
} 

function onConnect(status) 
{ 
    console.log("Connect") 
console.log(status) 
if (status == Strophe.Status.ATTACHED) { 
    $('#notifications').html('<p class="welcome">Hello! Any new posts will appear below.</p>'); 
    connection.addHandler(notifyUser, null, 'message', null, null, null); 
    connection.send($pres().tree()); 
}  
} 

$(document).ready(function() { 
$.ajax({'url':'http://localhost/x', 
     'method':'get', 
     'success':function(response){ 
      console.log(response); 
      console.log(jQuery.parseJSON(response)); 
      resp = jQuery.parseJSON(response); 
      window.sid = resp.sid; 
      window.rid = resp.rid; 
      prepareStrophe();    
     }}); 
}); 

function prepareStrophe(){ 
console.log(BOSH_SERVICE); 
jid = "[email protected]"; 
connection = new Strophe.Connection(BOSH_SERVICE); 
console.log(window.rid); 
console.log(window.sid); 
connection.attach( jid,window.sid,window.rid,null); 
connection.sendIQ($iq({to:Strophe.getDomainFromJid(jid),type:"get"}) 
        .c('query',{xmlns:'http://jabber.org/protocol/disco#info'}), 
        function(){ 
         if (status == Strophe.Status.ATTACHED) { 
        connection.send($pres().tree());} 
        });} 

我得到的IQ請求follwoing響應:

<body xmlns="http://jabber.org/protocol/httpbind"> 
<iq id="6173:sendIQ" xmlns="jabber:client" type="result" from="ghost" to="[email protected]/6b8bfe07"> 
<query xmlns="http://jabber.org/protocol/disco#info"> 
<identity category="server" name="Openfire Server" type="im"></identity> 
<identity category="pubsub" type="pep"></identity> 
<feature var="http://jabber.org/protocol/pubsub#delete-nodes"></feature> 
    . 
    . 
    . 
<feature var="http://jabber.org/protocol/pubsub#purge-nodes"></feature> 
<feature var="http://jabber.org/protocol/disco#info"></feature> 
<feature var="http://jabber.org/protocol/rsm"></feature> 
</query> 
</iq> 
</body> 

這種反應不說,本次會議是有效的。我對嗎? 我無法想象這件事,所以現在我將這件事交給社區。 順便說一句 - 聖誕快樂

回答