Class: NchanTools::Subscriber::WebSocketClient::WebSocketBundle
- Inherits:
-
Object
- Object
- NchanTools::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_close(reason = nil, code = 1000) ⇒ Object
- #send_data(data) ⇒ Object
- #send_handshake ⇒ Object
- #send_ping(msg = nil) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(url, sock, opt = {}) ⇒ WebSocketBundle
Returns a new instance of WebSocketBundle.
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/nchan_tools/pubsub.rb', line 439 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.
438 439 440 |
# File 'lib/nchan_tools/pubsub.rb', line 438 def connected @connected end |
#last_message_frame_type ⇒ Object
Returns the value of attribute last_message_frame_type.
437 438 439 |
# File 'lib/nchan_tools/pubsub.rb', line 437 def @last_message_frame_type end |
#last_message_time ⇒ Object
Returns the value of attribute last_message_time.
437 438 439 |
# File 'lib/nchan_tools/pubsub.rb', line 437 def @last_message_time end |
#sock ⇒ Object
Returns the value of attribute sock.
437 438 439 |
# File 'lib/nchan_tools/pubsub.rb', line 437 def sock @sock end |
#url ⇒ Object
Returns the value of attribute url.
437 438 439 |
# File 'lib/nchan_tools/pubsub.rb', line 437 def url @url end |
#ws ⇒ Object
Returns the value of attribute ws.
437 438 439 |
# File 'lib/nchan_tools/pubsub.rb', line 437 def ws @ws end |
Instance Method Details
#body_buf ⇒ Object
474 475 476 |
# File 'lib/nchan_tools/pubsub.rb', line 474 def body_buf @ws.response_body end |
#connected? ⇒ Boolean
468 469 470 |
# File 'lib/nchan_tools/pubsub.rb', line 468 def connected? @connected end |
#headers ⇒ Object
471 472 473 |
# File 'lib/nchan_tools/pubsub.rb', line 471 def headers @ws.headers end |
#read ⇒ Object
502 503 504 505 506 |
# File 'lib/nchan_tools/pubsub.rb', line 502 def read @buf.clear sock.readpartial(4096, @buf) @ws.parse @buf end |
#send_binary(data) ⇒ Object
486 487 488 |
# File 'lib/nchan_tools/pubsub.rb', line 486 def send_binary data @ws.binary data end |
#send_close(reason = nil, code = 1000) ⇒ Object
494 495 496 |
# File 'lib/nchan_tools/pubsub.rb', line 494 def send_close(reason=nil, code=1000) @ws.close(reason, code) end |
#send_data(data) ⇒ Object
482 483 484 |
# File 'lib/nchan_tools/pubsub.rb', line 482 def send_data data @ws.text data end |
#send_handshake ⇒ Object
478 479 480 |
# File 'lib/nchan_tools/pubsub.rb', line 478 def send_handshake ret = @ws.start end |
#send_ping(msg = nil) ⇒ Object
490 491 492 |
# File 'lib/nchan_tools/pubsub.rb', line 490 def send_ping(msg=nil) @ws.ping(msg) end |
#write(data) ⇒ Object
498 499 500 |
# File 'lib/nchan_tools/pubsub.rb', line 498 def write(data) @sock.write data end |