Skip to content
sprsquish edited this page Aug 12, 2010 · 1 revision

Running in this way will give the bare-metal library.

This is useful if you want to build a library with the ability to handle XMPP connections.

You’ll need to start either a Blather::Stream::Client or Blather::Stream::Component stream passing in the client to handle incoming stanzas, jid, password, host, and port. Host and port are optional and will default to the JID’s domain and 5222 respectively.

The stream object expects the handling client to provide a few methods:

  • post_init will be called when the stream negotiation has finished and the connection is ready
  • unbind will be called when the stream is shutdown (via normal shutdown or stream error)
  • receive_data is sent all incoming stanzas or errors (the stream object will never raise an error. it simply passes an error into the handling client).
  • jid= is used with Blather::Stream::Client to set the JID after resource binding

Here’s a very basic example:

require 'blather'
class HandlingClient
  attr_accessor :jid

  def post_init
    #stream started
  end

  def unbind
    #stream closed
  end

  def receive_data(stanza_or_error)
    #handle incoming stanza or error
  end
end
handler = HandlingClient.new
stream = Blather::Stream::Client.start handler, '[email protected]', 'echo'
Clone this wiki locally