Class: Rubyfox::Client::Transport
- Inherits:
-
Object
- Object
- Rubyfox::Client::Transport
- Defined in:
- lib/rubyfox/client/transport.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #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(request, *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 |
# File 'lib/rubyfox/client/transport.rb', line 21 def connect @event_handler.register @extension_handler.register @smartfox.connect(@config.host, @config.port) end |
#disconnect ⇒ Object
27 28 29 30 31 |
# File 'lib/rubyfox/client/transport.rb', line 27 def disconnect @smartfox.disconnect @extension_handler.unregister @event_handler.unregister end |
#exit(ret = 0) ⇒ Object
33 34 35 36 |
# File 'lib/rubyfox/client/transport.rb', line 33 def exit(ret=0) disconnect Java::System.exit(ret) end |
#on_event(*names, &block) ⇒ Object
55 56 57 |
# File 'lib/rubyfox/client/transport.rb', line 55 def on_event(*names, &block) @event_handler.add(*names, &block) end |
#on_extension(*commands, &block) ⇒ Object
47 48 49 |
# File 'lib/rubyfox/client/transport.rb', line 47 def on_extension(*commands, &block) @extension_handler.add(*commands, &block) end |
#remove_event(*names) ⇒ Object
59 60 61 |
# File 'lib/rubyfox/client/transport.rb', line 59 def remove_event(*names) @event_handler.remove(*names) end |
#remove_extension(*commands) ⇒ Object
51 52 53 |
# File 'lib/rubyfox/client/transport.rb', line 51 def remove_extension(*commands) @extension.remove(*commands) end |
#send(request, *args) ⇒ Object
38 39 40 41 |
# File 'lib/rubyfox/client/transport.rb', line 38 def send(request, *args) request = Requests[request, *args] @smartfox.send(request) end |
#send_extension(command, params = nil, room = nil) ⇒ Object
43 44 45 |
# File 'lib/rubyfox/client/transport.rb', line 43 def send_extension(command, params=nil, room=nil) send :extension, command.to_s, params, room end |