From f69d3e474ea08914bdbb50c22e1bbe8da3b26026 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Sat, 17 Sep 2016 23:16:51 -0400 Subject: [PATCH] More changes --- lib/server.dart | 5 +++++ lib/websocket_controller.dart | 4 ++++ pubspec.yaml | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/server.dart b/lib/server.dart index 1dd208b7..a9a2b45a 100644 --- a/lib/server.dart +++ b/lib/server.dart @@ -18,10 +18,13 @@ class AngelWebSocket extends AngelPlugin { List _clients = []; StreamController _onConnection = new StreamController.broadcast(); + StreamController _onDisconnect = + new StreamController.broadcast(); List get clients => new List.from(_clients, growable: false); List servicesAlreadyWired = []; String endpoint; Stream get onConnection => _onConnection.stream; + Stream get onDisconnection => _onDisconnect.stream; AngelWebSocket(String this.endpoint); @@ -208,8 +211,10 @@ class AngelWebSocket extends AngelPlugin { ws.listen((data) { onData(socket, data); }, onDone: () { + _onDisconnect.add(socket); _clients.remove(ws); }, onError: (e) { + _onDisconnect.add(socket); _clients.remove(ws); }, cancelOnError: true); }); diff --git a/lib/websocket_controller.dart b/lib/websocket_controller.dart index 702831d7..4ea621c1 100644 --- a/lib/websocket_controller.dart +++ b/lib/websocket_controller.dart @@ -89,6 +89,8 @@ class WebSocketController extends Controller { } }); }); + + ws.onDisconnection.listen(onDisconnect); } void broadcast(String eventName, data) { @@ -97,6 +99,8 @@ class WebSocketController extends Controller { Future onConnect(WebSocketContext socket) async {} + Future onDisconnect(WebSocketContext socket) async {} + Future onAllEvents(Map data) async {} void onData(data) {} diff --git a/pubspec.yaml b/pubspec.yaml index 6ac23378..63532c92 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_websocket description: WebSocket plugin for Angel -version: 1.0.0-dev+3 +version: 1.0.0-dev+4 author: thosakwe homepage: https://github.com/angel-dart/angel_websocket dependencies: