Sha256: 529534d3769c5f5fcb1540d1bcff74c7430a5c58dcd5940f9b1e4d460216376b

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 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
          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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
saber-1.0.2 lib/saber/autofetcher/client.rb