2.0.0-alpha.1
This commit is contained in:
parent
d48ef88e87
commit
11b7b6159e
12 changed files with 53 additions and 42 deletions
|
@ -1,3 +1,7 @@
|
|||
# 2.0.0-alpha.1
|
||||
* Refactorings for updated Angel 2 versions.
|
||||
* Remove `package:dart2_constant`.
|
||||
|
||||
# 2.0.0-alpha
|
||||
* Depend on Dart 2 and Angel 2.
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ class WebSocketEvent {
|
|||
|
||||
WebSocketEvent({String this.eventName, this.data});
|
||||
|
||||
factory WebSocketEvent.fromJson(Map data) =>
|
||||
new WebSocketEvent(eventName: data['eventName'].toString(), data: data['data']);
|
||||
factory WebSocketEvent.fromJson(Map data) => new WebSocketEvent(
|
||||
eventName: data['eventName'].toString(), data: data['data']);
|
||||
|
||||
Map toJson() {
|
||||
return {'eventName': eventName, 'data': data};
|
||||
|
@ -58,7 +58,7 @@ class WebSocketAction {
|
|||
String id;
|
||||
String eventName;
|
||||
var data;
|
||||
var params;
|
||||
Map<String, dynamic> params;
|
||||
|
||||
WebSocketAction(
|
||||
{String this.id, String this.eventName, this.data, this.params});
|
||||
|
@ -67,7 +67,7 @@ class WebSocketAction {
|
|||
id: data['id'].toString(),
|
||||
eventName: data['eventName'].toString(),
|
||||
data: data['data'],
|
||||
params: data['params']);
|
||||
params: data['params'] as Map<String, dynamic>);
|
||||
|
||||
Map toJson() {
|
||||
return {'id': id, 'eventName': eventName, 'data': data, 'params': params};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'package:angel_client/angel_client.dart';
|
||||
import 'package:angel_client/base_angel_client.dart';
|
||||
import 'package:angel_http_exception/angel_http_exception.dart';
|
||||
import 'package:dart2_constant/convert.dart';
|
||||
import 'package:http/src/base_client.dart' as http;
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
import 'package:web_socket_channel/status.dart' as status;
|
||||
|
@ -159,7 +159,8 @@ abstract class BaseWebSocketClient extends BaseAngelClient {
|
|||
}
|
||||
|
||||
if (event.eventName == EVENT_ERROR) {
|
||||
var error = new AngelHttpException.fromMap((event.data ?? {}) as Map);
|
||||
var error =
|
||||
new AngelHttpException.fromMap((event.data ?? {}) as Map);
|
||||
_onError.add(error);
|
||||
} else if (event.eventName == EVENT_AUTHENTICATED) {
|
||||
var authResult = new AngelAuthResult.fromMap(event.data as Map);
|
||||
|
@ -240,18 +241,12 @@ class WebSocketsService extends Service {
|
|||
|
||||
final StreamController<WebSocketEvent> _onAllEvents =
|
||||
new StreamController<WebSocketEvent>();
|
||||
final StreamController _onIndexed =
|
||||
new StreamController();
|
||||
final StreamController _onRead =
|
||||
new StreamController();
|
||||
final StreamController _onCreated =
|
||||
new StreamController();
|
||||
final StreamController _onModified =
|
||||
new StreamController();
|
||||
final StreamController _onUpdated =
|
||||
new StreamController();
|
||||
final StreamController _onRemoved =
|
||||
new StreamController();
|
||||
final StreamController _onIndexed = new StreamController();
|
||||
final StreamController _onRead = new StreamController();
|
||||
final StreamController _onCreated = new StreamController();
|
||||
final StreamController _onModified = new StreamController();
|
||||
final StreamController _onUpdated = new StreamController();
|
||||
final StreamController _onRemoved = new StreamController();
|
||||
|
||||
/// Fired on all events.
|
||||
Stream<WebSocketEvent> get onAllEvents => _onAllEvents.stream;
|
||||
|
@ -340,21 +335,23 @@ class WebSocketsService extends Service {
|
|||
}
|
||||
|
||||
@override
|
||||
Future index([Map params]) async {
|
||||
Future index([Map<String, dynamic> params]) async {
|
||||
app.sendAction(new WebSocketAction(
|
||||
eventName: '$path::${ACTION_INDEX}', params: params ?? {}));
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future read(id, [Map params]) async {
|
||||
Future read(id, [Map<String, dynamic> params]) async {
|
||||
app.sendAction(new WebSocketAction(
|
||||
eventName: '$path::${ACTION_READ}', id: id.toString(), params: params ?? {}));
|
||||
eventName: '$path::${ACTION_READ}',
|
||||
id: id.toString(),
|
||||
params: params ?? {}));
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future create(data, [Map params]) async {
|
||||
Future create(data, [Map<String, dynamic> params]) async {
|
||||
app.sendAction(new WebSocketAction(
|
||||
eventName: '$path::${ACTION_CREATE}',
|
||||
data: data,
|
||||
|
@ -363,7 +360,7 @@ class WebSocketsService extends Service {
|
|||
}
|
||||
|
||||
@override
|
||||
Future modify(id, data, [Map params]) async {
|
||||
Future modify(id, data, [Map<String, dynamic> params]) async {
|
||||
app.sendAction(new WebSocketAction(
|
||||
eventName: '$path::${ACTION_MODIFY}',
|
||||
id: id.toString(),
|
||||
|
@ -373,7 +370,7 @@ class WebSocketsService extends Service {
|
|||
}
|
||||
|
||||
@override
|
||||
Future update(id, data, [Map params]) async {
|
||||
Future update(id, data, [Map<String, dynamic> params]) async {
|
||||
app.sendAction(new WebSocketAction(
|
||||
eventName: '$path::${ACTION_UPDATE}',
|
||||
id: id.toString(),
|
||||
|
@ -383,9 +380,11 @@ class WebSocketsService extends Service {
|
|||
}
|
||||
|
||||
@override
|
||||
Future remove(id, [Map params]) async {
|
||||
Future remove(id, [Map<String, dynamic> params]) async {
|
||||
app.sendAction(new WebSocketAction(
|
||||
eventName: '$path::${ACTION_REMOVE}', id: id.toString(), params: params ?? {}));
|
||||
eventName: '$path::${ACTION_REMOVE}',
|
||||
id: id.toString(),
|
||||
params: params ?? {}));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -411,4 +410,4 @@ class WebSocketExtraneousEventHandler {
|
|||
|
||||
return _events[index].stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,8 @@ class WebSockets extends BaseWebSocketClient {
|
|||
return completer.complete(new HtmlWebSocketChannel(socket));
|
||||
})
|
||||
..onError.listen((e) {
|
||||
if (!completer.isCompleted) return completer.completeError(e is ErrorEvent ? e.error : e);
|
||||
if (!completer.isCompleted)
|
||||
return completer.completeError(e is ErrorEvent ? e.error : e);
|
||||
});
|
||||
|
||||
return completer.future;
|
||||
|
|
|
@ -41,4 +41,4 @@ class WebSockets extends BaseWebSocketClient {
|
|||
: {});
|
||||
return new IOWebSocketChannel(socket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,8 @@ class WebSockets extends BaseWebSocketClient {
|
|||
class IoWebSocketsService extends WebSocketsService {
|
||||
final Type type;
|
||||
|
||||
IoWebSocketsService(WebSocketChannel socket, WebSockets app, String uri, this.type)
|
||||
IoWebSocketsService(
|
||||
WebSocketChannel socket, WebSockets app, String uri, this.type)
|
||||
: super(socket, app, uri);
|
||||
|
||||
@override
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
library angel_websocket.server;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:mirrors';
|
||||
import 'package:angel_auth/angel_auth.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:dart2_constant/convert.dart';
|
||||
import 'package:json_god/json_god.dart' as god;
|
||||
import 'package:merge_map/merge_map.dart';
|
||||
import 'package:web_socket_channel/io.dart';
|
||||
|
@ -132,7 +132,7 @@ class AngelWebSocket {
|
|||
return null;
|
||||
}
|
||||
|
||||
var service = app.service(split[0]);
|
||||
var service = app.findService(split[0]);
|
||||
|
||||
if (service == null) {
|
||||
socket.sendError(new AngelHttpException.notFound(
|
||||
|
@ -142,7 +142,7 @@ class AngelWebSocket {
|
|||
|
||||
var actionName = split[1];
|
||||
|
||||
if (action.params is! Map) action.params = {};
|
||||
if (action.params is! Map) action.params = <String, dynamic>{};
|
||||
|
||||
if (allowClientParams != true) {
|
||||
if (action.params['query'] is Map)
|
||||
|
@ -151,8 +151,9 @@ class AngelWebSocket {
|
|||
action.params = {};
|
||||
}
|
||||
|
||||
var params = mergeMap([
|
||||
((deserializer ?? (params) => params)(action.params)) as Map,
|
||||
var params = mergeMap<String, dynamic>([
|
||||
((deserializer ?? (params) => params)(action.params))
|
||||
as Map<String, dynamic>,
|
||||
{
|
||||
"provider": Providers.websocket,
|
||||
'__requestctx': socket.request,
|
||||
|
|
|
@ -2,7 +2,7 @@ name: angel_websocket
|
|||
description: WebSocket plugin for Angel.
|
||||
environment:
|
||||
sdk: ">=2.0.0-dev <3.0.0"
|
||||
version: 2.0.0-alpha
|
||||
version: 2.0.0-alpha.1
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_websocket
|
||||
dependencies:
|
||||
|
@ -16,5 +16,7 @@ dependencies:
|
|||
meta: ^1.0.0
|
||||
web_socket_channel: ^1.0.0
|
||||
dev_dependencies:
|
||||
angel_container: ^1.0.0-alpha
|
||||
angel_model: ^1.0.0
|
||||
logging: ^0.11.0
|
||||
test: ^1.0.0
|
||||
|
|
|
@ -23,9 +23,11 @@ main() {
|
|||
auth.serializer = (_) async => 'baz';
|
||||
auth.deserializer = (_) async => USER;
|
||||
|
||||
auth.strategies.add(new LocalAuthStrategy((username, password) async {
|
||||
if (username == 'foo' && password == 'bar') return USER;
|
||||
}));
|
||||
auth.strategies['local'] = new LocalAuthStrategy(
|
||||
(username, password) async {
|
||||
if (username == 'foo' && password == 'bar') return USER;
|
||||
},
|
||||
);
|
||||
|
||||
app.post('/auth/local', auth.authenticate('local'));
|
||||
|
||||
|
|
|
@ -2,4 +2,4 @@ import 'package:test/test.dart';
|
|||
|
||||
main() {
|
||||
group('service.browser', () {});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ class Todo extends Model {
|
|||
|
||||
class TodoService extends MapService {
|
||||
TodoService() : super() {
|
||||
configuration['ws:filter'] = (HookedServiceEvent e, WebSocketContext socket) {
|
||||
configuration['ws:filter'] =
|
||||
(HookedServiceEvent e, WebSocketContext socket) {
|
||||
print('Hello, service filter world!');
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -9,4 +9,4 @@ main() {
|
|||
app.connect().catchError((_) {
|
||||
window.alert('no websocket');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue