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