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
- #dump(object) ⇒ Object
-
#initialize(framer, protocol = nil, **options) ⇒ Connection
constructor
A new instance of Connection.
- #parse(buffer) ⇒ Object
- #read ⇒ Object
- #write(object) ⇒ Object
Constructor Details
#initialize(framer, protocol = nil, **options) ⇒ Connection
Returns a new instance of Connection.
38 39 40 41 |
# File 'lib/async/websocket/connection.rb', line 38 def initialize(framer, protocol = nil, **) super(framer, **) @protocol = protocol end |
Instance Attribute Details
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
43 44 45 |
# File 'lib/async/websocket/connection.rb', line 43 def protocol @protocol end |
Class Method Details
.call(framer, protocol = [], **options) ⇒ Object
34 35 36 |
# File 'lib/async/websocket/connection.rb', line 34 def self.call(framer, protocol = [], **) return self.new(framer, Array(protocol).first, **) end |
Instance Method Details
#call ⇒ Object
63 64 65 |
# File 'lib/async/websocket/connection.rb', line 63 def call self.close end |
#dump(object) ⇒ Object
59 60 61 |
# File 'lib/async/websocket/connection.rb', line 59 def dump(object) JSON.dump(object) end |
#parse(buffer) ⇒ Object
55 56 57 |
# File 'lib/async/websocket/connection.rb', line 55 def parse(buffer) JSON.parse(buffer, symbolize_names: true) end |
#read ⇒ Object
45 46 47 48 49 |
# File 'lib/async/websocket/connection.rb', line 45 def read if buffer = super parse(buffer) end end |
#write(object) ⇒ Object
51 52 53 |
# File 'lib/async/websocket/connection.rb', line 51 def write(object) super(dump(object)) end |