Class: Rookout::ComWs::WebsocketConnection
- Inherits:
-
Object
- Object
- Rookout::ComWs::WebsocketConnection
- Defined in:
- lib/rookout/com_ws/websocket_client.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #close ⇒ Object
- #connect(driver) ⇒ Object
-
#initialize(url, proxy) ⇒ WebsocketConnection
constructor
A new instance of WebsocketConnection.
- #proxy_connect(driver) ⇒ Object
- #read_char ⇒ Object
- #write(buffer) ⇒ Object
Constructor Details
#initialize(url, proxy) ⇒ WebsocketConnection
Returns a new instance of WebsocketConnection.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rookout/com_ws/websocket_client.rb', line 88 def initialize url, proxy @url = url @proxy = proxy @uri = URI.parse @url @secure = %w[https wss].include? @uri.scheme @socket = nil @proxy_connected = false end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
128 129 130 |
# File 'lib/rookout/com_ws/websocket_client.rb', line 128 def url @url end |
Instance Method Details
#close ⇒ Object
138 139 140 141 142 143 |
# File 'lib/rookout/com_ws/websocket_client.rb', line 138 def close return if @socket.nil? @socket.close @socket = nil end |
#connect(driver) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/rookout/com_ws/websocket_client.rb', line 100 def connect driver @socket = tcp_connect proxy_connect driver if @proxy @socket = ssl_connect @socket if @secure end |
#proxy_connect(driver) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rookout/com_ws/websocket_client.rb', line 108 def proxy_connect driver connection_error = nil @proxy_connected = false proxy = driver.proxy @proxy proxy.on :connect do @proxy_connected = true end proxy.on :error do |error| connection_error = error end proxy.start proxy.parse read_char until @proxy_connected == true || !connection_error.nil? raise Exceptions::RookProxyException, connection_error unless connection_error.nil? end |
#read_char ⇒ Object
130 131 132 |
# File 'lib/rookout/com_ws/websocket_client.rb', line 130 def read_char @socket.getc end |
#write(buffer) ⇒ Object
134 135 136 |
# File 'lib/rookout/com_ws/websocket_client.rb', line 134 def write buffer @socket << buffer end |