Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 2.26 KB

README.md

File metadata and controls

53 lines (37 loc) · 2.26 KB

Peerbind

Peerbind is an event binding library that allows JavaScript-initiated interactions between website visitors.

Originally Authored by Matt Amacker https://twitter.com/#!/peerbind an Engineer for A9.com. This is an adaption to help people get up and running with their own endpoints or Peerbind in general.

Client side setup

Include jquery.js and jQuery.peerbind.js into your webpage:

<script src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script src="jQuery.peerbind.js"></script>

Bind an event to a DOM element:

<script>
  $(document).ready(function() {
    function addChat(msg) {
      $("#chats").append("<br>"+msg);
    }
    
    $("input").peerbind("change", {
      peer:  function(e) { addChat(e.srcPeer + ": " + e.peerData);},
      local: function(e) { addChat("You: " + e.peerData); $(this).val("");}
    });
  });
</script>
Type a message: <input type="text"> 
<div id="chats"></div>

That's it! Have a look at the documentation for other parts of the API.

Running your own Peerbind server (endpoint)

You'll need to have node.js installed to run the Peerbind server. For installation instructions see the node.js wiki. Once you've installed node, you can run the Peerbind server with the following command:

node peerbindserver.js

This server will serve files relative from the calling directory. You can specify the public directory with the first argument after the server:

node peerbindserver.js /var/www/peerbind/
node peerbindserver.js ~/peerbind

The index.html file included in this repository has some example code to set up a simple chat app that can run over a localhost node.js server and your browser.