Class: Subscriber::WebSocketClient::WebSocketBundle
- Inherits:
-
Object
- Object
- Subscriber::WebSocketClient::WebSocketBundle
- Defined in:
- lib/nchan_tools/pubsub.rb
Instance Attribute Summary collapse
-
#connected ⇒ Object
Returns the value of attribute connected.
-
#last_message_frame_type ⇒ Object
Returns the value of attribute last_message_frame_type.
-
#last_message_time ⇒ Object
Returns the value of attribute last_message_time.
-
#sock ⇒ Object
Returns the value of attribute sock.
-
#url ⇒ Object
Returns the value of attribute url.
-
#ws ⇒ Object
Returns the value of attribute ws.
Instance Method Summary collapse
- #body_buf ⇒ Object
- #connected? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(url, sock, opt = {}) ⇒ WebSocketBundle
constructor
A new instance of WebSocketBundle.
- #read ⇒ Object
- #send_binary(data) ⇒ Object
- #send_data(data) ⇒ Object
- #send_handshake ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(url, sock, opt = {}) ⇒ WebSocketBundle
Returns a new instance of WebSocketBundle.
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/nchan_tools/pubsub.rb', line 442 def initialize(url, sock, opt={}) @buf="" @url = url driver_opt = {max_length: 2**28-1} #256M if opt[:subprotocol] driver_opt[:protocols]=opt[:subprotocol] end @ws = WebSocket::Driver.client self, driver_opt if opt[:permessage_deflate] if opt[:permessage_deflate_max_window_bits] or opt[:permessage_deflate_server_max_window_bits] deflate = PermessageDeflate.configure( :max_window_bits => opt[:permessage_deflate_max_window_bits], :request_max_window_bits => opt[:permessage_deflate_server_max_window_bits] ) @ws.add_extension deflate else @ws.add_extension PermessageDeflate end end if opt[:extra_headers] opt[:extra_headers].each {|k, v| @ws.set_header(k, v)} end @sock = sock @id = opt[:id] || :"~" @logger = opt[:logger] end |
Instance Attribute Details
#connected ⇒ Object
Returns the value of attribute connected.
441 442 443 |
# File 'lib/nchan_tools/pubsub.rb', line 441 def connected @connected end |
#last_message_frame_type ⇒ Object
Returns the value of attribute last_message_frame_type.
440 441 442 |
# File 'lib/nchan_tools/pubsub.rb', line 440 def @last_message_frame_type end |
#last_message_time ⇒ Object
Returns the value of attribute last_message_time.
440 441 442 |
# File 'lib/nchan_tools/pubsub.rb', line 440 def @last_message_time end |
#sock ⇒ Object
Returns the value of attribute sock.
440 441 442 |
# File 'lib/nchan_tools/pubsub.rb', line 440 def sock @sock end |
#url ⇒ Object
Returns the value of attribute url.
440 441 442 |
# File 'lib/nchan_tools/pubsub.rb', line 440 def url @url end |
#ws ⇒ Object
Returns the value of attribute ws.
440 441 442 |
# File 'lib/nchan_tools/pubsub.rb', line 440 def ws @ws end |
Instance Method Details
#body_buf ⇒ Object
477 478 479 |
# File 'lib/nchan_tools/pubsub.rb', line 477 def body_buf @ws.response_body end |
#connected? ⇒ Boolean
471 472 473 |
# File 'lib/nchan_tools/pubsub.rb', line 471 def connected? @connected end |
#headers ⇒ Object
474 475 476 |
# File 'lib/nchan_tools/pubsub.rb', line 474 def headers @ws.headers end |
#read ⇒ Object
497 498 499 500 501 |
# File 'lib/nchan_tools/pubsub.rb', line 497 def read @buf.clear sock.readpartial(4096, @buf) @ws.parse @buf end |
#send_binary(data) ⇒ Object
489 490 491 |
# File 'lib/nchan_tools/pubsub.rb', line 489 def send_binary data @ws.binary data end |
#send_data(data) ⇒ Object
485 486 487 |
# File 'lib/nchan_tools/pubsub.rb', line 485 def send_data data @ws.text data end |
#send_handshake ⇒ Object
481 482 483 |
# File 'lib/nchan_tools/pubsub.rb', line 481 def send_handshake ret = @ws.start end |
#write(data) ⇒ Object
493 494 495 |
# File 'lib/nchan_tools/pubsub.rb', line 493 def write(data) @sock.write data end |