Skip to content

Instantly share code, notes, and snippets.

@stuffmc
Created March 23, 2010 13:00
Show Gist options
  • Save stuffmc/341137 to your computer and use it in GitHub Desktop.
Save stuffmc/341137 to your computer and use it in GitHub Desktop.
class XMPPD
def initialize(username, password)
begin
@mainthread = Thread.current
login(username, password)
listen_for_presence_notifications
send_initial_presence
rescue Exception => e
puts "*** ERROR (initialize): #{e}"
end
end
def login(username, password)
begin
@jid = Jabber::JID.new(username)
@client = Jabber::Client.new(@jid)
@client.connect
@client.auth(password)
rescue Exception => e
puts "*** ERROR (login): #{e}"
end
end
def send_initial_presence
@client.send(Jabber::Presence.new.set_status("XMPP4R at #{Time.now.utc}"))
end
def listen_for_presence_notifications
@client.add_presence_callback do |m|
case m.type
when nil # status: available
puts "PRESENCE: #{m.from} is online"
msg = Jabber::Message.new(m.from, "Welcome!")
msg.type = :chat
@client.send(msg)
when :unavailable
puts "PRESENCE: #{m.from} is offline"
end
end
end
end
DRb.start_service("druby://localhost:7777", XMPPD.new("user@server.com", "secret"))
DRb.thread.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment