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



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

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.



53
54
55
# File 'lib/async/websocket/connection.rb', line 53

def protocol
  @protocol
end

Class Method Details

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



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/async/websocket/connection.rb', line 19

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



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

def call
  self.close
end

#closeObject



44
45
46
47
48
49
50
51
# File 'lib/async/websocket/connection.rb', line 44

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

#reusable?Boolean



40
41
42
# File 'lib/async/websocket/connection.rb', line 40

def reusable?
  false
end