This commit is contained in:
thosakwe 2017-02-22 17:34:35 -05:00
parent cfae7cf99f
commit fe1f85bfa8
4 changed files with 30 additions and 13 deletions

View file

@ -1,5 +1,5 @@
# angel_websocket
[![1.0.0](https://img.shields.io/badge/pub-1.0.0-brightgreen.svg)](https://pub.dartlang.org/packages/angel_websocket)
[![1.0.1](https://img.shields.io/badge/pub-1.0.1-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.
@ -22,7 +22,9 @@ import "package:angel_websocket/server.dart";
main() async {
var app = new Angel();
await app.configure(new AngelWebSocket("/ws"));
// Ensure this runs after all our services are in-place
app.justBeforeStart.add(new AngelWebSocket("/ws"));
}
```

View file

@ -31,6 +31,10 @@ class AngelWebSocket extends AngelPlugin {
final StreamController<WebSocketContext> _onDisconnect =
new StreamController<WebSocketContext>.broadcast();
/// If this is not `true`, then all client-side service parameters will be
/// discarded, other than `params['query']`.
final bool allowClientParams;
/// Include debug information, and send error information across WebSockets.
final bool debug;
@ -59,10 +63,16 @@ class AngelWebSocket extends AngelPlugin {
/// Fired when a user disconnects.
Stream<WebSocketContext> get onDisconnection => _onDisconnect.stream;
AngelWebSocket({this.endpoint: '/ws', this.debug: false, this.register});
AngelWebSocket(
{this.endpoint: '/ws',
this.debug: false,
this.allowClientParams: false,
this.register});
_batchEvent(String path) {
serviceHook(String path) {
return (HookedServiceEvent e) async {
if (e.params != null && e.params['broadcast'] == false) return;
var event = await transformEvent(e);
event.eventName = "$path::${event.eventName}";
@ -115,6 +125,15 @@ class AngelWebSocket extends AngelPlugin {
var actionName = split[1];
if (action.params is! Map) action.params = {};
if (allowClientParams != true) {
if (action.params['query'] is Map)
action.params = {'query': action.params['query']};
else
action.params = {};
}
var params = mergeMap([
god.deserializeDatum(action.params),
{
@ -165,7 +184,7 @@ class AngelWebSocket extends AngelPlugin {
/// Hooks a service up to have its events broadcasted.
hookupService(Pattern _path, HookedService service) {
String path = _path.toString();
var batch = _batchEvent(path);
var batch = serviceHook(path);
service
..afterCreated.listen(batch)
@ -207,10 +226,6 @@ class AngelWebSocket extends AngelPlugin {
if (ACTIONS.contains(split[1])) {
var event = handleAction(action, socket);
if (event is Future) event = await event;
if (event is WebSocketEvent) {
batchEvent(event);
}
}
}
}

View file

@ -1,8 +1,8 @@
name: angel_websocket
description: WebSocket plugin for Angel
description: WebSocket plugin for Angel.
environment:
sdk: ">=1.19.0"
version: 1.0.0
version: 1.0.1
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_websocket
dependencies:

View file

@ -1,9 +1,9 @@
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/src/defs.dart';
import 'package:angel_framework/common.dart';
import 'package:angel_websocket/base_websocket_client.dart';
import 'package:test/test.dart';
class Todo extends MemoryModel {
class Todo extends Model {
String text;
String when;