pratikbaid3 / flutter_client_sse

Dart package to help consume SSE API. Consumes server sent events by returning parsed model of the event, id, and the data
https://pub.dev/packages/flutter_client_sse
MIT License
40 stars 41 forks source link

Browser support not working #5

Open skaba opened 2 years ago

skaba commented 2 years ago

Should the browser version wrap dart sse client (https://pub.dev/documentation/sse/latest/client_sse_client/SseClient-class.html) instead of using http client?

pratikbaid3 commented 2 years ago

The package was tested and intended for mobile use. Feel free to create a PR if you get it working on web.

foxB612 commented 2 years ago

That library uses EventSource from dart:html, which afaik is the only working way to use sse on flutter web. However, importing dart:html will raise Error: Not found when targeting at mobile platforms. And dart/flutter doesn't support conditional import, so it seems that we can't have both mobile and browser compatibility at library level. (See below)

srix55 commented 2 years ago

dart/flutter doesn't support conditional import

@foxB612 I have seen conditional imports in some libraries that I use.

export 'send_port_io.dart' if (dart.library.html) 'send_port_web.dart';

These are from worker_manager package.

import 'package:worker_manager_v2/src/worker/worker_web.dart'
    if (dart.library.io) 'package:worker_manager_v2/src/worker/worker_io.dart';
foxB612 commented 2 years ago

@srix55 Thank you for pointing out that. I did get it wrong. According to the document conditional export/import is supported.

AdrianRechina commented 1 year ago

Is it still not working on the web? I do not receive any event until it is disconnected that they all arrive

cybertheory commented 2 months ago

The package was tested and intended for mobile use. Feel free to create a PR if you get it working on web.

Then remove the Web tag on pub.dev this prevents misunderstandings.

cybertheory commented 2 months ago

For everyone else

I found this issue regarding http on browser for streams

https://github.com/dart-lang/http/issues/593

Looks like streaming with http buffers the data first which is an issue I am hitting