Websocket RPC+PUB/SUB library
If you want to anyway, go get it with
npm install brokr
I am quite serious with my versioning of this, so please install a specific version to avoid breaking your application.
I follow Semantic Versioning 2.0.*
If you need to use Brokr in the browser, you can
- Use the included connect middleware
Brokr.middleware(url)to serve a browser friendly Brokr version.
- Use the
Brokr.browserify(callback)function to get the source as a string.
- Use the included build tool. Simply run
make buildin the Brokr module root to build the
Note that i am writing a better more optimised version exclusively for the browser, and that the current browser implementation works, but have a gigantic footprint.
The browser version will have it's own repository, will properly not be avaiable through npm.
Your node application (lets call it app.js):
var Brokr = require'brokr'connect = require'connect';//let us choose a reasonable port numbervar port = 4000;//Start a http.Server as you usually would//Here we are using connect() to take advantage of//brokr's built in middleware for serving the static clientvar server =//our http.Server instance as returned by connect's .listen() methodconnect//serve the brokr source on requests to /brokr.jsuseBrokrstatic'/brokr.js'//serve the "public" directory as is (put your index.html here)useconnectstatic__dirname+'/public'//and start the webserverlistenport;console.log"listening on port "+port;//create a new Brokr object, exposing a single method called pingvar brokr =//when client requests ping, send with no error and the string "pong"responsenull "pong";;//attach our brokr to our server instance using the .listen() method//The listen method could also take a port number which would start//a new server on that portbrokrlistenserverthenconsole.log"brokr listening on port "+port;done;
Your ./public/index.html file:
Brokr web demo<!-- request the brokr script -->