-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a0c9ef
commit cbeff9f
Showing
3 changed files
with
138 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title></title> | ||
<link rel="stylesheet" href="../style.css" /> | ||
</head> | ||
<body> | ||
<h1>ID-TAKEN</h1> | ||
<div id="messages"></div> | ||
<div id="error-message"></div> | ||
<script src="/dist/peerjs.js"></script> | ||
<script type="module"> | ||
/** | ||
* @type {typeof import("../..").Peer} | ||
*/ | ||
const Peer = window.peerjs.Peer; | ||
|
||
const messages = document.getElementById("messages"); | ||
const errorMessage = document.getElementById("error-message"); | ||
|
||
// Peer A should be created without an error | ||
try { | ||
const peerA = await new Peer(); | ||
// Create 10 new `Peer`s that will try to steel A's id | ||
let peers_try_to_take = Array.from( | ||
{length: 10}, | ||
async (_, i) => { | ||
try{ | ||
await new Peer(peerA.id) | ||
throw `Peer ${i} failed! Connection got established.` | ||
} catch (error) { | ||
if (error.type === "unavailable-id") { | ||
return `ID already taken. (${i})`; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
); | ||
await Promise.all(peers_try_to_take) | ||
messages.textContent = "No ID takeover" | ||
} catch (error) { | ||
errorMessage.textContent += JSON.stringify(error); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters