# File lib/faye/websocket.rb, line 127
    def initialize(env, supported_protos = nil, options = {})
      @env     = env
      @stream  = Stream.new(self)
      @ping    = options[:ping]
      @ping_id = 0

      @url = WebSocket.determine_url(@env)
      @ready_state = CONNECTING
      @buffered_amount = 0

      @parser = WebSocket.parser(@env).new(self, :protocols => supported_protos)

      @send_buffer = []
      EventMachine.next_tick { open }

      @callback = @env['async.callback']
      @callback.call([101, {}, @stream])
      @stream.write(@parser.handshake_response)

      @ready_state = OPEN if @parser.open?

      if @ping
        @ping_timer = EventMachine.add_periodic_timer(@ping) do
          @ping_id += 1
          ping(@ping_id.to_s)
        end
      end
    end