2016-08-06 13:13:46 -04: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-27 23:55:31 -05:00
|
|
|
# Wrap the real socket to minimize the externally-presented API
|
2017-06-16 18:36:04 -04:00
|
|
|
class WebSocket # :nodoc:
|
2016-09-30 21:38:17 -04:00
|
|
|
def initialize(env, event_target, event_loop, protocols: ActionCable::INTERNAL[:protocols])
|
|
|
|
@websocket = ::WebSocket::Driver.websocket?(env) ? ClientSocket.new(env, event_target, event_loop, protocols) : nil
|
2015-06-27 10:50:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def possible?
|
|
|
|
websocket
|
|
|
|
end
|
|
|
|
|
|
|
|
def alive?
|
2016-01-27 23:55:31 -05:00
|
|
|
websocket && websocket.alive?
|
2015-06-27 10:50:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def transmit(data)
|
2016-01-27 23:55:31 -05:00
|
|
|
websocket.transmit data
|
|
|
|
end
|
|
|
|
|
|
|
|
def close
|
|
|
|
websocket.close
|
|
|
|
end
|
|
|
|
|
2016-03-17 10:05:06 -04:00
|
|
|
def protocol
|
|
|
|
websocket.protocol
|
|
|
|
end
|
|
|
|
|
2016-01-27 23:55:31 -05:00
|
|
|
def rack_response
|
|
|
|
websocket.rack_response
|
2015-06-27 10:50:05 -04:00
|
|
|
end
|
|
|
|
|
2016-12-19 05:10:49 -05:00
|
|
|
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
|
|
|
# Workaround for Ruby 2.2 "private attribute?" warning.
|
2015-12-17 10:23:36 -05:00
|
|
|
protected
|
2015-06-27 10:50:05 -04:00
|
|
|
attr_reader :websocket
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|