Class: Jabber::Discovery::Responder

Class | Jabber::Discovery::Responder
In: | lib/xmpp4r/discovery/helper/responder.rb
Parent: | Object

Responds to Service Discovery queries on a given node

Modify returned elements by these attributes:

- Responder#identities
- Responder#features (Responder#add_features is a short-cut accepting an Array of Strings, too)
- Responder#forms
- Responder#items

### Methods

add_feature add_features generate_caps generate_item new

### Constants

CALLBACK_PRIORITY | = | 180

### Attributes

features | [RW] | Features returned on Discovery Info query, Array of [Discovery::Feature]
forms | [RW] | Forms returned on Discovery Info query (such as Software Information) Array of [Dataforms::XData]
identities | [RW] | Identities returned on Discovery Info query Array of [Discovery::Identity]
items | [RW] | Children returned on Discovery Item query May contain other Discovery::Responder instances which will generate an item dynamically from their first identity Array of [Discovery::Item] or [Discovery::Responder] (mixed)
my_jid | [RW] | Set the JID this helper feels responsible for (default: nil, responsible for any JID)
node | [R] | Service Discovery node this Responder is responsible for (will not answer queries for other nodes)

### Public Class methods

new(stream, node=nil, identities=[], features=[], items=[])

Initialize responder for a specific node

stream: | [Jabber::Stream]
node: | [nil] or [String]

[Source]

         # File lib/xmpp4r/discovery/helper/responder.rb, line 64
     64:       def initialize(stream, node=nil, identities=[], features=[], items=[])
     65:         @stream = stream
     66:         @my_jid = nil
     67:         @node = node
     68:         @identities = identities
     69:         @features = []
     70:         add_features(features)
     71:         @forms = []
     72:         @items = items
     73:
     74:         @stream.add_iq_callback(CALLBACK_PRIORITY, self) do |iq|
     75:           my_nodes = [@node, "#{@node}##{generate_ver}"]
     76:
     77:           if iq.type == :get and
     78:              iq.query.kind_of? IqQueryDiscoInfo and
     79:              my_nodes.include?(iq.query.node)
     80:
     81:             answer = iq.answer(false)
     82:             answer.type = :result
     83:             query = answer.add(IqQueryDiscoInfo.new)
     84:             query.node = iq.query.node
     85:             (@identities + @features + @forms).each do |element|
     86:               query.add(element)
     87:             end
     88:             @stream.send(answer)
     89:
     90:             true  # handled
     91:
     92:           elsif iq.type == :get and
     93:                 iq.query.kind_of? IqQueryDiscoItems and
     94:                 my_nodes.include?(iq.query.node)
     95:
     96:             answer = iq.answer(false)
     97:             answer.type = :result
     98:             query = answer.add(IqQueryDiscoItems.new)
     99:             query.node = iq.query.node
    100:             @items.each do |item|
    101:               if item.kind_of? Responder
    102:                 query.add(item.generate_item)
    103:               else
    104:                 query.add(item)
    105:               end
    106:             end
    107:             @stream.send(answer)
    108:
    109:             true  # handled
    110:
    111:           else
    112:             false # not handled
    113:           end
    114:         end
    115:       end

### Public Instance methods

add_feature(feature)

Add a feature

feature: | [Jabber::Discovery::Feature] or [String]

[Source]

         # File lib/xmpp4r/discovery/helper/responder.rb, line 120
    120:       def add_feature(feature)
    121:         if feature.kind_of? Feature
    122:           @features << feature
    123:         else
    124:           @features << Feature.new(feature.to_s)
    125:         end
    126:       end

add_features(features)

Add a series of features

features: | Array of [Jabber::Discovery::Feature] or [String]

[Source]

         # File lib/xmpp4r/discovery/helper/responder.rb, line 131
    131:       def add_features(features)
    132:         features.each { |feature|
    133:           add_feature(feature)
    134:         }
    135:       end

generate_caps()

Generate a XEP-0115: Entity Capabilities <c/> element for inclusion in Presence stanzas. This enables efficient caching of Service Discovery information.

[Source]

         # File lib/xmpp4r/discovery/helper/responder.rb, line 141
    141:       def generate_caps
    142:         Caps::C.new(@node, generate_ver)
    143:       end

generate_item()

Generate an item for inclusion in items discovery in other responders

return: | [Discovery::Item] or nil

[Source]

         # File lib/xmpp4r/discovery/helper/responder.rb, line 149
    149:       def generate_item
    150:         i = @identities.first
    151:         if i
    152:           Item.new(@my_jid || @stream.jid, i.iname, @node)
    153:         else
    154:           nil
    155:         end
    156:       end

[Validate]