1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actioncable/lib/action_cable/connection/web_socket.rb

42 lines
956 B
Ruby
Raw Normal View History

require "websocket/driver"
2015-06-27 10:50:05 -04:00
module ActionCable
module Connection
# Wrap the real socket to minimize the externally-presented API
class WebSocket # :nodoc:
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?
websocket && websocket.alive?
2015-06-27 10:50:05 -04:00
end
def transmit(data)
websocket.transmit data
end
def close
websocket.close
end
def protocol
websocket.protocol
end
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.
protected
2015-06-27 10:50:05 -04:00
attr_reader :websocket
end
end
end