Class Jabber::Caps::Helper
In: lib/xmpp4r/caps/helper/helper.rb
Parent: Object

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')]

)

Methods

c   handle_discoinfo_query   new   ver  

Attributes

features  [RW] 
identities  [RW] 
node  [RW] 

Public Class methods

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

[Source]

    # File lib/xmpp4r/caps/helper/helper.rb, line 35
35:       def initialize(client,i=[],f=[],n="http://home.gna.org/xmpp4r/##{Jabber::XMPP4R_VERSION}")
36:         @stream = client
37:         @identities = i
38:         @features = f
39:         @node = n
40: 
41:         @stream.add_iq_callback(250) do |iq|
42:           if iq.type == :get and iq.query.kind_of? Jabber::Discovery::IqQueryDiscoInfo
43:             Thread.new do
44:               Thread.abort_on_exception = true
45:               handle_discoinfo_query(iq)
46:             end
47:             true
48:           else
49:             false
50:           end
51:         end
52: 
53:         p = Jabber::Presence.new()
54:         p.add(c)
55:         @stream.send(p)
56:       end

Public Instance methods

Return a <c/> element for inclusion in your own <presence> stanzas.

[Source]

    # File lib/xmpp4r/caps/helper/helper.rb, line 61
61:       def c
62:         Jabber::Caps::C.new(node, ver)
63:       end

Send actual identities/ features back to a requesting entity

[Source]

    # File lib/xmpp4r/caps/helper/helper.rb, line 67
67:       def handle_discoinfo_query(iq)
68:         caps_reply = Jabber::XMPPStanza.answer(iq)
69:         caps_reply.type = :result
70:         caps_reply.query = Jabber::Discovery::IqQueryDiscoInfo.new
71:         @identities.each { |i| caps_reply.query.add(i) }
72:         @features.each { |f| caps_reply.query.add(f) }
73: 
74:         @stream.send(caps_reply)
75:       end

Generate ‘ver’, an opaque hash used to represent this entity‘s capabilities

See www.xmpp.org/extensions/xep-0115.html#ver

[Source]

    # File lib/xmpp4r/caps/helper/helper.rb, line 82
82:       def ver
83:         Caps::generate_ver(@identities, @features)
84:       end

[Validate]