Sha256: 45ee0b3f312cf9cb74dca82919a76b8c1d3d225aff94afe24596f29b9875fb1b
Contents?: true
Size: 1.1 KB
Versions: 9
Compression:
Stored size: 1.1 KB
Contents
require 'spontaneous/simultaneous' module Spontaneous::Rack::Back class Events < Base def self.messenger @messenger ||= build_messenger end def self.build_messenger messenger = ::Spontaneous::Rack::EventSource.new # Find a way to move this into a more de-centralised place # at some point we are going to want to have some configurable, extendable # list of event handlers begin ::Simultaneous.on_event("publish_progress") { |event| messenger.deliver_event(event) } ::Simultaneous.on_event("page_lock_status") { |event| messenger.deliver_event(event) } rescue => e logger.error "Error while connecting to Simultaneous server" logger.error e.inspect end messenger end get '/?', :provides => 'text/event-stream' do headers 'X-Accel-Buffering' => 'no' stream(:keep_open) do |out| messenger = self.class.messenger out.errback { messenger.delete(out) } out.callback { messenger.delete(out) } messenger << out end end end end
Version data entries
9 entries across 9 versions & 1 rubygems