echo_server.js 721 B

123456789101112131415161718192021222324
  1. const Peer = require('../index.js').Peer;
  2. // MAIN -------------------------------------------------------------------------------------------
  3. // Claim this ID on the peerJS signalling server so that clients can connect to it directly
  4. // without having to coordinate this key with each other through other means
  5. const peer = new Peer('abcdefghijklmnopqrstuvwxyz', {debug: 2});
  6. peer.on('open', (localId) => {
  7. console.log(localId);
  8. })
  9. peer.on('connection', (conn) => {
  10. console.log('Got a connection');
  11. conn.on('open', () => {
  12. conn.on('data', (data) => {
  13. console.log(data);
  14. conn.send(`echo: ${data}`);
  15. });
  16. conn.send('Hello, I am the echo server');
  17. })
  18. });