Class: Subscriber::WebSocketClient::WebSocketBundle

Inherits:
Object
  • Object
show all
Defined in:
lib/nchan_tools/pubsub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connectedObject

Returns the value of attribute connected.



441
442
443
# File 'lib/nchan_tools/pubsub.rb', line 441

def connected
  @connected
end

#last_message_frame_typeObject

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
  @last_message_frame_type
end

#last_message_timeObject

Returns the value of attribute last_message_time.



440
441
442
# File 'lib/nchan_tools/pubsub.rb', line 440

def last_message_time
  @last_message_time
end

#sockObject

Returns the value of attribute sock.



440
441
442
# File 'lib/nchan_tools/pubsub.rb', line 440

def sock
  @sock
end

#urlObject

Returns the value of attribute url.



440
441
442
# File 'lib/nchan_tools/pubsub.rb', line 440

def url
  @url
end

#wsObject

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_bufObject



477
478
479
# File 'lib/nchan_tools/pubsub.rb', line 477

def body_buf
  @ws.response_body
end

#connected?Boolean

Returns:

  • (Boolean)


471
472
473
# File 'lib/nchan_tools/pubsub.rb', line 471

def connected?
  @connected
end

#headersObject



474
475
476
# File 'lib/nchan_tools/pubsub.rb', line 474

def headers
  @ws.headers
end

#readObject



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_handshakeObject



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