Sha256: 99ec1049483a06e672850beb5834b19736176ad92ca300ca74fdcbcf990de4af

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require "xmpp4r/client"
require "drb"

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

        Thread.list.each {|v| v.join}
      end
    end

    attr_reader :client, :downloader

    def initialize
      @client = Jabber::Client.new(Jabber::JID.new(Rc.client.xmpp.jid))
      @downloader = Downloader.new
    end

    def start
      client.connect Rc.client.xmpp.host, Rc.client.xmpp.port 
      client.auth Rc.client.xmpp.password

      client.add_message_callback { |msg|
        pd msg.from.bare
        if msg.from.bare == Rc.server.xmpp.jid
          files = msg.body.split("\n")
          $log.debug "::recv::\n #{files.join("\n")}"
          downloader.add *files
        end
      }

      client.send Jabber::Presence.new
      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::\n#{names.join("\n")}"
      server.add(*names)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
saber-0.0.6 lib/saber/client.rb