Class: Async::WebSocket::Client

Inherits:
Connection show all
Defined in:
lib/async/websocket/client.rb

Overview

This is a basic synchronous websocket client:

Constant Summary

Constants inherited from Connection

Async::WebSocket::Connection::BLOCK_SIZE, Async::WebSocket::Connection::EVENTS

Instance Attribute Summary

Attributes inherited from Connection

#driver, #url

Instance Method Summary collapse

Methods inherited from Connection

#close, #next_event, #next_message, #send_message, #send_text, #write

Constructor Details

#initialize(socket, url = "ws://.", **options) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
# File 'lib/async/websocket/client.rb', line 27

def initialize(socket, url = "ws://.", **options)
	@url = url

	super socket, build_client(**options)
end

Instance Method Details

#build_client(headers: nil, **options) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/async/websocket/client.rb', line 33

def build_client(headers: nil, **options)
	::WebSocket::Driver.client(self, options).tap do |client|
		headers&.each do |key, value|
			client.set_header(key, value)
		end
	end
end