-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): add default ids to channels, create a new event and forwar…
…d messages to the same channel
- Loading branch information
1 parent
4f86e9a
commit 7ab016c
Showing
7 changed files
with
223 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const byteToHex: string[] = [] | ||
|
||
for (let i = 0; i < 256; i++) { | ||
byteToHex[i] = (i + 0x100).toString(16).substr(1) | ||
} | ||
|
||
const unparse = (buf: Array<number>, offset?: number) => { | ||
let i = offset || 0 | ||
const bth = byteToHex | ||
|
||
return ( | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
"-" + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
"-" + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
"-" + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
"-" + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] + | ||
bth[buf[i++]] | ||
) | ||
} | ||
|
||
const min = 0 | ||
const max = 256 | ||
const RANDOM_LENGTH = 16 | ||
|
||
export const rng = () => { | ||
const result = new Array<number>(RANDOM_LENGTH) | ||
|
||
for (let j = 0; j < RANDOM_LENGTH; j++) { | ||
result[j] = 0xff & (Math.random() * (max - min) + min) | ||
} | ||
|
||
return result | ||
} | ||
|
||
export const uuidv4 = () => { | ||
const rnds: number[] = rng() | ||
|
||
rnds[6] = (rnds[6] & 0x0f) | 0x40 | ||
rnds[8] = (rnds[8] & 0x3f) | 0x80 | ||
|
||
return unparse(rnds) | ||
} |
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
Oops, something went wrong.