Class: Qswarm::Connections::Xmpp
- Inherits:
-
Qswarm::Connection
- Object
- Qswarm::Connection
- Qswarm::Connections::Xmpp
- Includes:
- DSL
- Defined in:
- lib/qswarm/connections/xmpp.rb
Instance Attribute Summary
Attributes inherited from Qswarm::Connection
Instance Method Summary collapse
-
#initialize(agent, name, args, &block) ⇒ Xmpp
constructor
A new instance of Xmpp.
- #run ⇒ Object
- #sink(args, payload) ⇒ Object
Methods included from DSL
#dsl_call, #dsl_load, included
Methods inherited from Qswarm::Connection
Constructor Details
#initialize(agent, name, args, &block) ⇒ Xmpp
Returns a new instance of Xmpp.
19 20 21 22 23 24 25 26 27 |
# File 'lib/qswarm/connections/xmpp.rb', line 19 def initialize(agent, name, args, &block) @channels = [] @connected = false @connection = nil @real_name = args[:real_name] || 'Bot' # Use the block for Blather bot DSL super end |
Instance Method Details
#run ⇒ Object
44 45 46 |
# File 'lib/qswarm/connections/xmpp.rb', line 44 def run xmpp_connect @args[:jid], @args[:password], @args[:channel] end |
#sink(args, payload) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/qswarm/connections/xmpp.rb', line 29 def sink(args, payload) if @connected # Use channel jid argument from write or from connection itself channel = args.nil? || args[:channel].nil? ? @args[:channel] : args[:channel] join channel; [*channel].each do |c| Qswarm.logger.info "[#{@agent.name.inspect} #{@name.inspect}] Sinking #{payload.raw.inspect} to XMPP channel #{c.inspect}" @connection.say c, payload.raw, :groupchat end else EventMachine::Timer.new(5,self.sink(args, payload)) end end |