This commit is contained in:
Tobe O 2017-10-19 18:26:59 -04:00
parent 6eed138927
commit 75cdcc8853
8 changed files with 33 additions and 10 deletions

View file

@ -90,8 +90,8 @@ class AngelWebSocket {
event.eventName = "$path::${event.eventName}";
_filter(WebSocketContext socket) {
if (e.service.properties.containsKey('ws:filter'))
return e.service.properties['ws:filter'](e, socket);
if (e.service.configuration.containsKey('ws:filter'))
return e.service.configuration['ws:filter'](e, socket);
else if (e.params != null && e.params.containsKey('ws:filter'))
return e.params['ws:filter'](e, socket);
else

View file

@ -9,13 +9,15 @@ class ExposeWs {
/// A special controller that also supports WebSockets.
class WebSocketController extends Controller {
final AngelWebSocket ws;
Map<String, MethodMirror> _handlers = {};
Map<String, Symbol> _handlerSymbols = {};
/// The plug-in instance powering this controller.
AngelWebSocket plugin;
WebSocketController() : super();
WebSocketController(this.ws) : super();
/// Sends an event to all clients.
void broadcast(String eventName, data, {filter(WebSocketContext socket)}) {
@ -36,8 +38,8 @@ class WebSocketController extends Controller {
onData(data, WebSocketContext socket) {}
@override
Future call(Angel app) async {
if (findExpose() != null) await super.call(app);
Future configureServer(Angel app) async {
if (findExpose() != null) await super.configureServer(app);
InstanceMirror instanceMirror = reflect(this);
ClassMirror classMirror = reflectClass(this.runtimeType);
@ -55,8 +57,6 @@ class WebSocketController extends Controller {
}
});
AngelWebSocket ws = app.container.make(AngelWebSocket);
ws.onConnection.listen((socket) async {
socket.request
..inject('socket', socket)

View file

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

View file

@ -20,6 +20,8 @@ const Game JOHN_VS_BOB = const Game(playerOne: 'John', playerTwo: 'Bob');
@Expose('/game')
class GameController extends WebSocketController {
GameController(AngelWebSocket ws) : super(ws);
@ExposeWs('search')
search(WebSocketContext socket) async {
print('User is searching for a game...');

View file

@ -23,7 +23,7 @@ main() {
await app.configure(websockets.configureServer);
app.all('/ws', websockets.handleRequest);
await app.configure(new GameController());
await app.configure(new GameController(websockets).configureServer);
app.logger = new Logger('angel_auth')..onRecord.listen(print);
server = await app.startServer();

View file

@ -13,7 +13,7 @@ class Todo extends Model {
class TodoService extends TypedService<Todo> {
TodoService() : super(new MapService()) {
properties['ws:filter'] = (HookedServiceEvent e, WebSocketContext socket) {
configuration['ws:filter'] = (HookedServiceEvent e, WebSocketContext socket) {
print('Hello, service filter world!');
return true;
};

9
web/index.html Normal file
View file

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Client</title>
</head>
<body>
<script src="main.dart.js"></script>
</body>
</html>

12
web/main.dart Normal file
View file

@ -0,0 +1,12 @@
import 'dart:html';
import 'package:angel_websocket/browser.dart';
/// Dummy app to ensure client works with DDC.
main() {
var app = new WebSockets(window.location.origin);
window.alert(app.basePath);
app.connect().catchError((_) {
window.alert('no websocket');
});
}