Cancel sub
This commit is contained in:
parent
f2fcc48642
commit
25da3788f7
3 changed files with 7 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
# angel_client
|
# angel_client
|
||||||
|
|
||||||
[](https://pub.dartlang.org/packages/angel_client)
|
[](https://pub.dartlang.org/packages/angel_client)
|
||||||
[](https://travis-ci.org/angel-dart/client)
|
[](https://travis-ci.org/angel-dart/client)
|
||||||
|
|
||||||
Client library for the Angel framework.
|
Client library for the Angel framework.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/// Browser library for the Angel framework.
|
/// Browser library for the Angel framework.
|
||||||
library angel_client.browser;
|
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:convert' show JSON;
|
||||||
import 'dart:html' show CustomEvent, window;
|
import 'dart:html' show CustomEvent, window;
|
||||||
import 'package:http/browser_client.dart' as http;
|
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');
|
var wnd = window.open(url, 'angel_client_auth_popup');
|
||||||
|
|
||||||
Timer t;
|
Timer t;
|
||||||
|
StreamSubscription<CustomEvent> sub;
|
||||||
t = new Timer.periodic(new Duration(milliseconds: 500), (timer) {
|
t = new Timer.periodic(new Duration(milliseconds: 500), (timer) {
|
||||||
if (!ctrl.isClosed) {
|
if (!ctrl.isClosed) {
|
||||||
if (wnd.closed) {
|
if (wnd.closed) {
|
||||||
|
@ -62,16 +63,18 @@ class Rest extends BaseAngelClient {
|
||||||
errorMessage ?? 'Authentication via popup window failed.'));
|
errorMessage ?? 'Authentication via popup window failed.'));
|
||||||
ctrl.close();
|
ctrl.close();
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
|
sub?.cancel();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
});
|
});
|
||||||
|
|
||||||
window.on[eventName ?? 'token'].listen((CustomEvent e) {
|
sub = window.on[eventName ?? 'token'].listen((CustomEvent e) {
|
||||||
if (!ctrl.isClosed) {
|
if (!ctrl.isClosed) {
|
||||||
ctrl.add(e.detail);
|
ctrl.add(e.detail);
|
||||||
t.cancel();
|
t.cancel();
|
||||||
ctrl.close();
|
ctrl.close();
|
||||||
|
sub.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_client
|
name: angel_client
|
||||||
version: 1.0.5
|
version: 1.0.6
|
||||||
description: Client library for the Angel framework.
|
description: Client library for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_client
|
homepage: https://github.com/angel-dart/angel_client
|
||||||
|
|
Loading…
Reference in a new issue