Bump to 2.0.0-alpha
This commit is contained in:
parent
7406f37204
commit
a1ddf47098
6 changed files with 38 additions and 40 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -73,3 +73,4 @@ crashlytics.properties
|
||||||
crashlytics-build.properties
|
crashlytics-build.properties
|
||||||
fabric.properties
|
fabric.properties
|
||||||
|
|
||||||
|
.dart_tool
|
|
@ -202,16 +202,15 @@ class AngelWebSocket {
|
||||||
action.params['query'] is Map &&
|
action.params['query'] is Map &&
|
||||||
action.params['query']['jwt'] is String) {
|
action.params['query']['jwt'] is String) {
|
||||||
try {
|
try {
|
||||||
var auth = socket.request.grab<AngelAuth>(AngelAuth);
|
var auth = socket.request.container.make<AngelAuth>();
|
||||||
var jwt = action.params['query']['jwt'] as String;
|
var jwt = action.params['query']['jwt'] as String;
|
||||||
AuthToken token;
|
AuthToken token;
|
||||||
|
|
||||||
token = new AuthToken.validate(jwt, auth.hmac);
|
token = new AuthToken.validate(jwt, auth.hmac);
|
||||||
var user = await auth.deserializer(token.userId);
|
var user = await auth.deserializer(token.userId);
|
||||||
var req = socket.request;
|
socket.request
|
||||||
req
|
..container.registerSingleton<AuthToken>(token)
|
||||||
..inject(AuthToken, req.properties['token'] = token)
|
..container.registerSingleton(user, as: user.runtimeType as Type);
|
||||||
..inject(user.runtimeType, req.properties["user"] = user);
|
|
||||||
socket.send(EVENT_AUTHENTICATED,
|
socket.send(EVENT_AUTHENTICATED,
|
||||||
{'token': token.serialize(auth.hmac), 'data': user});
|
{'token': token.serialize(auth.hmac), 'data': user});
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
|
@ -314,10 +313,10 @@ class AngelWebSocket {
|
||||||
|
|
||||||
/// Configures an [Angel] instance to listen for WebSocket connections.
|
/// Configures an [Angel] instance to listen for WebSocket connections.
|
||||||
Future configureServer(Angel app) async {
|
Future configureServer(Angel app) async {
|
||||||
app..container.singleton(this);
|
app..container.registerSingleton(this);
|
||||||
|
|
||||||
if (runtimeType != AngelWebSocket)
|
if (runtimeType != AngelWebSocket)
|
||||||
app.container.singleton(this, as: AngelWebSocket);
|
app..container.registerSingleton<AngelWebSocket>(this);
|
||||||
|
|
||||||
// Set up services
|
// Set up services
|
||||||
wireAllServices(app);
|
wireAllServices(app);
|
||||||
|
@ -340,9 +339,7 @@ class AngelWebSocket {
|
||||||
|
|
||||||
_onConnection.add(socket);
|
_onConnection.add(socket);
|
||||||
|
|
||||||
socket.request
|
socket.request.container.registerSingleton<WebSocketContext>(socket);
|
||||||
..properties['socket'] = socket
|
|
||||||
..inject(WebSocketContext, socket);
|
|
||||||
|
|
||||||
socket.channel.stream.listen(
|
socket.channel.stream.listen(
|
||||||
(data) {
|
(data) {
|
||||||
|
@ -363,15 +360,12 @@ class AngelWebSocket {
|
||||||
|
|
||||||
/// Handles an incoming HTTP request.
|
/// Handles an incoming HTTP request.
|
||||||
Future<bool> handleRequest(RequestContext req, ResponseContext res) async {
|
Future<bool> handleRequest(RequestContext req, ResponseContext res) async {
|
||||||
if (req is HttpRequestContextImpl) {
|
if (req is HttpRequestContext && res is HttpResponseContext) {
|
||||||
if (!WebSocketTransformer.isUpgradeRequest(req.io))
|
if (!WebSocketTransformer.isUpgradeRequest(req.rawRequest))
|
||||||
throw new AngelHttpException.badRequest();
|
throw new AngelHttpException.badRequest();
|
||||||
|
|
||||||
res
|
await res.detach();
|
||||||
..willCloseItself = true
|
var ws = await WebSocketTransformer.upgrade(req.rawRequest);
|
||||||
..end();
|
|
||||||
|
|
||||||
var ws = await WebSocketTransformer.upgrade(req.io);
|
|
||||||
var channel = new IOWebSocketChannel(ws);
|
var channel = new IOWebSocketChannel(ws);
|
||||||
var socket = new WebSocketContext(channel, req, res);
|
var socket = new WebSocketContext(channel, req, res);
|
||||||
handleClient(socket);
|
handleClient(socket);
|
||||||
|
|
|
@ -39,7 +39,8 @@ class WebSocketController extends Controller {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future configureServer(Angel app) async {
|
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);
|
InstanceMirror instanceMirror = reflect(this);
|
||||||
ClassMirror classMirror = reflectClass(this.runtimeType);
|
ClassMirror classMirror = reflectClass(this.runtimeType);
|
||||||
|
@ -58,16 +59,16 @@ class WebSocketController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.onConnection.listen((socket) async {
|
ws.onConnection.listen((socket) async {
|
||||||
socket.request
|
if (!socket.request.container.has<WebSocketContext>()) {
|
||||||
..inject('socket', socket)
|
socket.request.container.registerSingleton<WebSocketContext>(socket);
|
||||||
..inject(WebSocketContext, socket);
|
}
|
||||||
|
|
||||||
await onConnect(socket);
|
await onConnect(socket);
|
||||||
|
|
||||||
socket.onData.listen((data) => onData(data, socket));
|
socket.onData.listen((data) => onData(data, socket));
|
||||||
|
|
||||||
socket.onAction.listen((WebSocketAction action) async {
|
socket.onAction.listen((WebSocketAction action) async {
|
||||||
socket.request.inject(WebSocketAction, action);
|
socket.request.container.registerSingleton<WebSocketAction>(action);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await onAction(action, socket);
|
await onAction(action, socket);
|
||||||
|
@ -75,7 +76,8 @@ class WebSocketController extends Controller {
|
||||||
if (_handlers.containsKey(action.eventName)) {
|
if (_handlers.containsKey(action.eventName)) {
|
||||||
var methodMirror = _handlers[action.eventName];
|
var methodMirror = _handlers[action.eventName];
|
||||||
var fn = instanceMirror.getField(methodMirror.simpleName).reflectee;
|
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) {
|
} catch (e, st) {
|
||||||
ws.catchError(e, st, socket);
|
ws.catchError(e, st, socket);
|
||||||
|
|
16
pubspec.yaml
16
pubspec.yaml
|
@ -1,22 +1,20 @@
|
||||||
name: angel_websocket
|
name: angel_websocket
|
||||||
description: WebSocket plugin for Angel.
|
description: WebSocket plugin for Angel.
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=1.8.0 <3.0.0"
|
sdk: ">=2.0.0-dev <3.0.0"
|
||||||
version: 1.1.2
|
version: 2.0.0-alpha
|
||||||
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:
|
||||||
angel_auth: ^1.1.0-alpha
|
angel_auth: ^2.0.0-alpha
|
||||||
angel_client: ^1.1.0-alpha
|
angel_client: ^2.0.0-alpha
|
||||||
angel_framework: ^1.1.0-alpha
|
angel_framework: ^2.0.0-alpha
|
||||||
angel_http_exception: ^1.0.0
|
angel_http_exception: ^1.0.0
|
||||||
dart2_constant: ^1.0.0
|
|
||||||
http: ^0.11.0
|
http: ^0.11.0
|
||||||
json_god: ^2.0.0-beta
|
json_god: ^2.0.0-beta
|
||||||
merge_map: ^1.0.0
|
merge_map: ^1.0.0
|
||||||
meta: ^1.0.0
|
meta: ^1.0.0
|
||||||
uuid: ^0.5.3
|
|
||||||
web_socket_channel: ^1.0.0
|
web_socket_channel: ^1.0.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
logging: any
|
logging: ^0.11.0
|
||||||
test: "^0.12.15"
|
test: ^1.0.0
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'package:angel_container/mirrors.dart';
|
||||||
import 'package:angel_framework/angel_framework.dart' as srv;
|
import 'package:angel_framework/angel_framework.dart' as srv;
|
||||||
import 'package:angel_websocket/io.dart' as ws;
|
import 'package:angel_websocket/io.dart' as ws;
|
||||||
import 'package:angel_websocket/server.dart' as srv;
|
import 'package:angel_websocket/server.dart' as srv;
|
||||||
|
@ -15,7 +16,7 @@ main() {
|
||||||
String url;
|
String url;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = new srv.Angel();
|
app = new srv.Angel(reflector: const MirrorsReflector());
|
||||||
http = new srv.AngelHttp(app, useZone: false);
|
http = new srv.AngelHttp(app, useZone: false);
|
||||||
|
|
||||||
websockets = new srv.AngelWebSocket(app)
|
websockets = new srv.AngelWebSocket(app)
|
||||||
|
@ -34,6 +35,8 @@ main() {
|
||||||
client = new ws.WebSockets(url);
|
client = new ws.WebSockets(url);
|
||||||
await client.connect(timeout: new Duration(seconds: 3));
|
await client.connect(timeout: new Duration(seconds: 3));
|
||||||
|
|
||||||
|
print('Connected');
|
||||||
|
|
||||||
client
|
client
|
||||||
..onData.listen((data) {
|
..onData.listen((data) {
|
||||||
print('Received by client: $data');
|
print('Received by client: $data');
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
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/base_websocket_client.dart';
|
||||||
import 'package:angel_websocket/server.dart';
|
import 'package:angel_websocket/server.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
@ -11,8 +11,8 @@ class Todo extends Model {
|
||||||
Todo({String this.text, String this.when});
|
Todo({String this.text, String this.when});
|
||||||
}
|
}
|
||||||
|
|
||||||
class TodoService extends TypedService<Todo> {
|
class TodoService extends MapService {
|
||||||
TodoService() : super(new MapService()) {
|
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;
|
||||||
|
@ -21,10 +21,10 @@ class TodoService extends TypedService<Todo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
testIndex(BaseWebSocketClient client) async {
|
testIndex(BaseWebSocketClient client) async {
|
||||||
var Todos = client.service('api/todos');
|
var todoService = client.service('api/todos');
|
||||||
Todos.index();
|
todoService.index();
|
||||||
|
|
||||||
var indexed = await Todos.onIndexed.first;
|
var indexed = await todoService.onIndexed.first;
|
||||||
print('indexed: $indexed');
|
print('indexed: $indexed');
|
||||||
|
|
||||||
expect(indexed, isList);
|
expect(indexed, isList);
|
||||||
|
|
Loading…
Reference in a new issue