Class: Async::WebSocket::Connection

Inherits:
Protocol::WebSocket::Connection
  • Object
show all
Includes:
Protocol::WebSocket::Headers
Defined in:
lib/async/websocket/connection.rb

Overview

This is a basic synchronous websocket client:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framer, protocol = nil, response: nil, **options) ⇒ Connection

Returns a new instance of Connection.



48
49
50
51
52
53
# File 'lib/async/websocket/connection.rb', line 48

def initialize(framer, protocol = nil, response: nil, **options)
	super(framer, **options)
	
	@protocol = protocol
	@response = response
end

Instance Attribute Details

#protocolObject (readonly)

Returns the value of attribute protocol.



68
69
70
# File 'lib/async/websocket/connection.rb', line 68

def protocol
  @protocol
end

Class Method Details

.call(framer, protocol = [], extensions = nil, **options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/async/websocket/connection.rb', line 34

def self.call(framer, protocol = [], extensions = nil, **options)
	instance = self.new(framer, Array(protocol).first, **options)
	
	extensions&.apply(instance)
	
	return instance unless block_given?
	
	begin
		yield instance
	ensure
		instance.close
	end
end

Instance Method Details

#callObject



70
71
72
# File 'lib/async/websocket/connection.rb', line 70

def call
	self.close
end

#closeObject



59
60
61
62
63
64
65
66
# File 'lib/async/websocket/connection.rb', line 59

def close
	super
	
	if @response
		@response.finish
		@response = nil
	end
end

#reusable?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/async/websocket/connection.rb', line 55

def reusable?
	false
end