Cancel sub

This commit is contained in:
thosakwe 2017-06-03 13:46:49 -04:00
parent f2fcc48642
commit 25da3788f7
3 changed files with 7 additions and 4 deletions

View file

@ -1,6 +1,6 @@
# angel_client
[![pub 1.0.5](https://img.shields.io/badge/pub-1.0.5-brightgreen.svg)](https://pub.dartlang.org/packages/angel_client)
[![pub 1.0.6](https://img.shields.io/badge/pub-1.0.6-brightgreen.svg)](https://pub.dartlang.org/packages/angel_client)
[![build status](https://travis-ci.org/angel-dart/client.svg)](https://travis-ci.org/angel-dart/client)
Client library for the Angel framework.

View file

@ -1,7 +1,7 @@
/// Browser library for the Angel framework.
library angel_client.browser;
import 'dart:async' show Future, Stream, StreamController, Timer;
import 'dart:async' show Future, Stream, StreamController, StreamSubscription, Timer;
import 'dart:convert' show JSON;
import 'dart:html' show CustomEvent, window;
import 'package:http/browser_client.dart' as http;
@ -54,6 +54,7 @@ class Rest extends BaseAngelClient {
var wnd = window.open(url, 'angel_client_auth_popup');
Timer t;
StreamSubscription<CustomEvent> sub;
t = new Timer.periodic(new Duration(milliseconds: 500), (timer) {
if (!ctrl.isClosed) {
if (wnd.closed) {
@ -62,16 +63,18 @@ class Rest extends BaseAngelClient {
errorMessage ?? 'Authentication via popup window failed.'));
ctrl.close();
timer.cancel();
sub?.cancel();
}
} else
timer.cancel();
});
window.on[eventName ?? 'token'].listen((CustomEvent e) {
sub = window.on[eventName ?? 'token'].listen((CustomEvent e) {
if (!ctrl.isClosed) {
ctrl.add(e.detail);
t.cancel();
ctrl.close();
sub.cancel();
}
});

View file

@ -1,5 +1,5 @@
name: angel_client
version: 1.0.5
version: 1.0.6
description: Client library for the Angel framework.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_client