grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
860 stars 271 forks source link

Understanding the grpc-web example #570

Closed Gene-Dana closed 2 years ago

Gene-Dana commented 2 years ago

Hi there 👋🏼 I really appreciate the time and effort this community puts into these examples ! They are very helpful !

I'm seeking to understand a little more about docker, grpc, and dart and I want to understand how I can apply grpc to call js libraries in dart (in particular I'd like to run this IPFS library in a flutter app)

I'm seeking to understand this: Are we using grpc in this dart web app to interface with this JS library https://github.com/grpc/grpc-web?

mraleph commented 2 years ago

gRPC is not going to help you to run JavaScript libraries in Dart. gRPC is just a RPC protocol used for client-server communication.

If you want to include a JavaScript libraries into a Flutter app which runs natively (e.g. desktop or mobile - as opposed to web), then you need to start by finding a JavaScript engine and including that into your application, because there is no other way to execute JavaScript (as native Flutter is not JS based). Two main options is to take a pure JS engine package (e.g. https://pub.dev/packages/flutter_js, https://pub.dev/packages/flutter_jscore, https://pub.dev/packages/flutter_qjs - can't say anything about the quality of these though) or use a WebView (e.g. https://pub.dev/packages/webview_flutter). After you find a suitable engine (or write one yourself) you can start looking at making https://github.com/ipfs/js-ipfs run in it. It will probably run out of the box in WebView (because it seems to support browser), but running it on a standalone JS engine might require modifications if it expects certain browser or node.js specific APIs to be present.

On Flutter Web you can use Dart-to-JS interoperability to include this library into your Flutter Web application.

mraleph commented 2 years ago

That being said: it is probably better to just use a Dart implementation of the IPFS protocol. Maybe something like this package: https://github.com/tobimd/ipfs_http_rpc

Gene-Dana commented 2 years ago

Thank you so much !!!

Gene-Dana commented 2 years ago

That being said: it is probably better to just use a Dart implementation of the IPFS protocol. Maybe something like this package: https://github.com/tobimd/ipfs_http_rpc

The big problem with this example is that it requires running a local node somewhere (a daemon server) and every single pub.dev package for IPFS excludes the daemon.

I understand this is unrelated, I'm just researching how I can run a daemon from the phone and interact with it (ideally with grpc)

mraleph commented 2 years ago

Do you really want to run daemon on the phone? (i.e. you want to expose phone's filesystem through IPFS?)