def stream(room, &callback)
      parser = Yajl::Parser.new(:symbolize_keys => true)

      parser.on_parse_complete = proc do |data|
        callback.call(Firering::Message.instantiate(self, data)) if callback
      end

      # timeout 5s because the campfire streaming API chunked connection sends
      # "1\r\n \r\n" every 3s, and we want to bail as soon as that stops
      options = {:keepalive => true, :timeout => 5}

      uri = streaming_host.join("/room/#{room.id}/live.json")
      logger.info("performing streaming request to #{uri.to_s}")
      http = EventMachine::HttpRequest.new(uri).get(options.merge(parameters))

      http.stream do |chunk|
        begin
          parser << chunk; reset_retries_counter
        rescue Yajl::ParseError
          perform_retry(http) do
            room.stream(&callback)
          end
        end
      end

      # Campfire servers will try to hold the streaming connections open indefinitely.
      # However, API clients must be able to handle occasional timeouts or
      # disruptions. Upon unexpected disconnection, API clients should wait for a
      # few seconds before trying to reconnect.
      http.errback do
        logger.error("http error #{http.error}. Trying again in #{retry_delay} seconds...")
        perform_retry(http) do
          room.stream(&callback)
        end
      end

      # Campfire will _also_ actively close the connection. Correctly. Presumably,
      # this only happens when they deploy, but it does actually happen.
      http.callback do
        logger.error("http connection closed. Trying again in #{retry_delay} seconds...")
        perform_retry(http) do
          room.stream(&callback)
        end
      end

      http
    end
def stream(room, &callback)
      parser = Yajl::Parser.new(:symbolize_keys => true)

      parser.on_parse_complete = proc do |data|
        callback.call(Firering::Message.instantiate(self, data)) if callback
      end

      # timeout 5s because the campfire streaming API chunked connection sends
      # "1\r\n \r\n" every 3s, and we want to bail as soon as that stops
      options = {:keepalive => true, :timeout => 5}

      uri = streaming_host.join("/room/#{room.id}/live.json")
      logger.info("performing streaming request to #{uri.to_s}")
      http = EventMachine::HttpRequest.new(uri).get(options.merge(parameters))

      http.stream do |chunk|
        begin
          parser << chunk; reset_retries_counter
        rescue Yajl::ParseError
          perform_retry(http) do
            room.stream(&callback)
          end
        end
      end

      # Campfire servers will try to hold the streaming connections open indefinitely.
      # However, API clients must be able to handle occasional timeouts or
      # disruptions. Upon unexpected disconnection, API clients should wait for a
      # few seconds before trying to reconnect.
      http.errback do
        logger.error("http error #{http.error}. Trying again in #{retry_delay} seconds...")
        perform_retry(http) do
          room.stream(&callback)
        end
      end

      # Campfire will _also_ actively close the connection. Correctly. Presumably,
      # this only happens when they deploy, but it does actually happen.
      http.callback do
        logger.error("http connection closed. Trying again in #{retry_delay} seconds...")
        perform_retry(http) do
          room.stream(&callback)
        end
      end

      http
    end
Streaming

 The Streaming API allows you to monitor a room in real time. The
 authenticated user must already have joined the room in order to use this
 API.