peer-unavailable.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title></title>
  7. <link rel="stylesheet" href="../style.css" />
  8. </head>
  9. <body>
  10. <h1>PEER-UNAVAILABLE</h1>
  11. <div id="messages"></div>
  12. <div id="error-message"></div>
  13. <script src="/dist/peerjs.js"></script>
  14. <script type="application/javascript">
  15. /**
  16. * @type {typeof import("../..").Peer}
  17. */
  18. const Peer = window.peerjs.Peer;
  19. const connectionErrors = document.getElementById("messages");
  20. const peerErrors = document.getElementById("error-message");
  21. const not_existing_peer = crypto
  22. .getRandomValues(new Uint8Array(16))
  23. .join("");
  24. const peer = new Peer();
  25. peer
  26. .once(
  27. "error",
  28. (error) => void (peerErrors.textContent += JSON.stringify(error)),
  29. )
  30. .once("open", (id) => {
  31. const connection = peer.connect(not_existing_peer);
  32. connection.once(
  33. "error",
  34. (error) =>
  35. void (connectionErrors.textContent += JSON.stringify(error)),
  36. );
  37. });
  38. </script>
  39. </body>
  40. </html>