Breakout is a light framework for routing messages among web browsers and workers using WebSockets.
First, you should follow the instructions for getting started with the EM-Breakout server.
Next, in a new terminal, clone this repository and change to the examples directory. There are no dependencies for using the gem, but the example web app requires Sinatra, so make sure that is installed.
Before your browser can connect, you'll need to start a worker process by running the worker_app.rb file. (You're already running the em-breakout server, right?)
- Echo: The browser sends a message with every keypress and displays every message received; the worker echoes every message received
- Ping: The worker sends a valid WebSocket URL in response to each message; using the URLs received from the worker, the browser continues to open additional WebSockets, and for each one displays the time it takes for each ping. After awhile, try running a second worker to speed up response times.
- Chat: A simple chatroom that demonstrates the notification feature. You should try using two browsers for this, however the example will not work correctly with multiple workers, as described in the chat.rb file.
- Q: How do I use this with a Rails project? A: The details depend on your deployment scenario, but the trickiest part should be adjusting the breakout.yml that is generated so that browsers and workers can connect to wherever the em-breakout server is running. The other steps include adding the breakout gem to your dependencies (gem 'breakout', '0.0.1'), copying the echo.rb example worker and implementing your own do_work method (make sure your Rails environment is loaded in the worker so you can access models), copying the worker_app.rb to help run your workers, and using Breakout.browser_url in the appropriate view to allow your clients to connect to your workers.
Copyright (c) 2011 Steve Masterman. See LICENSE for details.