Class: Jabber::Caps::Helper
- Inherits:
-
Object
- Object
- Jabber::Caps::Helper
- Defined in:
- lib/vendor/xmpp4r/lib/xmpp4r/caps/helper/helper.rb
Overview
A Helper to manage advertising and discovery of entity capabilities.
Following XEP-0115 (ver 1.4 www.xmpp.org/extensions/xep-0115.html). you can use this Helper to, for example, advertise that your client wishes to receive XEP-0118 User Tune notifications, eg:
caps_helper=Jabber::Caps::Helper(cl,
[Jabber::Discovery::Identity.new('client',nil,'bot')],
[Jabber::Discovery::Feature.new('http://jabber.org/protocol/tune+notify')]
)
Instance Attribute Summary collapse
-
#features ⇒ Object
Returns the value of attribute features.
-
#identities ⇒ Object
Returns the value of attribute identities.
-
#node ⇒ Object
Returns the value of attribute node.
Instance Method Summary collapse
-
#c ⇒ Object
Return a <c/> element for inclusion in your own <presence> stanzas.
-
#handle_discoinfo_query(iq) ⇒ Object
Send actual identities/ features back to a requesting entity.
-
#initialize(client, i = [], f = [], n = "http://home.gna.org/xmpp4r/##{Jabber::XMPP4R_VERSION}") ⇒ Helper
constructor
Construct a new Caps Helper.
-
#ver ⇒ Object
Generate ‘ver’, an opaque hash used to represent this entity’s capabilities.
Constructor Details
#initialize(client, i = [], f = [], n = "http://home.gna.org/xmpp4r/##{Jabber::XMPP4R_VERSION}") ⇒ Helper
Construct a new Caps Helper.
This will send a <presence> message containing a <c/> (Jabber::Caps::C) stanza to your server.
- client
- Jabber::Stream
- i
- Array
-
of [Jabber::Discovery::Identity] objects that this entity will advertise
- f
- Array
-
of [Jabber::Discovery::Feature] objects that this entity will advertise
- n
- String
-
an identifier representing the software underlying this entity
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/caps/helper/helper.rb', line 35 def initialize(client,i=[],f=[],n="http://home.gna.org/xmpp4r/##{Jabber::XMPP4R_VERSION}") @stream = client @identities = i @features = f @node = n @stream.add_iq_callback(250) do |iq| if iq.type == :get and iq.query.kind_of? Jabber::Discovery::IqQueryDiscoInfo Thread.new do Thread.abort_on_exception = true handle_discoinfo_query(iq) end true else false end end p = Jabber::Presence.new() p.add(c) @stream.send(p) end |
Instance Attribute Details
#features ⇒ Object
Returns the value of attribute features.
24 25 26 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/caps/helper/helper.rb', line 24 def features @features end |
#identities ⇒ Object
Returns the value of attribute identities.
24 25 26 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/caps/helper/helper.rb', line 24 def identities @identities end |
#node ⇒ Object
Returns the value of attribute node.
24 25 26 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/caps/helper/helper.rb', line 24 def node @node end |
Instance Method Details
#c ⇒ Object
Return a <c/> element for inclusion in your own <presence> stanzas.
61 62 63 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/caps/helper/helper.rb', line 61 def c Jabber::Caps::C.new(node, ver) end |
#handle_discoinfo_query(iq) ⇒ Object
Send actual identities/ features back to a requesting entity
67 68 69 70 71 72 73 74 75 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/caps/helper/helper.rb', line 67 def handle_discoinfo_query(iq) caps_reply = Jabber::XMPPStanza.answer(iq) caps_reply.type = :result caps_reply.query = Jabber::Discovery::IqQueryDiscoInfo.new @identities.each { |i| caps_reply.query.add(i) } @features.each { |f| caps_reply.query.add(f) } @stream.send(caps_reply) end |
#ver ⇒ Object
Generate ‘ver’, an opaque hash used to represent this entity’s capabilities
82 83 84 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/caps/helper/helper.rb', line 82 def ver Caps::generate_ver(@identities, @features) end |