Class: WebSocket::EventMachine::Client
- Inherits:
- 
      Base
      
        - Object
- Base
- WebSocket::EventMachine::Client
 
- Defined in:
- lib/websocket/eventmachine/client.rb,
 lib/websocket/eventmachine/client/version.rb
Overview
WebSocket Client (using EventMachine)
Constant Summary collapse
- VERSION =
- '1.3.0'
Class Method Summary collapse
- 
  
    
      .connect(args = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Connect to websocket server. 
- 
  
    
      .connect_unix_domain(socketname, args = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Make a websocket connection to a UNIX-domain socket. 
Instance Method Summary collapse
- 
  
    
      #close(code = 1000, data = nil)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Close connection. 
- 
  
    
      #connection_completed  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called by EventMachine after connecting. 
- 
  
    
      #initialize(args)  ⇒ Client 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Initialize connection. 
- 
  
    
      #onclose(&blk)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called when connection is closed. 
- 
  
    
      #onerror(&blk)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called when error occurs. 
- 
  
    
      #onmessage(&blk)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called when message is received. 
- 
  
    
      #onopen(&blk)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called when connection is opened. 
- 
  
    
      #onping(&blk)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called when ping message is received One parameter passed to block: message - string with ping message. 
- 
  
    
      #onpong(&blk)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called when pong message is received One parameter passed to block: message - string with pong message. 
- 
  
    
      #ping(data = '')  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Send ping message. 
- 
  
    
      #pong(data = '')  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Send pong message. 
- 
  
    
      #post_init  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called after initialize of connection, but before connecting to server Eventmachine internal. 
- 
  
    
      #send(data, args = {})  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Send data. 
- 
  
    
      #ssl_handshake_completed  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Called by EventMachine after SSL/TLS handshake. 
Constructor Details
#initialize(args) ⇒ Client
Initialize connection
| 67 68 69 | # File 'lib/websocket/eventmachine/client.rb', line 67 def initialize(args) @args = args end | 
Class Method Details
.connect(args = {}) ⇒ Object
Connect to websocket server
| 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # File 'lib/websocket/eventmachine/client.rb', line 27 def self.connect(args = {}) host = nil port = nil if args[:uri] uri = URI.parse(args[:uri]) host = uri.host port = uri.port args[:ssl] = true if uri.scheme == 'wss' end host = args[:host] if args[:host] port = args[:port] if args[:port] if args[:ssl] args[:tls] ||= {} args[:tls][:sni_hostname] ||= host port ||= 443 else port ||= 80 end ::EventMachine.connect host, port, self, args end | 
.connect_unix_domain(socketname, args = {}) ⇒ Object
Make a websocket connection to a UNIX-domain socket.
| 54 55 56 57 58 | # File 'lib/websocket/eventmachine/client.rb', line 54 def self.connect_unix_domain(socketname, args = {}) fail ArgumentError, 'invalid socket' unless File.socket?(socketname) args[:host] ||= 'localhost' ::EventMachine.connect_unix_domain socketname, self, args end | 
Instance Method Details
#close(code = 1000, data = nil) ⇒ Boolean
Close connection
| 158 | # File 'lib/websocket/eventmachine/client.rb', line 158 def close(code = 1000, data = nil); super; end | 
#connection_completed ⇒ Object
Called by EventMachine after connecting. Sends handshake to server or starts SSL/TLS Eventmachine internal
| 87 88 89 90 91 92 93 | # File 'lib/websocket/eventmachine/client.rb', line 87 def connection_completed if @args[:ssl] start_tls @args[:tls] else send(@handshake.to_s, :type => :plain) end end | 
#onclose(&blk) ⇒ Object
Called when connection is closed. No parameters are passed to block
| 125 | # File 'lib/websocket/eventmachine/client.rb', line 125 def onclose(&blk); super; end | 
#onerror(&blk) ⇒ Object
Called when error occurs. One parameter passed to block:
error - string with error 
| 130 | # File 'lib/websocket/eventmachine/client.rb', line 130 def onerror(&blk); super; end | 
#onmessage(&blk) ⇒ Object
Called when message is received. Two parameters passed to block:
 - string with received 
type - type of . Valid values are :text and :binary
| 136 | # File 'lib/websocket/eventmachine/client.rb', line 136 def (&blk); super; end | 
#onopen(&blk) ⇒ Object
Called when connection is opened. No parameters are passed to block
| 121 | # File 'lib/websocket/eventmachine/client.rb', line 121 def onopen(&blk); super; end | 
#onping(&blk) ⇒ Object
Called when ping message is received One parameter passed to block:
 - string with ping 
| 141 | # File 'lib/websocket/eventmachine/client.rb', line 141 def onping(&blk); super; end | 
#onpong(&blk) ⇒ Object
Called when pong message is received One parameter passed to block:
 - string with pong 
| 146 | # File 'lib/websocket/eventmachine/client.rb', line 146 def onpong(&blk); super; end | 
#ping(data = '') ⇒ Boolean
Send ping message
| 162 | # File 'lib/websocket/eventmachine/client.rb', line 162 def ping(data = ''); super; end | 
#pong(data = '') ⇒ Boolean
Send pong message
| 166 | # File 'lib/websocket/eventmachine/client.rb', line 166 def pong(data = ''); super; end | 
#post_init ⇒ Object
Called after initialize of connection, but before connecting to server Eventmachine internal
| 78 79 80 81 | # File 'lib/websocket/eventmachine/client.rb', line 78 def post_init @state = :connecting @handshake = ::WebSocket::Handshake::Client.new(@args) end | 
#send(data, args = {}) ⇒ Boolean
Send data
| 154 | # File 'lib/websocket/eventmachine/client.rb', line 154 def send(data, args = {}); super; end | 
#ssl_handshake_completed ⇒ Object
Called by EventMachine after SSL/TLS handshake. Sends websocket handshake Eventmachine internal
| 99 100 101 | # File 'lib/websocket/eventmachine/client.rb', line 99 def ssl_handshake_completed send(@handshake.to_s, :type => :plain) end |