Class: Fargo::Client
- Inherits:
-
Object
- Object
- Fargo::Client
- Includes:
- ActiveSupport::Callbacks, ActiveSupport::Configurable, Supports::Chat, Supports::Downloads, Supports::LocalFileList, Supports::NickList, Supports::Persistence, Supports::RemoteFileList, Supports::Searches, Supports::Timeout, Supports::Uploads
- Defined in:
- lib/fargo/client.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#hub ⇒ Object
readonly
Returns the value of attribute hub.
Attributes included from Supports::LocalFileList
#local_file_list, #shared_directories
Attributes included from Supports::Downloads
#current_downloads, #failed_downloads, #finished_downloads, #queued_downloads, #timed_out, #trying
Attributes included from Supports::NickList
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #description ⇒ Object
- #disconnect ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #start_websocket_service ⇒ Object
Methods included from Supports::LocalFileList
#listing_for, #local_file_list_path, #local_listings, #search_local_listings, #share_directory, #share_size
Methods included from Supports::RemoteFileList
Methods included from Supports::Timeout
Methods included from Supports::Persistence
#connect_with, #connected_with?, #connection_for, #disconnect_from, #nicks_connected_with
Methods included from Supports::Downloads
#clear_failed_downloads, #clear_finished_downloads, #download, #has_download_slot?, #lock_next_download!, #open_download_slots, #remove_download, #retry_download, #try_again
Methods included from Supports::Searches
#remove_search, #search, #search_hub, #search_objects, #search_results, #searches
Methods included from Supports::NickList
#get_info, #get_ip, #info, #nick_has_slot?
Methods included from Supports::Uploads
#open_upload_slots, #release_slot!, #take_slot!
Methods included from Supports::Chat
#messages, #messages_with, #send_chat
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fargo/client.rb', line 50 def initialize run_callbacks :initialization do @channel = EventMachine::Channel.new @connection_timeouts = {} @channel.subscribe do |type, hash| Fargo.logger.debug "Channel received: #{type} - #{hash.inspect}" end config_file = config.config_dir + '/config' if File.exists? config_file eval File.read(config_file) end end end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
48 49 50 |
# File 'lib/fargo/client.rb', line 48 def channel @channel end |
#hub ⇒ Object (readonly)
Returns the value of attribute hub.
48 49 50 |
# File 'lib/fargo/client.rb', line 48 def hub @hub end |
Instance Method Details
#connect ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fargo/client.rb', line 66 def connect run_callbacks :connect do EventMachine.connect config.hub_address, config.hub_port, Protocol::Hub do |conn| @hub = conn @hub.client = self end unless config.passive EventMachine.start_server '0.0.0.0', config.active_port, Protocol::Peer do |conn| conn.client = self end EventMachine.open_datagram_socket '0.0.0.0', config.search_port, Protocol::DC do |conn| conn.client = self end end end start_websocket_service end |
#connected? ⇒ Boolean
107 108 109 |
# File 'lib/fargo/client.rb', line 107 def connected? EventMachine.reactor_running? && !hub.error? end |
#description ⇒ Object
116 117 118 |
# File 'lib/fargo/client.rb', line 116 def description "<fargo V:#{VERSION},M:#{config.passive ? 'P' : 'A'},H:1/0/0,S:#{open_upload_slots},Dt:1.2.6/W>" end |
#disconnect ⇒ Object
111 112 113 114 |
# File 'lib/fargo/client.rb', line 111 def disconnect Fargo.logger.info 'Disconnecting from hub.' EventMachine.stop_event_loop end |
#start_websocket_service ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fargo/client.rb', line 90 def start_websocket_service EventMachine.start_server(config.websocket_host, config.websocket_port, EventMachine::WebSocket::Connection, {}) do |ws| ws.onopen { Fargo.logger.debug('ws connected') sid = channel.subscribe do |type, hash| if type != :download_opened ws.send Base64.encode64(Marshal.dump([type, hash])) end end ws.onclose{ channel.unsubscribe sid } } end end |