|
@@ -10,21 +10,15 @@
|
|
|
<script>
|
|
|
|
|
|
var conn;
|
|
|
-
|
|
|
// Connect to PeerJS, have server assign an ID instead of providing one
|
|
|
var peer = new Peer({key: 'lwjd5qra8257b9', debug: true});
|
|
|
-
|
|
|
-
|
|
|
peer.on('open', function(id){
|
|
|
$('#pid').text(id);
|
|
|
- });
|
|
|
-
|
|
|
+ });
|
|
|
// Await connections from others
|
|
|
peer.on('connection', connect);
|
|
|
-
|
|
|
function connect(c) {
|
|
|
$('#chat_area').show();
|
|
|
-
|
|
|
conn = c;
|
|
|
$('#messages').empty().append('Now chatting with ' + conn.peer);
|
|
|
conn.on('data', function(data){
|
|
@@ -32,9 +26,7 @@
|
|
|
});
|
|
|
conn.on('close', function(err){ alert(conn.peer + ' has left the chat.') });
|
|
|
}
|
|
|
-
|
|
|
$(document).ready(function() {
|
|
|
-
|
|
|
// Conect to a peer
|
|
|
$('#connect').click(function(){
|
|
|
var c = peer.connect($('#rid').val());
|
|
@@ -43,7 +35,6 @@
|
|
|
});
|
|
|
c.on('error', function(err){ alert(err) });
|
|
|
});
|
|
|
-
|
|
|
// Send a chat message
|
|
|
$('#send').click(function(){
|
|
|
var msg = $('#text').val();
|
|
@@ -51,13 +42,15 @@
|
|
|
$('#messages').append('<br>You:<br>' + msg);
|
|
|
$('#text').val('');
|
|
|
});
|
|
|
-
|
|
|
+ // Show browser version
|
|
|
+ $('#browsers').text(navigator.userAgent);
|
|
|
});
|
|
|
|
|
|
</script>
|
|
|
</head>
|
|
|
|
|
|
<body>
|
|
|
+
|
|
|
Your PeerJS id is : <span id="pid"></span><br><br>
|
|
|
Connect to peer: <input type="text" id="rid" placeholder="Someone else's id">
|
|
|
<input type="button" value="Connect" id="connect"><br><br>
|
|
@@ -69,5 +62,12 @@
|
|
|
<input type="button" value="Send" id="send">
|
|
|
</div>
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ <br><br><br>
|
|
|
+ <p style="font-size: 10px;">Your browser version: <span id="browsers"></span><br>
|
|
|
+ Currently <strong>Google Chrome 26.0.1403.0 or above</strong> is required (Dev or Canary channels)</strong><br><br>For more up to date compatibility information see <a href="http://peerjs.com/status">PeerJS WebRTC Status</a><br><br>Note that this demo may also fail if you are behind stringent firewalls or both you and the remote peer and behind symmetric NATs.</p>
|
|
|
+
|
|
|
</body>
|
|
|
</html>
|