diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2015-06-27 16:50:05 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2015-06-27 16:50:05 +0200 |
commit | 321d04ff56e2f17ef7285141252dba8ff5cdecca (patch) | |
tree | 8e4f228f4cdc0305ae7789ed57d53be1cc4feb76 /lib/action_cable/connection/web_socket.rb | |
parent | 78f3c88d69741ffd9b24da8d362f3f7c4c8454f8 (diff) | |
download | rails-321d04ff56e2f17ef7285141252dba8ff5cdecca.tar.gz rails-321d04ff56e2f17ef7285141252dba8ff5cdecca.tar.bz2 rails-321d04ff56e2f17ef7285141252dba8ff5cdecca.zip |
Add WebSocket decorator
Diffstat (limited to 'lib/action_cable/connection/web_socket.rb')
-rw-r--r-- | lib/action_cable/connection/web_socket.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/action_cable/connection/web_socket.rb b/lib/action_cable/connection/web_socket.rb new file mode 100644 index 0000000000..135a28cfe4 --- /dev/null +++ b/lib/action_cable/connection/web_socket.rb @@ -0,0 +1,27 @@ +module ActionCable + module Connection + # Decorate the Faye::WebSocket with helpers we need. + class WebSocket + delegate :rack_response, :close, :on, to: :websocket + + def initialize(env) + @websocket = Faye::WebSocket.websocket?(env) ? Faye::WebSocket.new(env) : nil + end + + def possible? + websocket + end + + def alive? + websocket && websocket.ready_state == Faye::WebSocket::API::OPEN + end + + def transmit(data) + websocket.send data + end + + private + attr_reader :websocket + end + end +end |