class NchanTools::Subscriber::WebSocketClient::WebSocketBundle
Attributes
connected[RW]
last_message_frame_type[RW]
last_message_time[RW]
sock[RW]
url[RW]
ws[RW]
Public Class Methods
new(url, sock, opt={})
click to toggle source
# 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
Public Instance Methods
body_buf()
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 474 def body_buf @ws.response_body end
connected?()
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 468 def connected? @connected end
headers()
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 471 def headers @ws.headers end
read()
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 502 def read @buf.clear sock.readpartial(4096, @buf) @ws.parse @buf end
send_binary(data)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 486 def send_binary data @ws.binary data end
send_close(reason=nil, code=1000)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 494 def send_close(reason=nil, code=1000) @ws.close(reason, code) end
send_data(data)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 482 def send_data data @ws.text data end
send_handshake()
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 478 def send_handshake ret = @ws.start end
send_ping(msg=nil)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 490 def send_ping(msg=nil) @ws.ping(msg) end
write(data)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 498 def write(data) @sock.write data end