Sha256: f39c0b04f2b561278bbff4b5e24490dacfa742910d1402384ae97bda0d21a7bd

Contents?: true

Size: 652 Bytes

Versions: 1

Compression:

Stored size: 652 Bytes

Contents

require "puma"
require "rack/handler/puma"
require "drunkmonkey"

sockets = {}
Rack::Handler::Puma.run(Rack::Builder.new{
  root = File.dirname(__FILE__)
  use DrunkMonkey::Middleware do
    on :open do |socket|
      sockets[socket] = ""
    end
    
    on :message do |socket,msg|
      if sockets[socket].empty?
        sockets[socket] = msg
        socket.push "Welcome, #{msg}!"
      else
        name = sockets[socket]
        sockets.each{|s,_|s.push "#{name}: #{msg}"}
      end
    end
  end
  
  use Rack::Static, urls:[""], index:"index.html", root:"#{root}/public"
  run -> env { [404, {'Content-Type' => 'text/html'}, ['Not Found']] }
})

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
drunkmonkey-0.0.1 sample/app.rb