Sha256: f56a86c07e5e84b85c7da4f4b3f79c44b667a5e466a8d8d0a7705d9f3c0c1312

Contents?: true

Size: 1.08 KB

Versions: 31

Compression:

Stored size: 1.08 KB

Contents

require 'faye/websocket'

module ActionCable
  module Connection
    class FayeClientSocket
      def initialize(env, event_target, stream_event_loop, protocols)
        @env = env
        @event_target = event_target
        @protocols = protocols

        @faye = nil
      end

      def alive?
        @faye && @faye.ready_state == Faye::WebSocket::API::OPEN
      end

      def transmit(data)
        connect
        @faye.send data
      end

      def close
        @faye && @faye.close
      end

      def protocol
        @faye && @faye.protocol
      end

      def rack_response
        connect
        @faye.rack_response
      end

      private
        def connect
          return if @faye
          @faye = Faye::WebSocket.new(@env, @protocols)

          @faye.on(:open)    { |event| @event_target.on_open }
          @faye.on(:message) { |event| @event_target.on_message(event.data) }
          @faye.on(:close)   { |event| @event_target.on_close(event.reason, event.code) }
          @faye.on(:error)   { |event| @event_target.on_error(event.message) }
        end
    end
  end
end

Version data entries

31 entries across 31 versions & 4 rubygems

Version Path
actioncable-5.0.7.2 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.7.1 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.7 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.6 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.6.rc1 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.5 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.5.rc2 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.5.rc1 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.4 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.4.rc1 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.3 lib/action_cable/connection/faye_client_socket.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/actioncable-5.0.2/lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.2 lib/action_cable/connection/faye_client_socket.rb
actioncable-5.0.2.rc1 lib/action_cable/connection/faye_client_socket.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/faye_client_socket.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/faye_client_socket.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/faye_client_socket.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/faye_client_socket.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/faye_client_socket.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/faye_client_socket.rb