1.0.3
This commit is contained in:
parent
01db4aa9eb
commit
e42528ef42
5 changed files with 65 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
# angel_websocket
|
||||
[![1.0.2](https://img.shields.io/badge/pub-1.0.2-brightgreen.svg)](https://pub.dartlang.org/packages/angel_websocket)
|
||||
[![1.0.3](https://img.shields.io/badge/pub-1.0.3-brightgreen.svg)](https://pub.dartlang.org/packages/angel_websocket)
|
||||
[![build status](https://travis-ci.org/angel-dart/websocket.svg)](https://travis-ci.org/angel-dart/websocket)
|
||||
|
||||
WebSocket plugin for Angel.
|
||||
|
|
|
@ -263,6 +263,16 @@ class BaseWebSocketService extends Service {
|
|||
listen();
|
||||
}
|
||||
|
||||
Future close() async {
|
||||
_onAllEvents.close();
|
||||
_onCreated.close();
|
||||
_onIndexed.close();
|
||||
_onModified.close();
|
||||
_onRead.close();
|
||||
_onRemoved.close();
|
||||
_onUpdated.close();
|
||||
}
|
||||
|
||||
/// Serializes an [action] to be sent over a WebSocket.
|
||||
serialize(WebSocketAction action) => JSON.encode(action);
|
||||
|
||||
|
|
|
@ -15,8 +15,44 @@ final RegExp _straySlashes = new RegExp(r"(^/)|(/+$)");
|
|||
|
||||
/// Queries an Angel server via WebSockets.
|
||||
class WebSockets extends BaseWebSocketClient {
|
||||
final List<WebSocketsService> _services = [];
|
||||
|
||||
WebSockets(String path) : super(new http.BrowserClient(), path);
|
||||
|
||||
@override
|
||||
Future close() {
|
||||
for (var service in _services) {
|
||||
service.close();
|
||||
}
|
||||
|
||||
return super.close();
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<String> authenticateViaPopup(String url,
|
||||
{String eventName: 'token', String errorMessage}) {
|
||||
var ctrl = new StreamController<String>();
|
||||
var wnd = window.open(url, 'angel_client_auth_popup');
|
||||
|
||||
wnd
|
||||
..on['beforeunload'].listen((_) {
|
||||
if (!ctrl.isClosed) {
|
||||
ctrl.addError(new AngelHttpException.notAuthenticated(
|
||||
message:
|
||||
errorMessage ?? 'Authentication via popup window failed.'));
|
||||
ctrl.close();
|
||||
}
|
||||
})
|
||||
..on[eventName ?? 'token'].listen((CustomEvent e) {
|
||||
if (!ctrl.isClosed) {
|
||||
ctrl.add(e.detail);
|
||||
ctrl.close();
|
||||
}
|
||||
});
|
||||
|
||||
return ctrl.stream;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WebSocketChannel> getConnectedWebSocket() {
|
||||
var socket = new WebSocket(basePath);
|
||||
|
|
17
lib/io.dart
17
lib/io.dart
|
@ -17,8 +17,25 @@ final RegExp _straySlashes = new RegExp(r"(^/)|(/+$)");
|
|||
|
||||
/// Queries an Angel server via WebSockets.
|
||||
class WebSockets extends BaseWebSocketClient {
|
||||
final List<WebSocketsService> _services = [];
|
||||
|
||||
WebSockets(String path) : super(new http.Client(), path);
|
||||
|
||||
@override
|
||||
Stream<String> authenticateViaPopup(String url, {String eventName: 'token'}) {
|
||||
throw new UnimplementedError(
|
||||
'Opening popup windows is not supported in the `dart:io` client.');
|
||||
}
|
||||
|
||||
@override
|
||||
Future close() {
|
||||
for (var service in _services) {
|
||||
service.close();
|
||||
}
|
||||
|
||||
return super.close();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WebSocketChannel> getConnectedWebSocket() async {
|
||||
var socket = await WebSocket.connect(basePath);
|
||||
|
|
|
@ -2,7 +2,7 @@ name: angel_websocket
|
|||
description: WebSocket plugin for Angel.
|
||||
environment:
|
||||
sdk: ">=1.19.0"
|
||||
version: 1.0.2
|
||||
version: 1.0.3
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_websocket
|
||||
dependencies:
|
||||
|
|
Loading…
Reference in a new issue