Class: Saber::AutoFetcher::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/saber/autofetcher/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



21
22
23
24
# File 'lib/saber/autofetcher/client.rb', line 21

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



19
20
21
# File 'lib/saber/autofetcher/client.rb', line 19

def client
  @client
end

#fetcherObject (readonly)

Returns the value of attribute fetcher.



19
20
21
# File 'lib/saber/autofetcher/client.rb', line 19

def fetcher
  @fetcher
end

Class Method Details

.startObject



9
10
11
12
13
14
15
16
# File 'lib/saber/autofetcher/client.rb', line 9

def start
  client = Client.new

  client.start
  p Thread.list

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

Instance Method Details

#startObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/saber/autofetcher/client.rb', line 26

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

#stopObject



53
54
55
# File 'lib/saber/autofetcher/client.rb', line 53

def stop
  @client.close!
end