Class: Rubyfox::Client::Transport
- Inherits:
-
Object
- Object
- Rubyfox::Client::Transport
- Defined in:
- lib/rubyfox/client/transport.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
- #exit(ret = 0) ⇒ Object
- #init_crypto ⇒ Object
-
#initialize(config) ⇒ Transport
constructor
A new instance of Transport.
- #on_event(*names, &block) ⇒ Object
- #on_extension(*commands, &block) ⇒ Object
- #remove_event(*names) ⇒ Object
- #remove_extension(*commands) ⇒ Object
- #send(command, *args) ⇒ Object
- #send_extension(command, params = nil, room = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ Transport
Returns a new instance of Transport.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rubyfox/client/transport.rb', line 10 def initialize(config) @config = config @smartfox = Java::SmartFox.new(@config.debug?) @event_handler = EventHandler.new(@smartfox) @extension_handler = ExtensionHandler.new(@event_handler) if block_given? yield self connect end end |
Instance Method Details
#connect ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubyfox/client/transport.rb', line 21 def connect @event_handler.register @extension_handler.register config_data = Java::ConfigData.new config_data.host = @config.host config_data.port = @config.port config_data.http_port = @config.http_port config_data.https_port = @config.https_port config_data.zone = @config.zone @smartfox.connect(config_data) sleep 0.1 end |
#connected? ⇒ Boolean
36 37 38 |
# File 'lib/rubyfox/client/transport.rb', line 36 def connected? @smartfox.connected? end |
#disconnect ⇒ Object
40 41 42 43 44 |
# File 'lib/rubyfox/client/transport.rb', line 40 def disconnect @smartfox.disconnect @extension_handler.unregister @event_handler.unregister end |
#exit(ret = 0) ⇒ Object
46 47 48 49 |
# File 'lib/rubyfox/client/transport.rb', line 46 def exit(ret = 0) disconnect Java::System.exit(ret) end |
#init_crypto ⇒ Object
76 77 78 |
# File 'lib/rubyfox/client/transport.rb', line 76 def init_crypto @smartfox.init_crypto end |
#on_event(*names, &block) ⇒ Object
68 69 70 |
# File 'lib/rubyfox/client/transport.rb', line 68 def on_event(*names, &block) @event_handler.add(*names, &block) end |
#on_extension(*commands, &block) ⇒ Object
60 61 62 |
# File 'lib/rubyfox/client/transport.rb', line 60 def on_extension(*commands, &block) @extension_handler.add(*commands, &block) end |
#remove_event(*names) ⇒ Object
72 73 74 |
# File 'lib/rubyfox/client/transport.rb', line 72 def remove_event(*names) @event_handler.remove(*names) end |
#remove_extension(*commands) ⇒ Object
64 65 66 |
# File 'lib/rubyfox/client/transport.rb', line 64 def remove_extension(*commands) @extension.remove(*commands) end |
#send(command, *args) ⇒ Object
51 52 53 54 |
# File 'lib/rubyfox/client/transport.rb', line 51 def send(command, *args) request = Request[command].new(*args) @smartfox.send(request) end |
#send_extension(command, params = nil, room = nil) ⇒ Object
56 57 58 |
# File 'lib/rubyfox/client/transport.rb', line 56 def send_extension(command, params = nil, room = nil) send :extension, command.to_s, params, room end |