farcasterxyz / hub-monorepo

Implementation of the Farcaster Hub specification and supporting libraries for building applications on Farcaster
https://www.thehubble.xyz
MIT License
708 stars 404 forks source link

feat: @farcaster/js should run in browsers #573

Closed varunsrin closed 1 year ago

varunsrin commented 1 year ago

What is the feature you would like to implement?

Get @farcaster/js compiling in browsers

Why is this feature important?

Single-page and stand alone client applications will be able to interface directly with Hubs without a server.

Will the protocol spec need to be updated??

No

Additional context

pfletcherhill commented 1 year ago

Related other tickets to consolidate:

kcchu commented 1 year ago

My two cents:

  1. I am uncertain about the use case of calling Hub RPC from web browsers. The RPC methods are primitive compare with Merkle API (e.g. Hub RPC don't handle threading). A web browser client couldn't do much thing without talking to a higher-level API server (e.g. Merkle API, Farcaster Indexer).
  2. Client-Hub communication makes sense if the plan is to implement most functionalities needed by a client in Hub RPC.
  3. And alternative approach to (2) is releasing a separated Farcaster API services. Hub remains as a service that is primarily for distributing messages and syncing with the peer-to-peer network. The Farcaster API talks to a Hub and expose higher level API for clients (it may implement add-on functions on top of Hub like searching).
  4. Even if grpc-web is to be implemented in Hub, RPC between Hubs should stay on standard gRPC because it supports the most programming languages and much more efficient.
  5. There is no Typescript implementation of grpc-web proxy. A solution is embedding a Envoy proxy in the docker image to serve the grpc-web port.
pfletcherhill commented 1 year ago

Supporting web browsers isn't an immediate problem, but in the medium term it lowers the barrier to entry for community members looking to make something using farcaster, which is good. I imagine some devs will want very basic access and choose to use the hub RPC for reading/writing and others will use more feature-rich APIs or build their own backends for indexing data. There's certainly an opportunity for community members to make their own indexing services and APIs on top of hubs for many use cases, similar to Alchemy's various APIs for ethereum.

We should support both grpc and grpc-web simultaneously using a proxy (I made it work with Envoy, as you mentioned, though there may be other options too). So hub-to-hub communication will continue to use gRPC directly.

varunsrin commented 1 year ago

we should see whether farcaster/js works by default in serverless platforms like vercel. if it does, we can punt this to a later milestone

pfletcherhill commented 1 year ago

High-level goal:

Create a new package called @farcaster/hub-web that exports the same methods as @farcaster/hub-nodejs except with a grpc-web client instead of a grpc one that works in browsers.

Work to be done:

dawsbot commented 7 months ago

It appears this is solved, yet the readme states that it is not

I've supplied a PR to remove that! Let me know if this looks right 🙏 https://github.com/farcasterxyz/hub-monorepo/pull/1865