-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from appwrite/dev
fix: close realtime sockets
- Loading branch information
Showing
5 changed files
with
33 additions
and
10 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
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 |
---|---|---|
@@ -1,9 +1,28 @@ | ||
export class ID { | ||
// Generate an hex ID based on timestamp | ||
// Recreated from https://www.php.net/manual/en/function.uniqid.php | ||
static #hexTimestamp(): string { | ||
const now = new Date(); | ||
const sec = Math.floor(now.getTime() / 1000); | ||
const msec = now.getMilliseconds(); | ||
|
||
// Convert to hexadecimal | ||
const hexTimestamp = sec.toString(16) + msec.toString(16).padStart(5, '0'); | ||
return hexTimestamp; | ||
} | ||
|
||
public static custom(id: string): string { | ||
return id | ||
} | ||
|
||
public static unique(): string { | ||
return 'unique()' | ||
|
||
public static unique(padding: number = 7): string { | ||
// Generate a unique ID with padding to have a longer ID | ||
const baseId = ID.#hexTimestamp(); | ||
let randomPadding = ''; | ||
for (let i = 0; i < padding; i++) { | ||
const randomHexDigit = Math.floor(Math.random() * 16).toString(16); | ||
randomPadding += randomHexDigit; | ||
} | ||
return baseId + randomPadding; | ||
} | ||
} | ||
} |