Created
September 28, 2012 07:40
-
-
Save boutros/3798492 to your computer and use it in GitHub Desktop.
Multiple Goliath WebSocket endpoints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "bundler/setup" | |
require "goliath" | |
require "goliath/websocket" | |
class User < Goliath::WebSocket | |
def on_open(env) | |
env.logger.info("WS OPEN") | |
end | |
def on_message(env, msg) | |
env.logger.info("WS MESSAGE: #{msg}") | |
end | |
def on_close(env) | |
# this never get's called | |
env.logger.info("WS CLOSED from User") | |
end | |
def on_error(env, error) | |
env.logger.error error | |
end | |
def response(env) | |
super(env) | |
end | |
end | |
class Server < Goliath::WebSocket | |
def response(env) | |
case env['PATH_INFO'] | |
when '/user' | |
User.new.response(env) | |
when '/admin' | |
Admin.new.reponse(env) | |
end | |
end | |
def on_close(env) | |
# This get's triggered instead of User.on_close | |
env.logger.info "WS CLOSED from Server" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment