Sha256: 2762d66ef7aa2b14c8e0020d53de2ad08c48c8857aed4029e4c55075424bd9cc

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

# encoding: BINARY

module EventMachine
  module WebSocket
    module MessageProcessor03
      def message(message_type, extension_data, application_data)
        case message_type
        when :close
          if @state == :closing
            # TODO: Check that message body matches sent data
            # We can close connection immediately since there is no more data
            # is allowed to be sent or received on this connection
            @connection.close_connection
            @state = :closed
          else
            # Acknowlege close
            # The connection is considered closed
            send_frame(:close, application_data)
            @state = :closed
            @connection.close_connection_after_writing
          end
        when :ping
          # Pong back the same data
          send_frame(:pong, application_data)
        when :pong
          # TODO: Do something. Complete a deferrable established by a ping?
        when :text
          if application_data.respond_to?(:force_encoding)
            application_data.force_encoding("UTF-8")
          end
          @connection.trigger_on_message(application_data)
        when :binary
          @connection.trigger_on_message(application_data)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
sonixlabs-em-websocket-0.3.8 lib/em-websocket/message_processor_03.rb
sonixlabs-em-websocket-0.3.7 lib/em-websocket/message_processor_03.rb
em-websocket-0.3.5 lib/em-websocket/message_processor_03.rb
em-websocket-0.3.2 lib/em-websocket/message_processor_03.rb