Sha256: 8cf5ca21fa1369c028b9210544a2e3ce2715cd73dd0f0950060471d5e7b75567

Contents?: true

Size: 1.31 KB

Versions: 35

Compression:

Stored size: 1.31 KB

Contents

module Jabber

  module Command

    ##
    # The Responder Helper handles the low-level stuff of the
    # Ad-hoc commands (JEP 0050).
    class Responder

      ##
      # Initialize a Responder
      def initialize(stream)
        @stream = stream
        @commandsdiscocbs = CallbackList.new
        @commandexeccbs = CallbackList.new

        stream.add_iq_callback(180, self) { |iq|
          iq_callback(iq)
        }
      end

      ##
      # Add a callback for <query> stanzas asking for the list
      # of ad-hoc commands
      def add_commands_disco_callback(priority = 0, ref = nil, &block)
        @commandsdiscocbs.add(priority, ref, block)
      end

      ##
      # Add a callback for <command> stanzas asking for the execution
      # of an ad-hoc command
      def add_commands_exec_callback(priority = 0, ref = nil, &block)
        @commandexeccbs.add(priority, ref, block)
      end

      ##
      # Handles <iq> stanzas and execute callbacks
      def iq_callback(iq)
        if iq.type == :get
          if iq.query.kind_of?(Jabber::Discovery::IqQueryDiscoItems) &&
             iq.query.node == "http://jabber.org/protocol/commands"
            @commandsdiscocbs.process(iq)
          end
        elsif iq.type == :set && iq.command
          @commandexeccbs.process(iq)
        end
      end

    end

  end

end

Version data entries

35 entries across 35 versions & 13 rubygems

Version Path
brontes3d-xmpp4r-0.4 lib/xmpp4r/command/helper/responder.rb
bryanl-xmpp4r-0.3.2 lib/xmpp4r/command/helper/responder.rb
edavey-xmpp4r-0.4.1 lib/xmpp4r/command/helper/responder.rb
edavey-xmpp4r-0.4.2 lib/xmpp4r/command/helper/responder.rb
edavey-xmpp4r-0.4 lib/xmpp4r/command/helper/responder.rb
heipei-xmpp4r-0.3.2 lib/xmpp4r/command/helper/responder.rb
ln-xmpp4r-0.5 lib/xmpp4r/command/helper/responder.rb
mojodna-xmpp4r-0.4.0.2 lib/xmpp4r/command/helper/responder.rb
mojodna-xmpp4r-0.4.0.3 lib/xmpp4r/command/helper/responder.rb
seanohalpin-xmpp4r-0.4.1 lib/xmpp4r/command/helper/responder.rb
xmpp4r-0.5.6 lib/xmpp4r/command/helper/responder.rb
xmpp4r-0.5.5 lib/xmpp4r/command/helper/responder.rb
gmcmillan-xmpp4r-0.6.2 lib/xmpp4r/command/helper/responder.rb
gmcmillan-xmpp4r-0.6.1 lib/xmpp4r/command/helper/responder.rb
gmcmillan-xmpp4r-0.6 lib/xmpp4r/command/helper/responder.rb
gmcmillan-xmpp4r-0.5 lib/xmpp4r/command/helper/responder.rb
mad-p-xmpp4r-0.6.3 lib/xmpp4r/command/helper/responder.rb
mad-p-xmpp4r-0.6.2 lib/xmpp4r/command/helper/responder.rb
mad-p-xmpp4r-0.6.1 lib/xmpp4r/command/helper/responder.rb
mad-p-xmpp4r-0.6.0 lib/xmpp4r/command/helper/responder.rb