grpc-dart icon indicating copy to clipboard operation
grpc-dart copied to clipboard

Enable grpc-web without dart:html

Open sigurdm opened this issue 5 years ago • 9 comments

No fundamental reason to limit the grpc-web support to only web-apps as noted by: https://github.com/grpc/grpc-dart/issues/43#issuecomment-510437952 .

sigurdm avatar Jul 12 '19 07:07 sigurdm

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 https://github.com/improbable-eng/grpc-web/issues/46, and its not too hard rom looking at the code

joeblew99 avatar Aug 07 '19 20:08 joeblew99

@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).

sigurdm avatar Aug 08 '19 07:08 sigurdm

Any examples of this anywhere @sigurdm

We are using flutter web, mobile and desktop with GRPC.

winwisely99 avatar Nov 19 '19 22:11 winwisely99

Not sure I understood. Examples of what?

sigurdm avatar Nov 21 '19 12:11 sigurdm

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.

nichite avatar Sep 11 '20 23:09 nichite

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

songfei avatar Jan 08 '21 07:01 songfei

@mraleph @songfei any chance we can put some heads together to PR/triage the above solution? I can provide some assistance, although I'm not sure where I can fit in.

lukepighetti avatar Apr 06 '21 18:04 lukepighetti

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)!

MaMrEzO avatar Dec 07 '21 17:12 MaMrEzO

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.

roberts-pumpurs avatar Mar 01 '23 22:03 roberts-pumpurs