Brokr
brokr is a javascript RPC+PUB/SUB via Websocket library that you shouldn't use yet.
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.*
Usage
In the browser
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 build
in the Brokr module root to build thebrokr.web.js
file.
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.
Example with connect
Your node application (lets call it app.js):
var Brokr = 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() method //serve the brokr source on requests to /brokr.js //serve the "public" directory as is (put your index.html here) //and start the webserver ;console; //create a new Brokr object, exposing a single method called pingvar brokr = { //when client requests ping, send with no error and the string "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 portbrokr;
Your ./public/index.html file:
Brokr web demo <!-- request the brokr script -->