Skip to content

Instantly share code, notes, and snippets.

@majkrzak
Created May 6, 2014 17:22
Show Gist options
  • Save majkrzak/a0340a8495e32958fabf to your computer and use it in GitHub Desktop.
Save majkrzak/a0340a8495e32958fabf to your computer and use it in GitHub Desktop.
<doctype html>
<html>
<head>
<script src="http://cdn.peerjs.com/0.3/peer.min.js"></script>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
var peer = null;
var conn = null;
function create()
{
peer = new Peer({key: 'lwjd5qra8257b9'});
peer.on('open',function(){
$('#my').val(peer.id);
});
peer.on('connection',function(connection){
conn = connection;
$('#ym').val(conn.peer);
conn.on('data',function(data){
$('#content').append($('<p>'+data+'</p>'));
});
});
}
function connect()
{
conn = peer.connect($('#ym').val());
conn.on('data',function(data){
$('#content').append($('<p>'+data+'</p>'));
});
}
function send()
{
conn.send($('#in').val());
$('#content').append($('<p>'+$('#in').val()+'</p>'));
$('#in').val('');
}
</script>
</head>
<body>
<input id="my" type="text" disabled>
<button onclick="create()">Create</button>
<input id="ym" type="text" required>
<button onclick="connect()">Connect</button>
<div id="content">
</div>
<input id="in" type="text"></input>
<button onclick="send()">Send</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment