-
-
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.
Merge branch 'binarypack2.1' into rc
- Loading branch information
Showing
28 changed files
with
4,959 additions
and
4,390 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ npm-debug.log | |
.DS_STORE | ||
|
||
test/output | ||
browserstack.err | ||
.tscache | ||
test/public | ||
.vscode/ |
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 was deleted.
Oops, something went wrong.
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,24 @@ | ||
import { commit_data } from "../data.js"; | ||
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs"; | ||
|
||
const Encoder = new TextEncoder(); | ||
const Decoder = new TextDecoder(); | ||
|
||
/** @param {unknown[]} received */ | ||
export const check = (received) => { | ||
expect(received).to.be.an("array").with.lengthOf(commit_data.length); | ||
const commits_as_arraybuffer = commit_data.map( | ||
(blob) => Encoder.encode(JSON.stringify(blob)).buffer, | ||
); | ||
expect(received).to.deep.equal(commits_as_arraybuffer); | ||
const parsed_received = received.map((r) => JSON.parse(Decoder.decode(r))); | ||
expect(parsed_received).to.deep.equal(commit_data); | ||
}; | ||
/** | ||
* @param {import("../peerjs").DataConnection} dataConnection | ||
*/ | ||
export const send = async (dataConnection) => { | ||
for (const commit of commit_data) { | ||
await dataConnection.send(new Blob([JSON.stringify(commit)])); | ||
} | ||
}; |
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,25 @@ | ||
import { commit_data } from "../data.js"; | ||
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs"; | ||
|
||
const Encoder = new TextEncoder(); | ||
|
||
/** @param {unknown[]} received */ | ||
export const check = (received) => { | ||
expect(received).to.be.an("array").with.lengthOf(commit_data.length); | ||
const commits_as_arraybuffer = commit_data.map( | ||
(blob) => Encoder.encode(JSON.stringify(blob)).buffer, | ||
); | ||
expect(received).to.deep.equal(commits_as_arraybuffer); | ||
}; | ||
/** | ||
* @param {import("../peerjs").DataConnection} dataConnection | ||
*/ | ||
export const send = async (dataConnection) => { | ||
for (const commit of commit_data) { | ||
await dataConnection.send( | ||
new File([JSON.stringify(commit)], "commit.txt", { | ||
type: "dummy/data", | ||
}), | ||
); | ||
} | ||
}; |
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
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,34 @@ | ||
<!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="application/javascript"> | ||
/** | ||
* @type {typeof import("../..").Peer} | ||
*/ | ||
const Peer = window.peerjs.Peer; | ||
|
||
const messages = document.getElementById("messages"); | ||
|
||
const peer = new Peer(); | ||
peer | ||
.once( | ||
"error", | ||
(error) => void (messages.textContent = JSON.stringify(error)), | ||
) | ||
.once("open", (id) => { | ||
peer.disconnect(); | ||
peer.connect("otherid"); | ||
}); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!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="application/javascript"> | ||
/** | ||
* @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 | ||
const peerA = new Peer() | ||
.once( | ||
"error", | ||
(err) => (errorMessage.textContent += JSON.stringify(err)), | ||
) | ||
.once("open", (id) => { | ||
// Create 10 new `Peer`s that will try to steel A's id | ||
let peers_try_to_take = Array.from( | ||
{ length: 10 }, | ||
(_, i) => | ||
new Promise((resolve, reject) => | ||
new Peer(id) | ||
.once("open", () => | ||
reject(`Peer ${i} failed! Connection got established.`), | ||
) | ||
.once("error", (error) => { | ||
if (error.type === "unavailable-id") { | ||
resolve(`ID already taken. (${i})`); | ||
} else { | ||
reject(error); | ||
} | ||
}), | ||
), | ||
); | ||
Promise.all(peers_try_to_take) | ||
.then(() => (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { browser, $ } from "@wdio/globals"; | ||
class PeerPage { | ||
get messages() { | ||
return $("div[id='messages']"); | ||
} | ||
|
||
get errorMessage() { | ||
return $("div[id='error-message']"); | ||
} | ||
|
||
waitForMessage(right: string) { | ||
return browser.waitUntil( | ||
async () => { | ||
const messages = await this.messages.getText(); | ||
return messages.startsWith(right); | ||
}, | ||
{ timeoutMsg: `Expected message to start with ${right}`, timeout: 10000 }, | ||
); | ||
} | ||
|
||
async open(test: string) { | ||
await browser.url(`/e2e/peer/${test}.html`); | ||
} | ||
} | ||
|
||
export default new PeerPage(); |
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,20 @@ | ||
import P from "./peer.page.js"; | ||
import { browser, expect } from "@wdio/globals"; | ||
|
||
describe("Peer", () => { | ||
it("should emit an error, when the ID is already taken", async () => { | ||
await P.open("id-taken"); | ||
await P.waitForMessage("No ID takeover"); | ||
expect(await P.errorMessage.getText()).toBe(""); | ||
}); | ||
it("should emit an error, when the server is unavailable", async () => { | ||
await P.open("server-unavailable"); | ||
await P.waitForMessage('{"type":"server-error"}'); | ||
expect(await P.errorMessage.getText()).toBe(""); | ||
}); | ||
it("should emit an error, when it got disconnected from the server", async () => { | ||
await P.open("disconnected"); | ||
await P.waitForMessage('{"type":"disconnected"}'); | ||
expect(await P.errorMessage.getText()).toBe(""); | ||
}); | ||
}); |
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,31 @@ | ||
<!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="application/javascript"> | ||
/** | ||
* @type {typeof import("../..").Peer} | ||
*/ | ||
const Peer = window.peerjs.Peer; | ||
|
||
const messages = document.getElementById("messages"); | ||
const errorMessage = document.getElementById("error-message"); | ||
|
||
new Peer({ | ||
host: "thisserverwillneverexist.example.com", | ||
}).once( | ||
"error", | ||
(error) => void (messages.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
Oops, something went wrong.