add proper example, update lints
diff --git a/pkgs/sse/CHANGELOG.md b/pkgs/sse/CHANGELOG.md index 98eebc5..77c5538 100644 --- a/pkgs/sse/CHANGELOG.md +++ b/pkgs/sse/CHANGELOG.md
@@ -1,4 +1,4 @@ -## 0.0.2 +## 1.0.0 - Internal cleanup.
diff --git a/pkgs/sse/example/README.md b/pkgs/sse/example/README.md deleted file mode 100644 index 631fdad..0000000 --- a/pkgs/sse/example/README.md +++ /dev/null
@@ -1 +0,0 @@ -The test folder provides a very basic usage example.
diff --git a/pkgs/sse/example/index.dart b/pkgs/sse/example/index.dart new file mode 100644 index 0000000..afc1a49 --- /dev/null +++ b/pkgs/sse/example/index.dart
@@ -0,0 +1,15 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:sse/client/sse_client.dart'; + +/// A basic example which should be used in a browser that supports SSE. +void main() { + var channel = SseClient('/sseHandler'); + + channel.stream.listen((s) { + // Listen for messages and send the back. + channel.sink.add(s); + }); +}
diff --git a/pkgs/sse/example/server.dart b/pkgs/sse/example/server.dart new file mode 100644 index 0000000..74439c9 --- /dev/null +++ b/pkgs/sse/example/server.dart
@@ -0,0 +1,21 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:shelf/shelf_io.dart' as io; +import 'package:sse/server/sse_handler.dart'; + +/// A basic server which sets up an SSE handler. +/// +/// When a client connnects it will send a simple message and print the +/// response. +void main() async { + var handler = SseHandler(Uri.parse('/sseHandler')); + await io.serve(handler.handler, 'localhost', 0); + var connections = handler.connections; + while (await connections.hasNext) { + var connection = await connections.next; + connection.sink.add('foo'); + connection.stream.listen(print); + } +}
diff --git a/pkgs/sse/lib/client/sse_client.dart b/pkgs/sse/lib/client/sse_client.dart index d7e37ca..65bbbee 100644 --- a/pkgs/sse/lib/client/sse_client.dart +++ b/pkgs/sse/lib/client/sse_client.dart
@@ -46,7 +46,8 @@ /// Add messages to this [StreamSink] to send them to the server. /// - /// The message added to the sink has to be JSON encodable. + /// The message added to the sink has to be JSON encodable. Messages that fail + /// to encode will be logged through a [Logger]. @override StreamSink<String> get sink => _outgoingController.sink;
diff --git a/pkgs/sse/pubspec.yaml b/pkgs/sse/pubspec.yaml index 13c8db3..9e0487e 100644 --- a/pkgs/sse/pubspec.yaml +++ b/pkgs/sse/pubspec.yaml
@@ -1,5 +1,5 @@ name: sse -version: 0.0.1 +version: 1.0.0 author: Dart Team <misc@dartlang.org> homepage: https://github.com/dart-lang/sse description: >-
diff --git a/pkgs/sse/test/sse_test.dart b/pkgs/sse/test/sse_test.dart index cebde5c..d6e0445 100644 --- a/pkgs/sse/test/sse_test.dart +++ b/pkgs/sse/test/sse_test.dart
@@ -44,7 +44,7 @@ }); test('Multiple clients can connect', () async { - var connections = await handler.connections; + var connections = handler.connections; await webdriver.get('http://localhost:${server.port}'); await connections.next; await webdriver.get('http://localhost:${server.port}'); @@ -52,7 +52,7 @@ }); test('Routes data correctly', () async { - var connections = await handler.connections; + var connections = handler.connections; await webdriver.get('http://localhost:${server.port}'); var connectionA = await connections.next; await webdriver.get('http://localhost:${server.port}');
diff --git a/pkgs/sse/tool/travis-setup.sh b/pkgs/sse/tool/travis-setup.sh old mode 100644 new mode 100755