1.0.1
This commit is contained in:
parent
cfae7cf99f
commit
fe1f85bfa8
4 changed files with 30 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
||||||
# angel_websocket
|
# 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)
|
[![build status](https://travis-ci.org/angel-dart/websocket.svg)](https://travis-ci.org/angel-dart/websocket)
|
||||||
|
|
||||||
WebSocket plugin for Angel.
|
WebSocket plugin for Angel.
|
||||||
|
@ -22,7 +22,9 @@ import "package:angel_websocket/server.dart";
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
var app = new Angel();
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -31,6 +31,10 @@ class AngelWebSocket extends AngelPlugin {
|
||||||
final StreamController<WebSocketContext> _onDisconnect =
|
final StreamController<WebSocketContext> _onDisconnect =
|
||||||
new StreamController<WebSocketContext>.broadcast();
|
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.
|
/// Include debug information, and send error information across WebSockets.
|
||||||
final bool debug;
|
final bool debug;
|
||||||
|
|
||||||
|
@ -59,10 +63,16 @@ class AngelWebSocket extends AngelPlugin {
|
||||||
/// Fired when a user disconnects.
|
/// Fired when a user disconnects.
|
||||||
Stream<WebSocketContext> get onDisconnection => _onDisconnect.stream;
|
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 {
|
return (HookedServiceEvent e) async {
|
||||||
|
if (e.params != null && e.params['broadcast'] == false) return;
|
||||||
|
|
||||||
var event = await transformEvent(e);
|
var event = await transformEvent(e);
|
||||||
event.eventName = "$path::${event.eventName}";
|
event.eventName = "$path::${event.eventName}";
|
||||||
|
|
||||||
|
@ -115,6 +125,15 @@ class AngelWebSocket extends AngelPlugin {
|
||||||
|
|
||||||
var actionName = split[1];
|
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([
|
var params = mergeMap([
|
||||||
god.deserializeDatum(action.params),
|
god.deserializeDatum(action.params),
|
||||||
{
|
{
|
||||||
|
@ -165,7 +184,7 @@ class AngelWebSocket extends AngelPlugin {
|
||||||
/// Hooks a service up to have its events broadcasted.
|
/// Hooks a service up to have its events broadcasted.
|
||||||
hookupService(Pattern _path, HookedService service) {
|
hookupService(Pattern _path, HookedService service) {
|
||||||
String path = _path.toString();
|
String path = _path.toString();
|
||||||
var batch = _batchEvent(path);
|
var batch = serviceHook(path);
|
||||||
|
|
||||||
service
|
service
|
||||||
..afterCreated.listen(batch)
|
..afterCreated.listen(batch)
|
||||||
|
@ -207,10 +226,6 @@ class AngelWebSocket extends AngelPlugin {
|
||||||
if (ACTIONS.contains(split[1])) {
|
if (ACTIONS.contains(split[1])) {
|
||||||
var event = handleAction(action, socket);
|
var event = handleAction(action, socket);
|
||||||
if (event is Future) event = await event;
|
if (event is Future) event = await event;
|
||||||
|
|
||||||
if (event is WebSocketEvent) {
|
|
||||||
batchEvent(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
name: angel_websocket
|
name: angel_websocket
|
||||||
description: WebSocket plugin for Angel
|
description: WebSocket plugin for Angel.
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=1.19.0"
|
sdk: ">=1.19.0"
|
||||||
version: 1.0.0
|
version: 1.0.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:
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
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:angel_websocket/base_websocket_client.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
class Todo extends MemoryModel {
|
class Todo extends Model {
|
||||||
String text;
|
String text;
|
||||||
String when;
|
String when;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue