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

ServerSendEvent support for Flutter Web #1859

Open
kuloud opened this issue Jun 10, 2023 · 6 comments
Open

ServerSendEvent support for Flutter Web #1859

kuloud opened this issue Jun 10, 2023 · 6 comments
Labels
e: PR welcomed p: dio Targeting `dio` package s: feature This issue indicates a feature request

Comments

@kuloud
Copy link

kuloud commented Jun 10, 2023

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

@kuloud kuloud added the s: feature This issue indicates a feature request label Jun 10, 2023
@ueman
Copy link
Contributor

ueman commented Jun 19, 2023

How do you initialize dio? RawSocket is a dart:io class, which means it's unavailable on web.

@ueman ueman added h: need more info Further information is requested and removed s: feature This issue indicates a feature request labels Jun 19, 2023
@kuloud
Copy link
Author

kuloud commented Jun 19, 2023

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?

@ueman
Copy link
Contributor

ueman commented Jun 19, 2023

This library already supports web, so you actually shouldn't have any problem. Can you provide an example which reproduces this issue?

@AlexV525
Copy link
Member

This is a duplicate of #1740, as XHR requests do not currently support readable streams.

@AlexV525
Copy link
Member

Also, I've been planning to add extra support for SSE as an adapter or so, and only for the Web platform.

@AlexV525 AlexV525 added s: feature This issue indicates a feature request p: dio Targeting `dio` package and removed h: need more info Further information is requested labels Jun 19, 2023
@ueman
Copy link
Contributor

ueman commented Jun 19, 2023

We should really throw an UnsupportedException or something like that for this operation while it's not working. That would make things more obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e: PR welcomed p: dio Targeting `dio` package s: feature This issue indicates a feature request
Projects
None yet
Development

No branches or pull requests

3 participants