Class: RocketChat::Realtime::Client
- Inherits:
-
Object
- Object
- RocketChat::Realtime::Client
- Extended by:
- Forwardable
- Includes:
- EventEmitter, Methods::Auth, Methods::Message, Subscriptions::Room
- Defined in:
- lib/rocket_chat/realtime/client.rb
Overview
Rocket.Chat Reamtime API
Constant Summary collapse
- INITIALIZE_COMMAND =
{ msg: :connect, version: '1', support: ['1'] }.freeze
Instance Attribute Summary collapse
- #adapter ⇒ Object readonly
- #connector ⇒ Object readonly
- #dispatcher ⇒ Object readonly
- #driver ⇒ Object readonly
- #server ⇒ Object readonly
Instance Method Summary collapse
-
#add_to_reactor ⇒ Object
Add to reactor.
-
#connect ⇒ Object
Connect to server.
-
#disconnect ⇒ Object
Close connection to server.
-
#endpoint ⇒ String
The realtime api endpoint.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#opened? ⇒ Boolean
WebSocket is opened.
-
#process(monitor) ⇒ Object
Process I/O.
Methods included from Subscriptions::Room
Methods included from Methods::Message
Methods included from Methods::Auth
Methods included from EventEmitter
Constructor Details
Instance Attribute Details
#adapter ⇒ Object (readonly)
36 37 38 |
# File 'lib/rocket_chat/realtime/client.rb', line 36 def adapter @adapter end |
#connector ⇒ Object (readonly)
36 37 38 |
# File 'lib/rocket_chat/realtime/client.rb', line 36 def connector @connector end |
#dispatcher ⇒ Object (readonly)
36 37 38 |
# File 'lib/rocket_chat/realtime/client.rb', line 36 def dispatcher @dispatcher end |
#driver ⇒ Object (readonly)
36 37 38 |
# File 'lib/rocket_chat/realtime/client.rb', line 36 def driver @driver end |
#server ⇒ Object (readonly)
36 37 38 |
# File 'lib/rocket_chat/realtime/client.rb', line 36 def server @server end |
Instance Method Details
#add_to_reactor ⇒ Object
Add to reactor
56 57 58 59 60 61 62 63 |
# File 'lib/rocket_chat/realtime/client.rb', line 56 def add_to_reactor monitor = Reactor.register(self) return if monitor.nil? @adapter = Adapter.new(endpoint, monitor) @driver = WebSocket::Driver.client(adapter) @dispatcher = Dispatcher.new(self) end |
#connect ⇒ Object
Connect to server
68 69 70 71 72 |
# File 'lib/rocket_chat/realtime/client.rb', line 68 def connect add_to_reactor driver.start driver.text(INITIALIZE_COMMAND.to_json) end |
#disconnect ⇒ Object
Close connection to server
77 78 79 80 81 82 |
# File 'lib/rocket_chat/realtime/client.rb', line 77 def disconnect @adapter.dispose @dispatcher.dispose driver.close Reactor.deregister(self) end |
#endpoint ⇒ String
Returns the realtime api endpoint.
49 50 51 |
# File 'lib/rocket_chat/realtime/client.rb', line 49 def endpoint "#{server}/websocket" end |
#opened? ⇒ Boolean
WebSocket is opened
89 90 91 |
# File 'lib/rocket_chat/realtime/client.rb', line 89 def opened? driver.state == :open end |
#process(monitor) ⇒ Object
Process I/O
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rocket_chat/realtime/client.rb', line 98 def process(monitor) monitor.interests = adapter.pending? ? :rw : :r driver.parse(monitor.io.read_nonblock(2**14)) if monitor.readable? adapter.pump_buffer if monitor.writeable? rescue IO::WaitReadable, IO::WaitWritable # nope rescue Errno::ECONNRESET, EOFError, Errno::ECONNABORTED RocketChat::Realtime.logger.warn('Remote server is closed.') monitor.close disconnect end |