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 ~