使用XMPP4r获取RID和SID

时间:2012-08-14 03:55:04

标签: ruby xmpp4r

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

我搜索了文档here,但它对我没什么帮助。

非常感谢任何帮助或建议。谢谢!

2 个答案:

答案 0 :(得分: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 :(得分:2)

这就是我为所有Openfire用户做的事情:

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



class PageController < ApplicationController
  def index

    Jabber::debug = true
    @client = Jabber::HTTPBinding::Client.new('sankalpsingha@sankalpmacbook') # 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