Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 39 lines (31 sloc) 0.866 kb
#!/usr/bin/env ruby
$:<< '../lib' << 'lib'
require 'goliath'
require 'goliath/websocket'
require 'goliath/rack/templates'
class Websocket < Goliath::WebSocket
include Goliath::Rack::Templates
use Goliath::Rack::Favicon, File.expand_path(File.dirname(__FILE__) + '/ws/favicon.ico')
def on_open(env)
env.logger.info("WS OPEN")
env['subscription'] = env.channel.subscribe { |m| env.stream_send(m) }
end
def on_message(env, msg)
env.logger.info("WS MESSAGE: #{msg}")
env.channel << msg
end
def on_close(env)
env.logger.info("WS CLOSED")
env.channel.unsubscribe(env['subscription'])
end
def on_error(env, error)
env.logger.error error
end
def response(env)
if env['REQUEST_PATH'] == '/ws'
super(env)
else
[200, {}, erb(:index, :views => Goliath::Application.root_path('ws'))]
end
end
end
Jump to Line
Something went wrong with that request. Please try again.