Sha256: ebf7a5ab4989095fd1c93798da0dfe69282fe44bf844bcdf303c8ff9f21497bc

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

module Blather # :nodoc:
class Stream # :nodoc:

  class Resource < StreamHandler # :nodoc:
    def initialize(stream, jid)
      super stream
      @jid = jid
    end

  private
    ##
    # Respond to the bind request
    # If @jid has a resource set already request it from the server
    def bind
      response = Stanza::Iq.new :set
      @id = response.id

      binder = XMPPNode.new('bind')
      binder.namespace = 'urn:ietf:params:xml:ns:xmpp-bind'

      binder << XMPPNode.new('resource', @jid.resource) if @jid.resource

      response << binder
      @stream.send response
    end

    ##
    # Process the result from the server
    # Sets the sends the JID (now bound to a resource)
    # back to the stream
    def result
      LOG.debug "RESOURE NODE #{@node}"
      # ensure this is a response to our original request
      if @id == @node['id']
        @jid = JID.new @node.find_first('//bind_ns:bind/bind_ns:jid', :bind_ns => 'urn:ietf:params:xml:ns:xmpp-bind').content
        success @jid
      end
    end

    ##
    # Server returned an error
    def error
      failure StanzaError.import(@node)
    end
  end #Resource

end #Stream
end #Blather

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
sprsquish-blather-0.3.0 lib/blather/stream/resource.rb
sprsquish-blather-0.3.1 lib/blather/stream/resource.rb
sprsquish-blather-0.3.2 lib/blather/stream/resource.rb
sprsquish-blather-0.3.3 lib/blather/stream/resource.rb
sprsquish-blather-0.3.4 lib/blather/stream/resource.rb
blather-0.3.1 lib/blather/stream/resource.rb
blather-0.3.0 lib/blather/stream/resource.rb
blather-0.3.3 lib/blather/stream/resource.rb
blather-0.3.2 lib/blather/stream/resource.rb
blather-0.3.4 lib/blather/stream/resource.rb