5
0
Fork 0

Compare commits

...

5 Commits

Author SHA1 Message Date
Sudharshan S. 0368fb1fc3
fix: authToken handling 2019-03-23 23:32:21 +08:00
Sudharshan S. 5ab96112ea fix: adding auth to eventsource 2019-03-23 14:55:22 +00:00
Steven Roose a20f01d32c bump v0.2.1 2018-11-21 10:39:18 +00:00
Steven Roose f533f29798
Merge pull request #4 from NBTX/patch-1
Fix typedef error: (Duration) => void is not a subtype of (dynamic) => void
2018-10-25 00:32:27 +01:00
NBTX e139f38eae Fix typedef error 2018-10-24 20:34:51 +01:00
3 changed files with 9 additions and 5 deletions

View File

@ -34,6 +34,7 @@ class EventSource extends Stream<Event> {
// interface attributes
final Uri url;
String authToken = "";
EventSourceReadyState get readyState => _readyState;
@ -55,17 +56,19 @@ class EventSource extends Stream<Event> {
/// Create a new EventSource by connecting to the specified url.
static Future<EventSource> connect(url,
{http.Client client, String lastEventId}) async {
{http.Client client, String lastEventId, String authToken}) async {
// parameter initialization
url = url is Uri ? url : Uri.parse(url);
client = client ?? new http.Client();
lastEventId = lastEventId ?? "";
EventSource es = new EventSource._internal(url, client, lastEventId);
EventSource es =
new EventSource._internal(url, client, lastEventId, authToken);
await es._start();
return es;
}
EventSource._internal(this.url, this.client, this._lastEventId) {
EventSource._internal(
this.url, this.client, this._lastEventId, this.authToken) {
_decoder = new EventSourceDecoder(retryIndicator: _updateRetryDelay);
}
@ -82,6 +85,7 @@ class EventSource extends Stream<Event> {
var request = new http.Request("GET", url);
request.headers["Cache-Control"] = "no-cache";
request.headers["Accept"] = "text/event-stream";
request.headers["Authorization"] = "Bearer $authToken";
if (_lastEventId.isNotEmpty) {
request.headers["Last-Event-ID"] = _lastEventId;
}

View File

@ -5,7 +5,7 @@ import "dart:convert";
import "event.dart";
typedef void RetryIndicator(Duration);
typedef RetryIndicator = void Function(Duration retry);
class EventSourceDecoder implements StreamTransformer<List<int>, Event> {
RetryIndicator retryIndicator;

View File

@ -1,6 +1,6 @@
name: eventsource
description: A client and server implementation of Server-Sent Events.
version: 0.2.0
version: 0.2.1
author: Steven Roose <stevenroose@gmail.com>
homepage: https://github.com/stevenroose/dart-eventsource