Bump to 2.0.0-alpha

This commit is contained in:
Tobe O 2018-08-28 10:17:14 -04:00
parent 7406f37204
commit a1ddf47098
6 changed files with 38 additions and 40 deletions

1
.gitignore vendored
View file

@ -73,3 +73,4 @@ crashlytics.properties
crashlytics-build.properties
fabric.properties
.dart_tool

View file

@ -202,16 +202,15 @@ class AngelWebSocket {
action.params['query'] is Map &&
action.params['query']['jwt'] is String) {
try {
var auth = socket.request.grab<AngelAuth>(AngelAuth);
var auth = socket.request.container.make<AngelAuth>();
var jwt = action.params['query']['jwt'] as String;
AuthToken token;
token = new AuthToken.validate(jwt, auth.hmac);
var user = await auth.deserializer(token.userId);
var req = socket.request;
req
..inject(AuthToken, req.properties['token'] = token)
..inject(user.runtimeType, req.properties["user"] = user);
socket.request
..container.registerSingleton<AuthToken>(token)
..container.registerSingleton(user, as: user.runtimeType as Type);
socket.send(EVENT_AUTHENTICATED,
{'token': token.serialize(auth.hmac), 'data': user});
} catch (e, st) {
@ -314,10 +313,10 @@ class AngelWebSocket {
/// Configures an [Angel] instance to listen for WebSocket connections.
Future configureServer(Angel app) async {
app..container.singleton(this);
app..container.registerSingleton(this);
if (runtimeType != AngelWebSocket)
app.container.singleton(this, as: AngelWebSocket);
app..container.registerSingleton<AngelWebSocket>(this);
// Set up services
wireAllServices(app);
@ -340,12 +339,10 @@ class AngelWebSocket {
_onConnection.add(socket);
socket.request
..properties['socket'] = socket
..inject(WebSocketContext, socket);
socket.request.container.registerSingleton<WebSocketContext>(socket);
socket.channel.stream.listen(
(data) {
(data) {
_onData.add(data);
handleData(socket, data);
},
@ -363,15 +360,12 @@ class AngelWebSocket {
/// Handles an incoming HTTP request.
Future<bool> handleRequest(RequestContext req, ResponseContext res) async {
if (req is HttpRequestContextImpl) {
if (!WebSocketTransformer.isUpgradeRequest(req.io))
if (req is HttpRequestContext && res is HttpResponseContext) {
if (!WebSocketTransformer.isUpgradeRequest(req.rawRequest))
throw new AngelHttpException.badRequest();
res
..willCloseItself = true
..end();
var ws = await WebSocketTransformer.upgrade(req.io);
await res.detach();
var ws = await WebSocketTransformer.upgrade(req.rawRequest);
var channel = new IOWebSocketChannel(ws);
var socket = new WebSocketContext(channel, req, res);
handleClient(socket);

View file

@ -39,7 +39,8 @@ class WebSocketController extends Controller {
@override
Future configureServer(Angel app) async {
if (findExpose() != null) await super.configureServer(app);
if (findExpose(app.container.reflector) != null)
await super.configureServer(app);
InstanceMirror instanceMirror = reflect(this);
ClassMirror classMirror = reflectClass(this.runtimeType);
@ -58,16 +59,16 @@ class WebSocketController extends Controller {
});
ws.onConnection.listen((socket) async {
socket.request
..inject('socket', socket)
..inject(WebSocketContext, socket);
if (!socket.request.container.has<WebSocketContext>()) {
socket.request.container.registerSingleton<WebSocketContext>(socket);
}
await onConnect(socket);
socket.onData.listen((data) => onData(data, socket));
socket.onAction.listen((WebSocketAction action) async {
socket.request.inject(WebSocketAction, action);
socket.request.container.registerSingleton<WebSocketAction>(action);
try {
await onAction(action, socket);
@ -75,7 +76,8 @@ class WebSocketController extends Controller {
if (_handlers.containsKey(action.eventName)) {
var methodMirror = _handlers[action.eventName];
var fn = instanceMirror.getField(methodMirror.simpleName).reflectee;
return app.runContained(fn as Function, socket.request, socket.response);
return app.runContained(
fn as Function, socket.request, socket.response);
}
} catch (e, st) {
ws.catchError(e, st, socket);

View file

@ -1,22 +1,20 @@
name: angel_websocket
description: WebSocket plugin for Angel.
environment:
sdk: ">=1.8.0 <3.0.0"
version: 1.1.2
sdk: ">=2.0.0-dev <3.0.0"
version: 2.0.0-alpha
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_websocket
dependencies:
angel_auth: ^1.1.0-alpha
angel_client: ^1.1.0-alpha
angel_framework: ^1.1.0-alpha
angel_auth: ^2.0.0-alpha
angel_client: ^2.0.0-alpha
angel_framework: ^2.0.0-alpha
angel_http_exception: ^1.0.0
dart2_constant: ^1.0.0
http: ^0.11.0
json_god: ^2.0.0-beta
merge_map: ^1.0.0
meta: ^1.0.0
uuid: ^0.5.3
web_socket_channel: ^1.0.0
dev_dependencies:
logging: any
test: "^0.12.15"
logging: ^0.11.0
test: ^1.0.0

View file

@ -1,4 +1,5 @@
import 'dart:io';
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart' as srv;
import 'package:angel_websocket/io.dart' as ws;
import 'package:angel_websocket/server.dart' as srv;
@ -15,7 +16,7 @@ main() {
String url;
setUp(() async {
app = new srv.Angel();
app = new srv.Angel(reflector: const MirrorsReflector());
http = new srv.AngelHttp(app, useZone: false);
websockets = new srv.AngelWebSocket(app)
@ -34,6 +35,8 @@ main() {
client = new ws.WebSockets(url);
await client.connect(timeout: new Duration(seconds: 3));
print('Connected');
client
..onData.listen((data) {
print('Received by client: $data');

View file

@ -1,5 +1,5 @@
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/common.dart';
import 'package:angel_model/angel_model.dart';
import 'package:angel_websocket/base_websocket_client.dart';
import 'package:angel_websocket/server.dart';
import 'package:test/test.dart';
@ -11,8 +11,8 @@ class Todo extends Model {
Todo({String this.text, String this.when});
}
class TodoService extends TypedService<Todo> {
TodoService() : super(new MapService()) {
class TodoService extends MapService {
TodoService() : super() {
configuration['ws:filter'] = (HookedServiceEvent e, WebSocketContext socket) {
print('Hello, service filter world!');
return true;
@ -21,10 +21,10 @@ class TodoService extends TypedService<Todo> {
}
testIndex(BaseWebSocketClient client) async {
var Todos = client.service('api/todos');
Todos.index();
var todoService = client.service('api/todos');
todoService.index();
var indexed = await Todos.onIndexed.first;
var indexed = await todoService.onIndexed.first;
print('indexed: $indexed');
expect(indexed, isList);