Class: Jabber::BoshSession
- Inherits:
-
Object
- Object
- Jabber::BoshSession
- Defined in:
- lib/jabber4r/bosh_session.rb
Overview
XMPP Over BOSH class NOTE: xmpp.org/extensions/xep-0206.html
Constant Summary collapse
- DEFAULTS =
Public: Default connection options
{ host: "localhost", port: 5280, bind_uri: "/http-bind" }.freeze
Instance Attribute Summary collapse
-
#bind_uri ⇒ Object
readonly
Returns the value of attribute bind_uri.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#jid ⇒ Object
readonly
Returns the value of attribute jid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#rid ⇒ Object
readonly
Returns the value of attribute rid.
-
#sid ⇒ Object
readonly
Returns the value of attribute sid.
-
#stream_id ⇒ Object
readonly
Returns the value of attribute stream_id.
Class Method Summary collapse
-
.bind(username, password, options = {}) ⇒ Object
Public: Create new BOSH-session and bind it to jabber http-bind service.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Public: Is BOSH-session active? (no polling consider).
-
#authenticate(username, password) ⇒ Object
Public: Authenticate user in jabber server by his username and password NOTE: This authentication is Non-SASL xmpp.org/extensions/xep-0078.html.
-
#initialize(host, port, bind_uri) ⇒ BoshSession
constructor
Public: Create new BOSH-session (not binded to http-bind service).
-
#to_json ⇒ Object
Public: Represent BOSH-session as json object.
Constructor Details
#initialize(host, port, bind_uri) ⇒ BoshSession
Public: Create new BOSH-session (not binded to http-bind service)
host - String the jabber server host port - [String|Fixnum] the port of http-bind endpoint of jabber server bind_uri - String the http-bind uri
Examples
Jabber::BoshSession.new(“localhost”, 5280, “/http-bind”)
Returns Jabber::BoshSession
65 66 67 68 |
# File 'lib/jabber4r/bosh_session.rb', line 65 def initialize(host, port, bind_uri) @host, @port, @bind_uri = host, port, bind_uri @alive = false end |
Instance Attribute Details
#bind_uri ⇒ Object (readonly)
Returns the value of attribute bind_uri.
26 27 28 |
# File 'lib/jabber4r/bosh_session.rb', line 26 def bind_uri @bind_uri end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
26 27 28 |
# File 'lib/jabber4r/bosh_session.rb', line 26 def host @host end |
#jid ⇒ Object (readonly)
Returns the value of attribute jid.
25 26 27 |
# File 'lib/jabber4r/bosh_session.rb', line 25 def jid @jid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
26 27 28 |
# File 'lib/jabber4r/bosh_session.rb', line 26 def port @port end |
#rid ⇒ Object (readonly)
Returns the value of attribute rid.
25 26 27 |
# File 'lib/jabber4r/bosh_session.rb', line 25 def rid @rid end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
25 26 27 |
# File 'lib/jabber4r/bosh_session.rb', line 25 def sid @sid end |
#stream_id ⇒ Object (readonly)
Returns the value of attribute stream_id.
24 25 26 |
# File 'lib/jabber4r/bosh_session.rb', line 24 def stream_id @stream_id end |
Class Method Details
.bind(username, password, options = {}) ⇒ Object
Public: Create new BOSH-session and bind it to jabber http-bind service
username - String the login of jabber server user password - String the password of jabber server user options - Hash the options for jabber http-bind service (default: Empty hash)
:host - String the jabber server host
:port - [String|Fixnum] the port of http-bind endpoint of jabber server
:bind_uri - String the http-bind uri
Examples
Jabber::BoshSession.bind(“strech@localhost/res-1”, “secret-pass”) Jabber::BoshSession.bind(“strech@localhost/res-1”, “secret-pass”, )
Raises Jabber::AuthenticationError Returns Jabber::BoshSession
45 46 47 48 49 50 51 52 |
# File 'lib/jabber4r/bosh_session.rb', line 45 def self.bind(username, password, = {}) host, port, bind_uri = DEFAULTS.dup.merge!().values session = new(host, port, bind_uri) raise AuthenticationError, "Failed to login" unless session.authenticate(username, password) session end |
Instance Method Details
#alive? ⇒ Boolean
Public: Is BOSH-session active? (no polling consider)
Returns boolean
90 91 92 |
# File 'lib/jabber4r/bosh_session.rb', line 90 def alive? @alive end |
#authenticate(username, password) ⇒ Object
Public: Authenticate user in jabber server by his username and password NOTE: This authentication is Non-SASL xmpp.org/extensions/xep-0078.html
Examples
bosh = Jabber::BoshSession.new … bosh.authenticate(“strech@localhost/my-resource”, “super-secret-password”) # => true bosh.alive? # => true
Returns boolean
80 81 82 83 84 85 |
# File 'lib/jabber4r/bosh_session.rb', line 80 def authenticate(username, password) open_new_stream @jid = username.is_a?(JID) ? username : JID.new(username) @alive = login(jid, password) end |
#to_json ⇒ Object
Public: Represent BOSH-session as json object
Returns String
97 98 99 |
# File 'lib/jabber4r/bosh_session.rb', line 97 def to_json {jid: jid.to_s, rid: rid, sid: sid}.to_json end |