Skip to content

Commit

Permalink
Properly namespace realtime
Browse files Browse the repository at this point in the history
  • Loading branch information
holman committed Jan 3, 2012
1 parent e46651b commit e806532
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
22 changes: 22 additions & 0 deletions app/realtime.rb
@@ -0,0 +1,22 @@
require 'rack/websocket'
class Realtime < Rack::WebSocket::Application
def initialize(options = {})
super
end

def on_close(env)
puts "Client disconnected"
end

def on_message(env, msg)
puts "Received message: " + msg
end

def on_error(env, error)
puts "Error occured: " + error.message
end

def on_open(env)
send_data Play::Player.now_playing.to_json
end
end
31 changes: 5 additions & 26 deletions config.ru
@@ -1,37 +1,16 @@
require File.expand_path(File.dirname(__FILE__) + '/app/boot')
require 'sprockets'
require 'realtime'

stylesheets = Sprockets::Environment.new
stylesheets.append_path 'app/frontend/styles'

javascripts = Sprockets::Environment.new
javascripts.append_path 'app/frontend/scripts'

map("/css") { run stylesheets }
map("/js") { run javascripts }
map('/realtime') { run Realtime.new }

map('/') { run Play::App }
map("/css") { run stylesheets }
map("/js") { run javascripts }

require 'rack/websocket'
class Realtime < Rack::WebSocket::Application
def initialize(options = {})
super
end

def on_close(env)
puts "Client disconnected"
end

def on_message(env, msg)
puts "Received message: " + msg
end

def on_error(env, error)
puts "Error occured: " + error.message
end

def on_open(env)
send_data Play::Player.now_playing.to_json
end
end
map('/realtime') { run Realtime.new }
map('/') { run Play::App }

0 comments on commit e806532

Please sign in to comment.