stevenroose / dart-eventsource

A client and server implementation of Server-Side Events.
MIT License
56 stars 49 forks source link

Ability to close eventsource #14

Closed rvowles closed 3 years ago

rvowles commented 4 years ago
rvowles commented 4 years ago

Sorry about the reformatting, thats dartfmt.

stevenroose commented 4 years ago

It's been a while since I did any Dart development.

I'm trying to run the tests for this package and I'm getting this error:

$ pub run test 
Precompiling executable... (5.6s)
Failed to precompile test:test:
../../../.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.5/lib/src/multi_headers.dart:78:8: Error: The method 'MultiHeaders.add' has fewer named arguments than those of overridden method 'HttpHeaders.add'.
  void add(String name, Object value) {
       ^
org-dartlang-sdk:///sdk/lib/_http/http.dart:694:8: Context: This is the overridden method ('add').
  void add(String name, Object value,
       ^
../../../.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.5/lib/src/multi_headers.dart:105:8: Error: The method 'MultiHeaders.set' has fewer named arguments than those of overridden method 'HttpHeaders.set'.
  void set(String name, Object value) {
       ^
org-dartlang-sdk:///sdk/lib/_http/http.dart:703:8: Context: This is the overridden method ('set').
  void set(String name, Object value,
       ^

Any chance this is due to your change or any chance you could help resolve this error?

rvowles commented 4 years ago

Sure!

rvowles commented 4 years ago

hrm:

dart-eventsource git:(feature/close-on-last-stream) ✗ pub get   
Resolving dependencies... 
Got dependencies!
➜  dart-eventsource git:(feature/close-on-last-stream) ✗ pub run test
Precompiling executable... (10.0s)
Precompiled test:test.
00:01 +3: All tests passed!  
stevenroose commented 3 years ago

@rvowles why did you close this?

rvowles commented 3 years ago

I was not planning on resolving any of the issues raised, so rather than wasting your & others time, I closed & dropped it. It is only polite!

selankon commented 3 years ago

Hey @rvowles, I still don't understand why you deleted your branch if the work was almost done, this job was useful for us!

Thanks anyway!

rvowles commented 3 years ago

@selankon its a simple set of changes, you can reapply them and resubmit yourself?

selankon commented 3 years ago

Yes for sure (:

git checkout -b close-on-last-stream
git pull origin 825cc2d572253a03b66cb5996232ec8e564747bc

Thanks!

selankon commented 3 years ago

Anyway this code is not working at all.

If I do this:

StreamSubscription<Event> streamSubscription;

var eventSource =
await EventSource.connect(reqUrl,
  method: "POST",
  body: jsonEncode(body),
  headers: {
    HttpHeaders.authorizationHeader:
    basicAuth
  },
  closeOnLastListener: true,
);

streamSubscription = eventSource.listen((Event event) {
  // Deserialize the message
  streamSubscription.cancel();
});

The second time I execute this code I get the error NoSuchMethodError: The method 'add' was called on null. here.

Not sure why, because I'm instantiating the eventSource each time, is strange :thinking:

rvowles commented 3 years ago

https://stackoverflow.com/questions/34261928/can-server-sent-events-sse-with-eventsource-pass-parameter-by-post

You cannot use POST, only GET.

selankon commented 3 years ago

Do you think this cause the error? Our server only listen POST calls for some non relevant reason

selankon commented 3 years ago

This error happen even using GET