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 51 |
# 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.
62 63 64 |
# File 'lib/async/websocket/connection.rb', line 62 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
82 83 84 |
# File 'lib/async/websocket/connection.rb', line 82 def call self.close end |
#close ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/async/websocket/connection.rb', line 53 def close super if @response @response.finish @response = nil end end |
#dump(object) ⇒ Object
78 79 80 |
# File 'lib/async/websocket/connection.rb', line 78 def dump(object) JSON.dump(object) end |
#parse(buffer) ⇒ Object
74 75 76 |
# File 'lib/async/websocket/connection.rb', line 74 def parse(buffer) JSON.parse(buffer, symbolize_names: true) end |
#read ⇒ Object
64 65 66 67 68 |
# File 'lib/async/websocket/connection.rb', line 64 def read if buffer = super parse(buffer) end end |
#write(object) ⇒ Object
70 71 72 |
# File 'lib/async/websocket/connection.rb', line 70 def write(object) super(dump(object)) end |