12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <!DOCTYPE HTML>
- <html lang="en">
- <head>
- <title>PeerJS Hello World Code Example</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta http-equiv="Content-Language" content="en-us">
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
- <script type="text/javascript" src="http://cdn.peerjs.com/0/peer.js"></script>
- <script type="text/javascript" src="../dist/peer.js"></script>
- <script>
- // This is a very simple code example. See chat.html for a more involved
- // example.
- $(document).ready(function() {
- var peer1, peer2, peerId1;
- // Create a new Peer with our demo API key, with debug set to true so we can
- // see what's going on.
- peer1 = new Peer({ key: 'lwjd5qra8257b9', debug: true });
- // Create another Peer with our demo API key to connect to.
- peer2 = new Peer({ key: 'lwjd5qra8257b9', debug: true });
- // The `open` event signifies that the Peer is ready to connect with other
- // Peers and, if we didn't provide the Peer with an ID, that an ID has been
- // assigned by the server.
- peer1.on('open', function(id){
- peerId1 = id;
- var c = peer2.connect(peerId1);
- c.on('data', function(data) {
- // When we receive 'Hello', send ' world'.
- $('body').append(data);
- c.send(' world');
- });
- });
- // Wait for a connection from the second peer.
- peer1.on('connection', function(connection) {
- // This `connection` is a DataConnection object with which we can send
- // data.
- // The `open` event firing means that the connection is now ready to
- // transmit data.
- connection.on('open', function() {
- // Send 'Hello' on the connection.
- connection.send('Hello');
- });
- // The `data` event is fired when data is received on the connection.
- connection.on('data', function(data) {
- // Append the data to body.
- $('body').append(data);
- });
- });
- });
- </script>
- </head>
-
- <body>
- </body>
- </html>
|