This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connect): use stable prot for builtin server
- Loading branch information
1 parent
81fa7fd
commit 9175a81
Showing
3 changed files
with
19 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Calculates a stable port number based on the device id | ||
*/ | ||
export const portForDevice = ({ deviceId }: { deviceId: string }): number => { | ||
let hash = 0 | ||
for (let i = 0; i < deviceId.length; i++) { | ||
hash = (hash << 5) - hash + deviceId.charCodeAt(i) | ||
hash |= 0 // Convert to 32bit integer | ||
} | ||
return 1024 + Math.round((hash / Math.pow(2, 31)) * (65535 - 1024)) | ||
} |
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