class Faye::WebSocket::Client
Constants
- DEFAULT_PORTS
- SECURE_PROTOCOLS
Public Class Methods
Source
# File lib/faye/websocket/client.rb, line 15 def initialize(url, protocols = nil, options = {}) @url = url super(options) { ::WebSocket::Driver.client(self, :max_length => options[:max_length], :protocols => protocols, :binary_data_format => options[:binary_data_format] ) } proxy = options.fetch(:proxy, {}) @endpoint = URI.parse(proxy[:origin] || @url) port = @endpoint.port || DEFAULT_PORTS[@endpoint.scheme] @origin_tls = options.fetch(:tls, {}) @socket_tls = proxy[:origin] ? proxy.fetch(:tls, {}) : @origin_tls configure_proxy(proxy) EventMachine.connect(@endpoint.host, port, Connection) do |conn| conn.parent = self end rescue => error on_network_error(error) end
Calls superclass method
Faye::WebSocket::API::new
Private Instance Methods
Source
# File lib/faye/websocket/client.rb, line 42 def configure_proxy(proxy) return unless proxy[:origin] @proxy = @driver.proxy(proxy[:origin]) @proxy.on(:error) { |error| @driver.emit(:error, error) } if headers = proxy[:headers] headers.each { |name, value| @proxy.set_header(name, value) } end @proxy.on(:connect) do @proxy = nil start_tls(URI.parse(@url), @origin_tls) @driver.start end end
Source
# File lib/faye/websocket/client.rb, line 67 def on_connect(stream) @stream = stream start_tls(@endpoint, @socket_tls) worker = @proxy || @driver worker.start end
Source
# File lib/faye/websocket/client.rb, line 75 def on_network_error(error) emit_error("Network error: #{ @url }: #{ error.message }") finalize_close end
Source
# File lib/faye/websocket/client.rb, line 86 def ssl_handshake_completed @ssl_verifier.ssl_handshake_completed rescue => error on_network_error(error) end
Source
# File lib/faye/websocket/client.rb, line 80 def ssl_verify_peer(cert) @ssl_verifier.ssl_verify_peer(cert) rescue => error on_network_error(error) end
Source
# File lib/faye/websocket/client.rb, line 59 def start_tls(uri, options) return unless SECURE_PROTOCOLS.include?(uri.scheme) tls_options = { :sni_hostname => uri.host, :verify_peer => true }.merge(options) @ssl_verifier = SslVerifier.new(uri.host, tls_options) @stream.start_tls(tls_options) end