lib/sinatra-rocketio/application.rb in sinatra-rocketio-0.0.1 vs lib/sinatra-rocketio/application.rb in sinatra-rocketio-0.0.2

- old
+ new

@@ -1,15 +1,26 @@ module Sinatra module RocketIO def self.registered(app) - app.register Sinatra::CometIO - app.register Sinatra::WebSocketIO app.helpers Sinatra::RocketIO::Helpers - - app.get '/rocketio/rocketio.js' do - content_type 'application/javascript' - @js ||= ERB.new(Sinatra::RocketIO.javascript).result(binding) + EM::defer do + while !EM::reactor_running? do + sleep 1 + end + if options[:comet] + require 'sinatra/cometio' + app.register Sinatra::CometIO + end + if options[:websocket] + require 'sinatra/websocketio' + app.register Sinatra::WebSocketIO + end + app.get '/rocketio/rocketio.js' do + content_type 'application/javascript' + @js ||= ERB.new(Sinatra::RocketIO.javascript).result(binding) + end + Sinatra::RocketIO.emit :regist_events end end end end