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
-
#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 |
# File 'lib/rubyfox/client/transport.rb', line 21 def connect @event_handler.register @extension_handler.register @smartfox.connect(@config.host, @config.port) sleep 0.1 end |
#connected? ⇒ Boolean
28 29 30 |
# File 'lib/rubyfox/client/transport.rb', line 28 def connected? @smartfox.connected? end |
#disconnect ⇒ Object
32 33 34 35 36 |
# File 'lib/rubyfox/client/transport.rb', line 32 def disconnect @smartfox.disconnect @extension_handler.unregister @event_handler.unregister end |
#exit(ret = 0) ⇒ Object
38 39 40 41 |
# File 'lib/rubyfox/client/transport.rb', line 38 def exit(ret = 0) disconnect Java::System.exit(ret) end |
#on_event(*names, &block) ⇒ Object
60 61 62 |
# File 'lib/rubyfox/client/transport.rb', line 60 def on_event(*names, &block) @event_handler.add(*names, &block) end |
#on_extension(*commands, &block) ⇒ Object
52 53 54 |
# File 'lib/rubyfox/client/transport.rb', line 52 def on_extension(*commands, &block) @extension_handler.add(*commands, &block) end |
#remove_event(*names) ⇒ Object
64 65 66 |
# File 'lib/rubyfox/client/transport.rb', line 64 def remove_event(*names) @event_handler.remove(*names) end |
#remove_extension(*commands) ⇒ Object
56 57 58 |
# File 'lib/rubyfox/client/transport.rb', line 56 def remove_extension(*commands) @extension.remove(*commands) end |
#send(command, *args) ⇒ Object
43 44 45 46 |
# File 'lib/rubyfox/client/transport.rb', line 43 def send(command, *args) request = Request[command].new(*args) @smartfox.send(request) end |
#send_extension(command, params = nil, room = nil) ⇒ Object
48 49 50 |
# File 'lib/rubyfox/client/transport.rb', line 48 def send_extension(command, params = nil, room = nil) send :extension, command.to_s, params, room end |