Enable grpc-web without dart:html
sigurdm opened this issue ยท 9 comments
No fundamental reason to limit the grpc-web support to only web-apps as noted by: #43 (comment) .
Glad someone else raised this !!
It would be amazing to be able to use GRPC for Flutter Web, Mobile and Desktop. So much less code to maintan.
@sigurdm Can you explain by what you mean "without dart:html" please ?
I am wanting to expose a golang Server API to both Flutter and Flutter Web.
https://github.com/grpc-ecosystem/grpc-gateway does not support Web sockets
Then again Long Polling is another option to be able to push events at least to the Flutter Web clients. SSE is not supported by Microsoft Edge ( still !! ).
https://github.com/improbable-eng/grpc-web does support web sockets, but only has TypeScript and JS client support.
But it looks like someone already raised to have Dart support here improbable-eng/grpc-web#46, and its not too hard rom looking at the code
@sigurdm Can you explain by what you mean "without dart:html" please ?
I can try to elaborate a little:
When dart is run on a mobile device as flutter or on the command line via the VM it cannot import dart:html
. (Only dart compiled to JavaScript and run in the browser as in flutter-web has access to this library)
Currently the dart grpc-web implementation relies on HttpRequest (the same as XmlHttpRequest in javascript) from dart:html
.
It should be possible to instead use https://pub.dev/packages/http for making the requests. It is supported both on the VM and in the browser.
Non-web grpc is based on http2 that is only available in the vm settings (flutter and command line).
Any examples of this anywhere @sigurdm
We are using flutter web, mobile and desktop with GRPC.
Not sure I understood. Examples of what?
One this this breaks is the ability to send credentials with web requests. This was previously possible with dart:html
import, but I don't believe I see such options anywhere in the Request
interface from the HTTP library.
I have implemented this, and it can already work on my project. I haven't written the test yet. I will send pull request after I finish it. Welcome to review my code.
https://github.com/songfei/grpc-dart/blob/master/lib/src/client/transport/io_xhr_transport.dart
No fundamental reason to limit the grpc-web support to only web-apps as noted by: #43 (comment) .
grpc-web
is some sort of protocol and not limited to call it with JS on Web, and I cannot understand why this implementation limit it with xhr and dart:html :|
Our endpoint just supports grpc-web and I cannot call our services in Flutter(NOT Flutter-Web)!
Is there any progress regarding this? Platforms like DigitalOcean App Platform do not support http2, meaning I cannot use pure grpc calls there. This also means that I cannot use grpc-web with my flutter app. My current solution is to deploy elsewhere because grpc-web support on flutter mobile is impossible.