Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Realtime server push with node.js, WebSockets and Comet
JavaScript Ruby
Branch: master
Pull request Compare This branch is 1 commit ahead, 74 commits behind maccman:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
client
lib
public
vendor
.gitignore
.gitmodules
LICENSE
README.md
Rakefile
index.js
server.js

README.md

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
  • SSL 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

Setup

Running

Start Redis

>> ./redis-server redis.conf

Download Juggernaut, and start the Juggernaut server:

>> git clone git://github.com/maccman/juggernaut.git --recursive
>> cd juggernaut
>> node server.js

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

Flash

Flash is optional, but it's the default fallback for Firefox (until the beta is released). Start the server using root if you want Flash support. It needs to open a restricted port. Also, you need to specify the location of WebSocketMain.swf

Either copy it to your web app root, or set the address like this:

window.WEB_SOCKET_SWF_LOCATION = "http://juggaddress:8080/WebSocketMain.swf"

SSL

Juggernaut has SSL support! To activate, just put create a folder called 'keys' in the 'juggernaut' dir, containing your privatekey.pem and certificate.pem files.

>> mkdir keys
>> cd keys
>> openssl genrsa -out privatekey.pem 1024 
>> openssl req -new -key privatekey.pem -out certrequest.csr 
>> openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem

Then, pass the secure option to Juggernaut:

var juggernaut = new Juggernaut({secure: true})

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 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("/chats", function(data){
    var li = $("<li />");
    li.text(data);
    $("#chats").append(li);
  });  
</script>

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

Usage case - Private Chat

<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("/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

Something went wrong with that request. Please try again.