Class: Ably::Realtime::Connection::WebsocketTransport Private
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Ably::Realtime::Connection::WebsocketTransport
- Extended by:
- Modules::Enum
- Includes:
- Modules::EventEmitter, Modules::StateEmitter
- Defined in:
- lib/ably/realtime/connection/websocket_transport.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
EventMachine WebSocket transport
Constant Summary collapse
- STATE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Valid WebSocket connection states
ruby_enum('STATE', :initialized, :connecting, :connected, :disconnecting, :disconnected )
Instance Attribute Summary collapse
-
#__incoming_protocol_msgbus__ ⇒ Ably::Util::PubSub
readonly
private
Websocket Transport internal incoming protocol message bus.
-
#__outgoing_protocol_msgbus__ ⇒ Ably::Util::PubSub
readonly
private
Websocket Transport internal outgoing protocol message bus.
Instance Method Summary collapse
-
#connection_completed ⇒ Object
private
Remote TCP connection attempt completes successfully Required EventMachine::Connection interface.
-
#disconnect ⇒ void
Disconnect the socket transport connection and write all pending text.
-
#initialize(connection, url) ⇒ WebsocketTransport
constructor
private
A new instance of WebsocketTransport.
-
#post_init ⇒ Object
private
Network connection has been established Required EventMachine::Connection interface.
-
#ready_for_release? ⇒ Boolean
private
True if socket connection is ready to be released i.e.
-
#receive_data(data) ⇒ Object
private
Called by the event loop whenever data has been received by the network connection.
-
#unbind ⇒ Object
private
Called whenever a connection (either a server or client connection) is closed Required EventMachine::Connection interface.
-
#url ⇒ Object
private
URL end point including initialization configuration WebSocket::Driver interface.
-
#write(data) ⇒ Object
private
WebSocket::Driver interface.
Methods included from Modules::StateEmitter
#once_or_if, #once_state_changed, #state, #state=, #state?, #unsafe_once_or_if, #unsafe_once_state_changed
Methods included from Modules::EventEmitter
#emit, #off, #on, #once, #unsafe_on, #unsafe_once
Constructor Details
#initialize(connection, url) ⇒ WebsocketTransport
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of WebsocketTransport.
19 20 21 22 23 24 25 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 19 def initialize(connection, url) @connection = connection @state = STATE.Initialized @url = url setup_event_handlers end |
Instance Attribute Details
#__incoming_protocol_msgbus__ ⇒ Ably::Util::PubSub (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Websocket Transport internal incoming protocol message bus.
89 90 91 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 89 def __incoming_protocol_msgbus__ @__incoming_protocol_msgbus__ ||= end |
#__outgoing_protocol_msgbus__ ⇒ Ably::Util::PubSub (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Websocket Transport internal outgoing protocol message bus.
96 97 98 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 96 def __outgoing_protocol_msgbus__ @__outgoing_protocol_msgbus__ ||= end |
Instance Method Details
#connection_completed ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remote TCP connection attempt completes successfully Required EventMachine::Connection interface
50 51 52 53 54 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 50 def connection_completed change_state STATE.Connected start_tls if client.use_tls? driver.start end |
#disconnect ⇒ void
This method returns an undefined value.
Disconnect the socket transport connection and write all pending text. If Disconnected state is not automatically emitted, it will be emitted automatically
31 32 33 34 35 36 37 38 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 31 def disconnect close_connection_after_writing change_state STATE.Disconnecting create_timer(2) do # if connection is not disconnected within 2s, set state as disconnected change_state STATE.Disconnected unless disconnected? end end |
#post_init ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Network connection has been established Required EventMachine::Connection interface
42 43 44 45 46 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 42 def post_init clear_timer change_state STATE.Connecting setup_driver end |
#ready_for_release? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
True if socket connection is ready to be released i.e. it is not currently connecting or connected
82 83 84 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 82 def ready_for_release? !connecting? && !connected? end |
#receive_data(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Called by the event loop whenever data has been received by the network connection. Simply pass onto the WebSocket driver to process and determine content boundaries. Required EventMachine::Connection interface
59 60 61 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 59 def receive_data(data) driver.parse(data) end |
#unbind ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Called whenever a connection (either a server or client connection) is closed Required EventMachine::Connection interface
65 66 67 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 65 def unbind change_state STATE.Disconnected, reason_closed || 'Websocket connection closed unexpectedly' end |
#url ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
URL end point including initialization configuration WebSocket::Driver interface
71 72 73 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 71 def url @url end |
#write(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
WebSocket::Driver interface
76 77 78 |
# File 'lib/ably/realtime/connection/websocket_transport.rb', line 76 def write(data) send_data(data) end |