-
Notifications
You must be signed in to change notification settings - Fork 32
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
1fab840
commit a213661
Showing
6 changed files
with
113 additions
and
62 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@farcaster/auth-relay": patch | ||
--- | ||
|
||
chore: use GRPC hub client |
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,35 @@ | ||
import { getSSLHubRpcClient, HubRpcClient } from "@farcaster/hub-nodejs"; | ||
import { RelayAsyncResult, RelayError } from "./errors"; | ||
import { err, ok } from "neverthrow"; | ||
|
||
export type HubClient = { | ||
host: string; | ||
client: HubRpcClient; | ||
}; | ||
|
||
const MAX_RECEIVE_MESSAGE_LENGTH = 10 * 1024 * 1024; // 10mb | ||
|
||
const clientOptions = { | ||
"grpc.max_receive_message_length": MAX_RECEIVE_MESSAGE_LENGTH, | ||
}; | ||
|
||
export class HubService { | ||
public static async getReadyClient(host: string): RelayAsyncResult<HubClient> { | ||
const client = getSSLHubRpcClient(host, clientOptions); | ||
const res = await this.waitForReadyHubClient(client); | ||
if (res.isErr()) return err(res.error); | ||
|
||
return ok({ | ||
host, | ||
client, | ||
}); | ||
} | ||
|
||
public static waitForReadyHubClient(hubClient: HubRpcClient): RelayAsyncResult<void> { | ||
return new Promise((resolve) => { | ||
hubClient?.$.waitForReady(Date.now() + 500, (e) => { | ||
return e ? resolve(err(new RelayError("unknown", e))) : resolve(ok(undefined)); | ||
}); | ||
}); | ||
} | ||
} |
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