| Class | Jabber::Version::Responder |
| In: |
lib/xmpp4r/version/helper/responder.rb
|
| Parent: | Object |
A class to answer version requests using IqQueryVersion
If you don‘t need the flexibility of dynamic responses with the callback you can register with add_version_callback, take a look at SimpleResponder
Initialize a new version responder
Registers it‘s callback (prio = 180, ref = self)
| stream: | [Stream] Where to register callback handlers |
# File lib/xmpp4r/version/helper/responder.rb, line 22
22: def initialize(stream)
23: @stream = stream
24: @versioncbs = CallbackList.new
25:
26: stream.add_iq_callback(180, self) { |iq|
27: iq_callback(iq)
28: }
29: end
Add a callback for Iq stanzas with IqQueryVersion
First argument passed to block is the Iq stanza, second argument is a block, which can be called with software name, version and os
Example:
my_version_helper.add_version_callback { |iq,block|
block.call('Cool client', '6.0', 'Cool OS')
}
# File lib/xmpp4r/version/helper/responder.rb, line 42
42: def add_version_callback(priority = 0, ref = nil, &block)
43: @versioncbs.add(priority, ref, block)
44: end
<iq/> callback handler to answer Software Version queries (registered by constructor and used internally only)
Used internally
# File lib/xmpp4r/version/helper/responder.rb, line 51
51: def iq_callback(iq)
52: if iq.type == :get
53: if iq.query.kind_of?(IqQueryVersion)
54: replyblock = lambda { |name,version,os|
55: answer = iq.answer
56: answer.type = :result
57: answer.query.set_iname(name).set_version(version).set_os(os)
58:
59: @stream.send(answer)
60: true
61: }
62: @versioncbs.process(iq, replyblock)
63: else
64: false
65: end
66: else
67: false
68: end
69: end