-
Notifications
You must be signed in to change notification settings - Fork 15
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
321084d
commit dcbabd9
Showing
9 changed files
with
55 additions
and
42 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
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,10 @@ | ||
import { Client } from "../../Client.js" | ||
import { DocumentId } from "../../index.js" | ||
import { connection } from "./connection.js" | ||
import { WebSocket } from "isomorphic-ws" | ||
|
||
export const allConnected = (a: Client, b: Client, documentId?: DocumentId) => | ||
Promise.all<WebSocket>([ | ||
connection(a, b, documentId), | ||
connection(b, a, documentId), | ||
]) |
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,5 @@ | ||
import { Client } from "../../Client.js" | ||
import { disconnection } from "./disconnection.js" | ||
|
||
export const allDisconnected = (a: Client, b: Client) => | ||
Promise.all([disconnection(a, b), disconnection(b, a)]) |
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,15 @@ | ||
import { Client } from "../../Client.js" | ||
import { DocumentId } from "../../index.js" | ||
import { WebSocket } from "isomorphic-ws" | ||
|
||
export const connection = (a: Client, b: Client, documentId?: DocumentId) => | ||
new Promise<WebSocket>(resolve => | ||
a.on("peer-connect", ({ userName, documentId: d, socket }) => { | ||
if ( | ||
userName === b.userName && | ||
// are we waiting to connect on a specific document ID? | ||
(documentId === undefined || documentId === d) | ||
) | ||
resolve(socket) | ||
}) | ||
) |
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,8 @@ | ||
import { Client } from "../../Client.js" | ||
|
||
export const disconnection = (a: Client, b: Client) => | ||
new Promise<void>(resolve => | ||
a.on("peer-disconnect", ({ userName = "" }) => { | ||
if (userName === b.userName) resolve() | ||
}) | ||
) |
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,2 @@ | ||
export const factorial = (n: number): number => | ||
n === 1 ? 1 : n * factorial(n - 1) |
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,3 @@ | ||
import { factorial } from "./factorial.js" | ||
|
||
export const permutationsOfTwo = (n: number) => factorial(n) / factorial(n - 2) |