class Blather::Stream::Resource
@private
Constants
- BIND_NS
Public Class Methods
new(stream, succeed, fail)
click to toggle source
Calls superclass method
Blather::Stream::Features::new
# File lib/blather/stream/features/resource.rb, line 9 def initialize(stream, succeed, fail) super @jid = stream.jid end
Public Instance Methods
receive_data(stanza)
click to toggle source
# File lib/blather/stream/features/resource.rb, line 14 def receive_data(stanza) @node = stanza case stanza.element_name when 'bind' then bind when 'iq' then result else fail!(UnknownResponse.new(@node)) end end
Private Instance Methods
bind()
click to toggle source
Respond to the bind request If @jid has a resource set already request it from the server
# File lib/blather/stream/features/resource.rb, line 27 def bind response = Stanza::Iq.new :set @id = response.id response << (binder = XMPPNode.new('bind', response.document)) binder.namespace = BIND_NS if @jid.resource binder << (resource = XMPPNode.new('resource', binder.document)) resource.content = @jid.resource end @stream.send response end
result()
click to toggle source
Process the result from the server Sets the sends the JID
(now bound to a resource) back to the stream
# File lib/blather/stream/features/resource.rb, line 46 def result if @node[:type] == 'error' fail! StanzaError.import(@node) return end # ensure this is a response to our original request if @id == @node['id'] @stream.jid = JID.new @node.find_first('bind_ns:bind/bind_ns:jid', :bind_ns => BIND_NS).content succeed! else fail!("BIND result ID mismatch. Expected: #{@id}. Received: #{@node['id']}") end end