Class: Async::WebSocket::Connection
- Inherits:
-
Protocol::WebSocket::Connection
- Object
- Protocol::WebSocket::Connection
- Async::WebSocket::Connection
- Includes:
- Protocol::WebSocket::Headers
- Defined in:
- lib/async/websocket/connection.rb
Overview
This is a basic synchronous websocket client:
Instance Attribute Summary collapse
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #close ⇒ Object
- #dump(object) ⇒ Object
-
#initialize(framer, protocol = nil, response: nil, **options) ⇒ Connection
constructor
A new instance of Connection.
- #parse(buffer) ⇒ Object
- #read ⇒ Object
- #write(object) ⇒ Object
Constructor Details
#initialize(framer, protocol = nil, response: nil, **options) ⇒ Connection
Returns a new instance of Connection.
46 47 48 49 50 |
# File 'lib/async/websocket/connection.rb', line 46 def initialize(framer, protocol = nil, response: nil, **) super(framer, **) @protocol = protocol @response = response end |
Instance Attribute Details
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol
61 62 63 |
# File 'lib/async/websocket/connection.rb', line 61 def protocol @protocol end |
Class Method Details
.call(framer, protocol = [], **options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/async/websocket/connection.rb', line 34 def self.call(framer, protocol = [], **) instance = self.new(framer, Array(protocol).first, **) return instance unless block_given? begin yield instance ensure instance.close end end |
Instance Method Details
#call ⇒ Object
81 82 83 |
# File 'lib/async/websocket/connection.rb', line 81 def call self.close end |
#close ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/async/websocket/connection.rb', line 52 def close super if @response @response.finish @response = nil end end |
#dump(object) ⇒ Object
77 78 79 |
# File 'lib/async/websocket/connection.rb', line 77 def dump(object) JSON.dump(object) end |
#parse(buffer) ⇒ Object
73 74 75 |
# File 'lib/async/websocket/connection.rb', line 73 def parse(buffer) JSON.parse(buffer, symbolize_names: true) end |
#read ⇒ Object
63 64 65 66 67 |
# File 'lib/async/websocket/connection.rb', line 63 def read if buffer = super parse(buffer) end end |
#write(object) ⇒ Object
69 70 71 |
# File 'lib/async/websocket/connection.rb', line 69 def write(object) super(dump(object)) end |