Getting RID and SID using XMPP4r

314 views Asked by At

I'm having problems in how to get the SID and the RID after I connect to my jabber server using the XMPP4r gem. I can connect successfully and I just need the SID and RID to pass it to the javascript.

I've searched the docs here but it hasn't helped me much.

Any help or suggestions will be much appreciated. Thanks!

2

There are 2 answers

2
Vincent Paca On BEST ANSWER

Just in case anyone else would encounter the same roadblock in the future, I solved this by accessing the instance variables directly like so:

First, require the httpbinding client, instead of client

require 'xmpp4r/httpbinding/client'

then connect by doing

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

The instance variables are @http_sid and @http_rid, and since they are not accessible I did

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

Then I stored those variables in my session so that I can use them on my Strophe.js client.

0
Sankalp Singha On

This is how I did it for all the Openfire Users :

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