Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
119 lines (98 sloc) 2.71 KB
<!DOCTYPE HTML>
<html>
<head>
<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..
$(document).ready(function(){
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.
$("#nickname").peerbind(options,"change",{
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) {
addChat("You",e.peerData);
$("#message").val("");
}
});
});
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 ));
}
</script>
<style>
body {
font-family: verdana, arial, sans;
font-size: 14px;
background-color: #BFC9FF;
}
.chat {
height: 90%;
min-height:30px;
}
.new_message {
height:10%;
}
.message {
font-size: 0.8em;
}
</style>
</head>
<body>
<h1>Peerbind Chat Example</h1>
<fieldset>
<legend>Nickname (optional)</legend>
<div class="settings">
<input type="textbox" id="nickname"><button id="">set</button><br/>
</div>
</fieldset>
<fieldset>
<legend>Messages</legend>
<div class="chat"></div>
<div class="new_message">
<input type="textbox" id="message"><button id="send">send</button>
</div>
</fieldset>
</body>
</html>
Something went wrong with that request. Please try again.