Class: EventMachine::WebSocketWrapper

Inherits:
WebSocket
  • Object
show all
Defined in:
lib/em-ws-request/wrapper.rb

Constant Summary

Constants inherited from WebSocket

WebSocket::OPCODE_BINARY, WebSocket::OPCODE_CLOSE, WebSocket::OPCODE_CONTINUATION, WebSocket::OPCODE_PING, WebSocket::OPCODE_PONG, WebSocket::OPCODE_TEXT, WebSocket::WEB_SOCKET_GUID

Instance Attribute Summary

Attributes inherited from WebSocket

#header, #path, #server

Instance Method Summary collapse

Methods inherited from WebSocket

#close_socket, #handshake, #host, #location, #origin, #send, #tcp_socket

Constructor Details

#initialize(client, version) ⇒ WebSocketWrapper

Returns a new instance of WebSocketWrapper.


5
6
7
8
9
10
# File 'lib/em-ws-request/wrapper.rb', line 5

def initialize(client, version)
  @handshaked = true
  @client = client
  @web_socket_version = version
  @read_buffer = ''
end

Instance Method Details

#close(code = 1005, reason = "", origin = :self) ⇒ Object

Called on a CLOSE frame


37
38
39
40
41
# File 'lib/em-ws-request/wrapper.rb', line 37

def close(code = 1005, reason = "", origin = :self)
  origin = :self if origin == :peer # to skip @socket.close
  super(code, reason, origin)
  @client.unbind
end

#read(num_bytes) ⇒ Object


26
27
28
29
30
31
32
33
34
# File 'lib/em-ws-request/wrapper.rb', line 26

def read(num_bytes)
  if(@read_buffer.size < num_bytes)
    raise EOFError
  else
    str = @read_buffer.slice(0, num_bytes)
    @read_buffer = @read_buffer[num_bytes..-1]
    return str
  end
end

#receive(data) ⇒ Object


21
22
23
24
# File 'lib/em-ws-request/wrapper.rb', line 21

def receive(data)
  @read_buffer << data if data
  super()
end

#send_frame(opcode, data, mask = true) ⇒ Object


12
13
14
15
# File 'lib/em-ws-request/wrapper.rb', line 12

def send_frame(opcode, data, mask = true)
  opcode = type_to_opcode(opcode) if opcode.is_a?(Symbol)
  super(opcode, data, mask)
end

#write(data) ⇒ Object


17
18
19
# File 'lib/em-ws-request/wrapper.rb', line 17

def write(data)
  @client.send_data(data)
end