Class: Jabber::Command::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/xmpp4r-0.4/lib/xmpp4r/command/helper/responder.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Responder

Initialize a Responder



12
13
14
15
16
17
18
19
20
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/command/helper/responder.rb', line 12

def initialize(stream)
  @stream = stream
  @commandsdiscocbs = CallbackList.new
  @commandexeccbs = CallbackList.new

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

Instance Method Details

#add_commands_disco_callback(priority = 0, ref = nil, &block) ⇒ Object

Add a callback for <query> stanzas asking for the list of ad-hoc commands



25
26
27
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/command/helper/responder.rb', line 25

def add_commands_disco_callback(priority = 0, ref = nil, &block)
  @commandsdiscocbs.add(priority, ref, block)
end

#add_commands_exec_callback(priority = 0, ref = nil, &block) ⇒ Object

Add a callback for <command> stanzas asking for the execution of an ad-hoc command



32
33
34
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/command/helper/responder.rb', line 32

def add_commands_exec_callback(priority = 0, ref = nil, &block)
  @commandexeccbs.add(priority, ref, block)
end

#iq_callback(iq) ⇒ Object

Handles <iq> stanzas and execute callbacks



38
39
40
41
42
43
44
45
46
47
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/command/helper/responder.rb', line 38

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