Sha256: 15ce9bf2d42edb9854daaea54d7a29aada47f19e599aca4fa625e2c2fa6aa67b

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require "rubygems"
require "compp"

## Default
# Start the HTTP server with the right handler.
# A user connects and provides his jid:password
# By default, the 'message' stanzas send to 'jid' will be sent to the Comet connection
Compp.start(Compp::Default, {:host => '0.0.0.0', :port => 8000})

## Another Example : customization
# You can write classes that overide the default default behavior open XMPP events.
# We use Blather's syntax.
# This Example just show incoming XMPP notifications from Superfeedr (http://superfeedr.com)
class MyCompp < Compp::Default
  ##
  # This example just 
  def register_xmpp_handlers(connection)
    connection.register_handler :message  do |m|
      status = m.xpath("//message/ps:event/sf:status", {"ps" => "http://jabber.org/protocol/pubsub#event", "sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first
      if !status.nil?
        feed        = status["feed"]
        http_code   = status.xpath("./sf:http/@code", {"sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first
        msg_status  = status.xpath("./sf:http",       {"sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first.text
        orbitize("#{feed} => #{http_code} (#{msg_status})")
      end
    end
  end
end
# Starts the server 
Compp.start(MyCompp, {:host => '0.0.0.0', :port => 8000})

##
# A Sprinkler example
# The HTTP server connects just 1 client and broadcasts the messages to any HTTP comet connection
Compp.start(Compp::Sprinkler, {:host => '0.0.0.0', :port => 8000, :jid => "jid@server.tld", :password => "password"})

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
compp-1.0.0 example.rb