Sha256: d5bd2cb843f37469f97c22b253cdfd3466d6e9cc72c156d9ad4701029829d54e

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require "tagen/xmpp4r"
require "xmpp4r/client"
require "drb"

module Saber
  module AutoFetcher
    class Client
      class << self
        def start
          client = Client.new

          client.start

          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
          client.send Jabber::Presence.new.set_type(:unavaliable)
        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
        }

        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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
saber-1.0.1 lib/saber/autofetcher/client.rb
saber-1.0.0 lib/saber/autofetcher/client.rb