require "tagen/xmpp4r" require "xmpp4r/client" require "drb" module Saber module AutoFetcher class Client class << self def start client = Client.new client.start p Thread.list Thread.list.each{|v| v.join} end end attr_reader :client, :fetcher def initialize @client = Jabber::Client.new(Jabber::JID.new(Rc.client.xmpp.jid)) @fetcher = Fetcher.new end def start client.connect Rc.client.xmpp.host, Rc.client.xmpp.port client.auth Rc.client.xmpp.password at_exit do pd Thread.current begin client.send Jabber::Presence.new.set_type(:unavaliable) rescue IOError # closed stream Saber.ui.error "closed stream (IOError)" end end client.add_message_callback { |msg| if msg.from.bare == Rc.server.xmpp.jid files = msg.body.split("\n") Saber.ui.debug "RECV #{files}" fetcher.add *files end pd "add done" } client.send Jabber::Iq.new_rosterget client.send Jabber::Presence.new.set_type(:avaliable) Saber.ui.say ">> Connected to xmpp with #{Rc.client.xmpp.jid}" end def stop @client.close! end end class DRbClient attr_reader :server def initialize DRb.start_service @server = DRbObject.new_with_uri(Rc.drb_uri) Saber.ui.say ">> DRbClient connected to #{Rc.drb_uri}" end def add(*names) Saber.ui.say "ADD #{names}" server.add(*names) end end end end