dart-lang / dart-lang/http

Unable to Receive SSE Events when running as a Flutter Web app on Chrome Web

Open
#337 21 comments 25 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
1.1k
Forks
419
Avg merge
4d 14h
Merged PRs (30d)
8

Description

Have a Flutter App that is able to receive SSE text/event-stream events when running on mobile but it is not receiving the same SSE text/event-stream events when running on the chrome web.

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

http.Client _client;

MyApp() : super() {
print("Ctor called");
subscribe();
}

@override
Widget build(BuildContext context) {
print("building..");
return MaterialApp(
title: 'Flutter SSE',
home: Scaffold(
appBar: AppBar(
title: Text('Receive SSE Events'),
),
body: Center(
child: Text('Ready for events..'),
),
),
);
}

subscribe() async {
print("Subscribing..");
try {
_client = http.Client();

var request = new http.Request("GET", Uri.parse("http://192.168.1.11:8080/myserver/events"));
request.headers["Cache-Control"] = "no-cache";
request.headers["Accept"] = "text/event-stream";

Future response = _client.send(request);
print("Subscribed!");

response.asStream().listen((streamedResponse) {
print("Received streamedResponse.statusCode:${streamedResponse.statusCode}");
streamedResponse.stream.listen((data) {
print("Received data:$data");
});
});
} catch(e) {
print("Caught $e");
}
}

unsubscribe() {
_client.close();
}
}

On the server-side, I can see that the flutter app always subscribes okay as I can see the Sink being added. And the server-side always dispatches the events to the Sink but the flutter app only receives the events when running as a mobile app and NOT when running as a Chrome web app.

C:\Users\pondeMuse\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel master, v1.10.15-pre.188, on Microsoft Windows [Version 10.0.16299.1087], locale en-GB)
• Flutter version 1.10.15-pre.188 at C:\Users\pondeMuse\flutter
• Framework revision 584ee10c68 (2 days ago), 2019-10-21 07:49:28 -0700
• Engine revision 8aefcd8575
• Dart version 2.6.0 (build 2.6.0-dev.8.0 a61c775db8)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\pondeMuse\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 40.2.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[!] IntelliJ IDEA Community Edition (version 2019.2)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.5
X Flutter plugin not installed; this adds Flutter specific functionality.
• Dart plugin version 192.7402
• For information about installing plugins, see
https://flutter.dev/intellij-setup/#installing-the-plugins

[√] Connected device (2 available)
• Chrome • chrome • web-javascript • Google Chrome 77.0.3865.120
• Web Server • web-server • web-javascript • Flutter Tools

! Doctor found issues in 1 category.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.