Class: ActionCable::Connection::WebSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/action_cable/connection/web_socket.rb

Overview

Decorate the Faye::WebSocket with helpers we need.

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ WebSocket

Returns a new instance of WebSocket.


7
8
9
# File 'lib/action_cable/connection/web_socket.rb', line 7

def initialize(env)
  @websocket = Faye::WebSocket.websocket?(env) ? Faye::WebSocket.new(env) : nil
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)

15
16
17
# File 'lib/action_cable/connection/web_socket.rb', line 15

def alive?
  websocket && websocket.ready_state == Faye::WebSocket::API::OPEN
end

#possible?Boolean

Returns:

  • (Boolean)

11
12
13
# File 'lib/action_cable/connection/web_socket.rb', line 11

def possible?
  websocket
end

#transmit(data) ⇒ Object


19
20
21
# File 'lib/action_cable/connection/web_socket.rb', line 19

def transmit(data)
  websocket.send data
end