1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/action_cable/connection/web_socket.rb
David Heinemeier Hansson 321d04ff56 Add WebSocket decorator
2015-06-27 16:50:05 +02:00

27 lines
576 B
Ruby

module ActionCable
module Connection
# Decorate the Faye::WebSocket with helpers we need.
class WebSocket
delegate :rack_response, :close, :on, to: :websocket
def initialize(env)
@websocket = Faye::WebSocket.websocket?(env) ? Faye::WebSocket.new(env) : nil
end
def possible?
websocket
end
def alive?
websocket && websocket.ready_state == Faye::WebSocket::API::OPEN
end
def transmit(data)
websocket.send data
end
private
attr_reader :websocket
end
end
end