Class: OMQ::Transport::WebSocket::Dialer

Inherits:
Object
  • Object
show all
Defined in:
lib/omq/transport/websocket/transport.rb

Overview

Outgoing connection factory. Stateful so reconnect can call #connect again without redoing endpoint parsing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, engine) ⇒ Dialer

Returns a new instance of Dialer.



119
120
121
122
# File 'lib/omq/transport/websocket/transport.rb', line 119

def initialize(endpoint, engine)
  @endpoint = endpoint
  @engine   = engine
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



116
117
118
# File 'lib/omq/transport/websocket/transport.rb', line 116

def endpoint
  @endpoint
end

Instance Method Details

#connectvoid

This method returns an undefined value.

Establishes the WebSocket upgrade and hands the resulting Async::WebSocket::Connection to the engine. The engine builds the OMQ::Transport::WebSocket::Connection on top via the transport's connection_class hook and runs the ZWS handshake.



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/omq/transport/websocket/transport.rb', line 133

def connect
  tls           = @engine.options.tls_context
  subprotocols  = @engine.options.ws_subprotocols
  http_endpoint = WebSocket.parse_http_endpoint(@endpoint, tls)
  ws_conn       = ::Async::WebSocket::Client.connect(
    http_endpoint,
    protocols: subprotocols,
  )

  @engine.handle_connected(ws_conn, endpoint: @endpoint)
end