2016-01-20 23:29:11 -05:00
|
|
|
require 'websocket/driver'
|
2015-10-16 04:02:22 -04:00
|
|
|
|
2015-06-27 10:50:05 -04:00
|
|
|
module ActionCable
|
|
|
|
module Connection
|
2016-01-20 23:29:11 -05:00
|
|
|
# Wrap the real socket to minimize the externally-presented API
|
2015-06-27 10:50:05 -04:00
|
|
|
class WebSocket
|
2016-01-20 23:29:11 -05:00
|
|
|
def initialize(env, event_target, stream_event_loop)
|
|
|
|
@websocket = ::WebSocket::Driver.websocket?(env) ? ClientSocket.new(env, event_target, stream_event_loop) : nil
|
2015-06-27 10:50:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def possible?
|
|
|
|
websocket
|
|
|
|
end
|
|
|
|
|
|
|
|
def alive?
|
2016-01-20 23:29:11 -05:00
|
|
|
websocket && websocket.alive?
|
2015-06-27 10:50:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def transmit(data)
|
2016-01-20 23:29:11 -05:00
|
|
|
websocket.transmit data
|
|
|
|
end
|
|
|
|
|
|
|
|
def close
|
|
|
|
websocket.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def rack_response
|
|
|
|
websocket.rack_response
|
2015-06-27 10:50:05 -04:00
|
|
|
end
|
|
|
|
|
2015-12-17 10:23:36 -05:00
|
|
|
protected
|
2015-06-27 10:50:05 -04:00
|
|
|
attr_reader :websocket
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|