Realtime server push with node.js, WebSockets and Comet
Switch branches/tags
Nothing to show
Pull request Compare This branch is 104 commits behind maccman:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
client
lib
public
.gitignore
LICENSE
README
Rakefile
index.js
server.js

README

# Juggernaut

Juggernaut lets you push data to browser, which means you can do awesome 
things like multiplayer gaming, chat, realtime collaboration and more!

Juggernaut is super simple and easy to get going. 
Juggernaut 2, which is a completely rewrite, is built on node.js, is insanely fast, and can scale horizontally to millions of clients.

## Features
  * node.js server
  * Ruby client
  * Supports the following protocols:
    * WebSocket
    * Adobe Flash Socket
    * ActiveX HTMLFile (IE)
    * Server-Sent Events (Opera)
    * XHR with multipart encoding
    * XHR with long-polling
  * Reconnection support 

## Subscribe (JavaScript)

<script src="http://localhost:8080/application.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
  var jug = new Juggernaut;
  jug.subscribe("channel_name", function(data){
    console.log("Got data: " + data);
  });
</script>

## Publish (Ruby)

Juggernaut.publish("channel_name", {:some => "data"})
Juggernaut.publish(["channel1", "channel2"], "foo")

## Requirements

 * Node.js
 * Redis
 * Ruby
 
node.js requirements:
 * socket.io
 * node-static
 * redis-client
 
## Installation
 
 * Install node.js - http://nodejs.org/
 * Install npm
   >> curl http://npmjs.org/install.sh | sudo sh
 * Install socket.io
   >> sudo npm install socket.io
 * Install node-static
   >> sudo npm install http://github.com/cloudhead/node-static/tarball/master
 * Install redis-client
   >> sudo npm install http://github.com/technoweenie/redis-node-client/tarball/npm
 * Install Redis - http://code.google.com/p/redis/
 * Install the Juggernaut gem (optional):
   >> sudo gem install juggernaut --pre

## Running

Start Redis
>> ./redis-server redis.conf

Download Juggernaut, and start the Juggernaut server:
>> git clone git://github.com/maccman/juggernaut.git
>> cd juggernaut
>> node server.js

That's it! Now go to http://localhost:8080/ to see Juggernaut in action.

Start the server using root if you want Flash support. It needs to open a restricted port.

## Daemonize

http://kevin.vanzonneveld.net/techblog/article/run_nodejs_as_a_service_on_ubuntu_karmic/

# Scaling

Just create more Juggernaut daemons. Put a TCP load balancer in front of them.
Make sure they all connect to the same Redis instance. Use sticky sessions.

## Usage case - Group Chat

<script type="text/javascript" charset="utf-8">
  var jug = new Juggernaut;
  jug.subscribe("/chats", function(data){
    var li = $("<li />");
    li.text(data);
    $("#chats").append(li);
  });  
</script>

Juggernaut.publish("/chats", params[:body])

## Usage case - Private Chat

<script type="text/javascript" charset="utf-8">
  var jug = new Juggernaut;
  jug.subscribe("/chats/<%= current_user.id %>", function(data){
    var li = $("<li />");
    li.text(data);
    $("#chats").append(li);
  });  
</script>

Juggernaut.publish(users.map {|u| "/chats/#{u.id}" }, params[:body])

## Usage case - Model Synchronisation 

# Implement sync_clients on models
  def sync_clients
    users.map(&:id)
  end
  
# Check out client/examples/juggernaut_observer.rb and client/examples/juggernaut_observer.js