Sha256: f7de35440a20a2364765324aca2d1a0e1dce3b4952ce913b7ea53b6abf114601

Contents?: true

Size: 629 Bytes

Versions: 2

Compression:

Stored size: 629 Bytes

Contents

module Dashing
  class EventsController < ApplicationController
    include ActionController::Live

    respond_to :html

    def index
      response.headers['Content-Type']      = 'text/event-stream'
      response.headers['X-Accel-Buffering'] = 'no'

      redis = Redis.new
      redis.psubscribe("#{Dashing.config.redis_namespace}.*") do |on|
        on.pmessage do |pattern, event, data|
          response.stream.write("data: #{data}\n\n")
        end
      end
    rescue IOError
      logger.info "[Dashing][#{Time.now.utc.to_s}] Stream closed"
    ensure
      redis.quit
      response.stream.close
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dashing-rails-1.0.1 app/controllers/dashing/events_controller.rb
dashing-rails-1.0.0 app/controllers/dashing/events_controller.rb