# finish with `exit` if running within `irb` require 'plezi' class ChatServer def index render 'client' end def on_open return close unless params['id'] @name = params['id'] subscribe "chat" publish "chat", "#{@name} joind the chat." write "Welcome, #{@name}!" end def on_close publish "chat", "#{@name} joind the chat." end def on_message data publish "chat", "#{@name}: #{data}" end end # setup route to html/javascript client path_to_client = File.expand_path( File.dirname(__FILE__) ) Plezi.templates = path_to_client # connect route to controller Plezi.route '/', ChatServer