Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double json encoding in SseConnection #75

Open
spkersten opened this issue Jan 11, 2023 · 5 comments
Open

Double json encoding in SseConnection #75

spkersten opened this issue Jan 11, 2023 · 5 comments

Comments

@spkersten
Copy link

The type of SseConnection.sink is Stream<String>but then before sending (in _setUpListener) the message is JSON encoded. The interface I try to implement expects singly encoded JSON. Could the type of SseConnection.sink be relaxed to Stream<Object> so any JSON-encodable object can be sent?

@grouma
Copy link
Member

grouma commented Jan 11, 2023

The message is JSON encoded before sending over the wire. We decode it into a String here:

jsonDecode((message as MessageEvent).data as String) as String;

Changing this behavior would be a breaking change. Note the resulting String should be singly encoded so I'm not sure what the issue is. Can you provide more details?

@spkersten
Copy link
Author

It currently only allows Strings to be sent. I'd like to send json object (say, a list of strings). So I use json.encode to make it a String, but then _setUpListener encodes it as json again.

I'm not proposing to remove the json encoding (as it would be a break change) but to change the type of SseConnection.sink to Stream<Object> so that in addition to Strings it accepts any json-encodable object.

@grouma
Copy link
Member

grouma commented Jan 12, 2023

The incoming type will have to change which is a breaking change:

Stream<String> get stream => _incomingController.stream;

The String you get on the otherside can be decoded once again to get the obj you want.

@ratzrattillo
Copy link

ratzrattillo commented Jun 3, 2023

I would propose to introduce this breaking change. It makes using the library more difficult, especially for newcomers.
Also, you would not expect this behaviour according to the standard. Why not stick to https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events ?

I wondered also, why there are "Control Messages" like "close" to close the connection. Ideally, this is not done by the library, but by the user. Also, SSE is intended as a one way data transfer. I cannot follow these design decisions, even though they are stated in the Readme.

//Edit:
If the design decisions of this package cannot be followed, maybe it is better to use EventSource from dart:html directly instead.

@radzish
Copy link

radzish commented Jun 29, 2023

Absolutely agree. With current implementation this package is unusable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants