Title / Description
Code require 'reloader/sse' class BrowserController < ApplicationController include ActionController::Live def index # SSE expects the `text/event-stream` content type response.headers['Content-Type'] = 'text/event-stream' sse = Reloader::SSE.new(response.stream) begin $redis.subscribe('browser') do |on| on.message do |channel, msg| sse.write(msg, :event => 'refresh') end end rescue IOError # When the client disconnects, we'll get an IOError on write ensure sse.close end end end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code