Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
119 lines (98 sloc) 2.71 KB
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>A Peer Bind Example</title>
<script src="jquery-1.7.min.js"></script>
<script src="jQuery.peerbind.js"></script>
<script type="text/javascript">
var nicks = {}; // nasty global to store nicknames..
var options = {
//Leaving as is allows for localhost / Local LAN IP to be used allowing empty string is in the todo
'endpointprefixes': [""],
//Set to your url, IP, or localhost (for local testing), moving port to config on the todo
'endpoint': "localhost:8080",
//string, geo, ip, url
'type': "string",
//Required for type: string only
'regstring': "PeerBindChatExample",
//Required only for geo
'coords': {
lat: 0,
long: 0
'coordsSet': false, //to remove - unused
//Polling interval in milliseconds
'pollinterval': 500,
'pollmax': 31000,
//Callback function to be called after registration with the server.
'regcallback': null
//This only works for people already connected
//Will have change this to be a post back on a custom "arrived" trigger I think.
peer: function(e){
//yay for globals?
nicks[e.srcPeer] = e.peerData;
local: function(e){
addChat("Nickname set", e.peerData);
//Bind a change event for the nickname input
$("#message").peerbind(options,"change", {
peer: function(e) {
addChat(e.srcPeer, e.peerData);
local: function(e) {
function addChat(user,msg) {
//If no nick is stored, just display the users uid
var nick = user;
if (nicks[user]) {
nick = nicks[user];
$(".chat").append( $("<div class='message'/>").text( nick + ": " + msg ));
body {
font-family: verdana, arial, sans;
font-size: 14px;
background-color: #BFC9FF;
.chat {
height: 90%;
.new_message {
.message {
font-size: 0.8em;
<h1>Peerbind Chat Example</h1>
<legend>Nickname (optional)</legend>
<div class="settings">
<input type="textbox" id="nickname"><button id="">set</button><br/>
<div class="chat"></div>
<div class="new_message">
<input type="textbox" id="message"><button id="send">send</button>