Class: RubyBOSH
- Inherits:
-
Object
- Object
- RubyBOSH
- Defined in:
- app/controllers/ruby_bosh.rb
Defined Under Namespace
Classes: AuthFailed, ConnFailed, Error, Timeout
Constant Summary collapse
- BOSH_XMLNS =
'http://jabber.org/protocol/httpbind'
- TLS_XMLNS =
'urn:ietf:params:xml:ns:xmpp-tls'
- SASL_XMLNS =
'urn:ietf:params:xml:ns:xmpp-sasl'
- BIND_XMLNS =
'urn:ietf:params:xml:ns:xmpp-bind'
- SESSION_XMLNS =
'urn:ietf:params:xml:ns:xmpp-session'
- CLIENT_XMLNS =
'jabber:client'
- @@logging =
false
Instance Attribute Summary collapse
-
#custom_resource ⇒ Object
Returns the value of attribute custom_resource.
-
#jid ⇒ Object
Returns the value of attribute jid.
-
#rid ⇒ Object
Returns the value of attribute rid.
-
#sid ⇒ Object
Returns the value of attribute sid.
-
#success ⇒ Object
Returns the value of attribute success.
Class Method Summary collapse
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(jid, pw, service_url, opts = {}) ⇒ RubyBOSH
constructor
A new instance of RubyBOSH.
- #success? ⇒ Boolean
Constructor Details
#initialize(jid, pw, service_url, opts = {}) ⇒ RubyBOSH
Returns a new instance of RubyBOSH.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/ruby_bosh.rb', line 26 def initialize(jid, pw, service_url, opts={}) @service_url = service_url # Extract the resource if present split_jid = jid.split("/") @jid = split_jid.first @custom_resource = split_jid.last if split_jid.length > 1 @pw = pw @host = @jid.split("@").last @success = false @timeout = opts[:timeout] || 3 #seconds @headers = {"Content-Type" => "text/xml; charset=utf-8", "Accept" => "text/xml"} @wait = opts[:wait] || 5 @hold = opts[:hold] || 3 @window = opts[:window] || 5 end |
Instance Attribute Details
#custom_resource ⇒ Object
Returns the value of attribute custom_resource.
25 26 27 |
# File 'app/controllers/ruby_bosh.rb', line 25 def custom_resource @custom_resource end |
#jid ⇒ Object
Returns the value of attribute jid.
25 26 27 |
# File 'app/controllers/ruby_bosh.rb', line 25 def jid @jid end |
#rid ⇒ Object
Returns the value of attribute rid.
25 26 27 |
# File 'app/controllers/ruby_bosh.rb', line 25 def rid @rid end |
#sid ⇒ Object
Returns the value of attribute sid.
25 26 27 |
# File 'app/controllers/ruby_bosh.rb', line 25 def sid @sid end |
#success ⇒ Object
Returns the value of attribute success.
25 26 27 |
# File 'app/controllers/ruby_bosh.rb', line 25 def success @success end |
Class Method Details
.initialize_session(*args) ⇒ Object
63 64 65 66 |
# File 'app/controllers/ruby_bosh.rb', line 63 def self.initialize_session(*args) new(*args).connect end |
.logging=(value) ⇒ Object
21 22 23 |
# File 'app/controllers/ruby_bosh.rb', line 21 def self.logging=(value) @@logging = value end |
.register(user) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/ruby_bosh.rb', line 43 def self.register(user) salt = SecureRandom.random_bytes(64) key = ActiveSupport::KeyGenerator.new('password').generate_key(salt) # => "\x89\xE0\x156\xAC..." crypt = ActiveSupport::MessageEncryptor.new(key) # => #<ActiveSupport::MessageEncryptor ...> ap ENV['DOORKEEPER_APP_ID'] encrypted_data = crypt.encrypt_and_sign("#{user.email}_#{ENV['DOORKEEPER_APP_ID']}") jid = Jabber::JID.new("#{encrypted_data}@idlecampus.com") client = Jabber::Client.new(jid) Jabber::debug = false client.connect fields = {} client.register("#{ENV['DOORKEEPER_APP_SECRET']}", fields) client.close encrypted_data end |
Instance Method Details
#connect ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/ruby_bosh.rb', line 68 def connect initialize_bosh_session if send_auth_request send_restart_request request_resource_binding @success = send_session_request p @success end raise RubyBOSH::AuthFailed, "could not authenticate #{@jid}" unless success? @rid += 1 #updates the rid for the next call from the browser [@jid, @sid, @rid] end |
#success? ⇒ Boolean
59 60 61 |
# File 'app/controllers/ruby_bosh.rb', line 59 def success? @success == true end |