update README
[sunshowers.git] / examples / sinshowers.rb
blob62b79792423a81586e2d9611e461a2f45516fd7b
1 # Example of Sunshowers + Sinatra 0.9.4, for use with echo_client.{rb,py}
3 require 'sinatra/base'
4 require 'sunshowers'
6 # There's probably a better/cleaner way to do this, but we're not
7 # very familiar with Sinatra...
8 # Let us know of a better way at sunshowers@librelist.com
9 class Sinatra::Request < Rack::Request
10   include Sunshowers::WebSocket
11 end
13 class Sinshowers < Sinatra::Base
15   get "/echo" do
16     if request.ws?
17       request.ws_handshake!
18       ws_io = request.ws_io
19       ws_io.each do |record|
20         ws_io.write_utf8(record)
21         break if record == "Goodbye"
22       end
23       request.ws_quit!
24     end
25     "You're not using Web Sockets"
26   end
28 end