mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
41 lines
850 B
Ruby
41 lines
850 B
Ruby
# frozen_string_literal: true
|
|
|
|
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
|
|
|
|
private
|
|
attr_reader :websocket
|
|
end
|
|
end
|
|
end
|