mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
322dca293b
(as adapted to use concurrent-ruby / nio4r instead of eventmachine)
35 lines
711 B
Ruby
35 lines
711 B
Ruby
require 'websocket/driver'
|
|
|
|
module ActionCable
|
|
module Connection
|
|
# Wrap the real socket to minimize the externally-presented API
|
|
class WebSocket
|
|
def initialize(env, event_target, stream_event_loop)
|
|
@websocket = ::WebSocket::Driver.websocket?(env) ? ClientSocket.new(env, event_target, stream_event_loop) : nil
|
|
end
|
|
|
|
def possible?
|
|
websocket
|
|
end
|
|
|
|
def alive?
|
|
websocket && websocket.alive?
|
|
end
|
|
|
|
def transmit(data)
|
|
websocket.transmit data
|
|
end
|
|
|
|
def close
|
|
websocket.close
|
|
end
|
|
|
|
def rack_response
|
|
websocket.rack_response
|
|
end
|
|
|
|
protected
|
|
attr_reader :websocket
|
|
end
|
|
end
|
|
end
|