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
T.J. Schuck 2f8dc184fc nodoc AC::Connection::WebSocket
Users should never publicly be interacting with an instance of this.  The instance that comes along with an `AC::Connection::Base` instance (the only thing a user should be working with) is [itself intended to be private](https://github.com/tjschuck/rails/blob/master/actioncable/lib/action_cable/connection/base.rb#L137-L140).

[ci skip]
2017-06-16 18:36:04 -04:00

41 lines
956 B
Ruby

require "websocket/driver"
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
end
def possible?
websocket
end
def alive?
websocket && websocket.alive?
end
def transmit(data)
websocket.transmit data
end
def close
websocket.close
end
def protocol
websocket.protocol
end
def rack_response
websocket.rack_response
end
# TODO Change this to private once we've dropped Ruby 2.2 support.
# Workaround for Ruby 2.2 "private attribute?" warning.
protected
attr_reader :websocket
end
end
end