support for multiple rooms.

This commit is contained in:
alcy 2011-08-08 15:55:03 +05:30 committed by Jordan Sissel
parent b3024c9367
commit 98d54b4d2f

View file

@ -12,33 +12,35 @@ class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
config :pass, :validate => :string, :required => :true
# if muc/multi-user-chat required, pass the name of the room: room@conference.domain/nick
config :room, :validate => :string
config :rooms, :validate => :array
public
def register
require 'xmpp4r'
require 'xmpp4r' # xmpp4r gem
@cl = Jabber::Client.new(Jabber::JID.new("#{@jid}"))
@cl.connect
@cl.auth("#{@pass}")
@cl.send(Jabber::Presence.new.set_type(:available))
if @room
require 'xmpp4r/muc/helper/simplemucclient'
@muc = Jabber::MUC::SimpleMUCClient.new(@cl)
@muc.join("#{@room}")
if @rooms
require 'xmpp4r/muc/helper/simplemucclient' # xmpp4r muc helper
end
end # def register
def run(queue)
if @room
@muc.on_message { |time,from,body|
e = to_event(body, from)
if e
queue << e
end
}
end
if @rooms
@rooms.each do |room| # handle muc messages in different rooms
@muc = Jabber::MUC::SimpleMUCClient.new(@cl)
@muc.join("#{room}")
@muc.on_message { |time,from,body|
e = to_event(body, "#{room}/#{from}")
if e
queue << e
end
}
end
end
@cl.add_message_callback { |msg|
@cl.add_message_callback { |msg| # handle direct/private messages
e = to_event(msg.body, msg.from) unless msg.body == nil # to avoid msgs from presence updates etc.
if e
queue << e