diff --git a/lib/server.dart b/lib/server.dart index f2374acc..9e58c020 100644 --- a/lib/server.dart +++ b/lib/server.dart @@ -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 diff --git a/lib/websocket_controller.dart b/lib/websocket_controller.dart index 4aad8d9c..cfdf42ce 100644 --- a/lib/websocket_controller.dart +++ b/lib/websocket_controller.dart @@ -9,13 +9,15 @@ class ExposeWs { /// A special controller that also supports WebSockets. class WebSocketController extends Controller { + final AngelWebSocket ws; + Map _handlers = {}; Map _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) diff --git a/pubspec.yaml b/pubspec.yaml index fc4e576d..7c1ddf51 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 homepage: https://github.com/angel-dart/angel_websocket dependencies: diff --git a/test/controller/common.dart b/test/controller/common.dart index d23bbee2..1a8f914a 100644 --- a/test/controller/common.dart +++ b/test/controller/common.dart @@ -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...'); diff --git a/test/controller/io_test.dart b/test/controller/io_test.dart index 7e78b796..2b334249 100644 --- a/test/controller/io_test.dart +++ b/test/controller/io_test.dart @@ -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(); diff --git a/test/service/common.dart b/test/service/common.dart index 1abca933..11d265f1 100644 --- a/test/service/common.dart +++ b/test/service/common.dart @@ -13,7 +13,7 @@ class Todo extends Model { class TodoService extends TypedService { 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; }; diff --git a/web/index.html b/web/index.html new file mode 100644 index 00000000..7728ad7e --- /dev/null +++ b/web/index.html @@ -0,0 +1,9 @@ + + + + Client + + + + + \ No newline at end of file diff --git a/web/main.dart b/web/main.dart new file mode 100644 index 00000000..8cab522e --- /dev/null +++ b/web/main.dart @@ -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'); + }); +} \ No newline at end of file