Skip to content

Instantly share code, notes, and snippets.

@wtip
Last active December 29, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtip/7727444 to your computer and use it in GitHub Desktop.
Save wtip/7727444 to your computer and use it in GitHub Desktop.
PeerJS Data connections test - for some reason this is not working for me.
<!DOCTYPE html>
<html>
<head>
<title>test A - sender</title>
<script type="text/javascript" src="http://cdn.peerjs.com/0.3/peer.js"></script>
<script>
// PeerJS object
var peer = new Peer({ key: 'lwjd5qra8257b9', debug: 3, config: {'iceServers': [
{ url: 'stun:stun.l.google.com:19302' } // Pass in optional STUN and TURN server for maximum network compatibility
]}});
var conn = peer.connect('xqdk2tvj44dfgxbfjx');
conn.on('open', function(){
conn.send('test message received over datachannel');
});
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>test B - receiver</title>
<script type="text/javascript" src="http://cdn.peerjs.com/0.3/peer.js"></script>
<script>
// PeerJS object
var peer = new Peer('xqdk2tvj44dfgxbfjx',{ key: 'lwjd5qra8257b9', debug: 3, config: {'iceServers': [
{ url: 'stun:stun.l.google.com:19302' } // Pass in optional STUN and TURN server for maximum network compatibility
]}});
peer.on('connection', function(conn) {
conn.on('data', function(data){
// Will print 'hi!'
console.log(data);
});
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment