dio
dio copied to clipboard
ServerSendEvent support for Flutter Web
Request Statement
When request for ServerSendEvent stream on TargetPlatform: Web, it response with a UnsupportedError: RawSocket constructor
Stream<T> requestForServerSendEventStream<T>(String url, Map<String, dynamic> request,
{required void Function(CancelData cancelData) onCancel}) {
final controller = StreamController<T>.broadcast();
final cancelData = CancelData(cancelToken: CancelToken());
try {
onCancel(cancelData);
_dio
.post(url,
cancelToken: cancelData.cancelToken,
data: json.encode(request),
options: Options(responseType: ResponseType.stream))
.then((it) {
it.data.stream.listen((it) {
// ...
}, onDone: () {
controller.close();
}, onError: (err, t) {
// ...
});
}, onError: (err, t) {
// ...
});
} on DioException catch (e) {
// ...
}
return controller.stream;
}
Solution Brainstorm
No response
How do you initialize dio? RawSocket is a dart:io class, which means it's unavailable on web.
final dio = Dio(BaseOptions( sendTimeout: setup.sendTimeout, connectTimeout: setup.connectTimeout, receiveTimeout: setup.receiveTimeout));
got it, Is there a plan to support this feature on web?
This library already supports web, so you actually shouldn't have any problem. Can you provide an example which reproduces this issue?
This is a duplicate of #1740, as XHR requests do not currently support readable streams.
Also, I've been planning to add extra support for SSE as an adapter or so, and only for the Web platform.
We should really throw an UnsupportedException or something like that for this operation while it's not working. That would make things more obvious.