2012-08-14 73 views
2

我在使用XMPP4r gem连接到我的jabber服务器后,如何获取SID和RID时遇到问题。我可以连接成功,我只需要SID和RID将它传递给JavaScript。使用XMPP4r获取RID和SID

我搜查了文档here但它对我没有太大的帮助。

任何帮助或建议将不胜感激。谢谢!

回答

2

万一别人会遇到同样的障碍在未来,我解决了这个通过直接访问实例变量像这样:

首先,需要httpbinding客户,而不是客户端

require 'xmpp4r/httpbinding/client' 

然后通过执行

@client = Jabber::HTTPBinding::Client.new("your_jabber_id_with/resource") 
@client.connect("your_bosh_url") 
@client.auth("your_jabber_password") 

实例变量@http_sid和@http_rid连接,并且由于它们无法访问我所做

sid = @client.instance_variable_get("@http_sid") 
rid = @client.instance_variable_get("@http_rid") 

然后我将这些变量存储在我的会话中,以便我可以在我的Strophe.js客户端上使用它们。

+1

与失败:HTTP请求的路径是空:S – Rubytastic 2013-10-03 17:12:06

+0

这里同样的错误......请告诉我们你是如何解决的HTTP请求路径空问题? – 2014-08-18 18:41:16

2

这是我做的所有的Openfire用户:

require 'xmpp4r' 
require 'xmpp4r/httpbinding/client' 



class PageController < ApplicationController 
    def index 

    Jabber::debug = true 
    @client = Jabber::HTTPBinding::Client.new('[email protected]') # This is the JID 
    @client.connect('http://localhost:7070/http-bind/') # This is the bosh address 
    @client.auth('sankalp') # This is the password 
    @sid = @client.instance_variable_get('@http_sid') 
    @rid = @client.instance_variable_get('@http_rid') 


    end 
end