More changes
This commit is contained in:
parent
00b681f04b
commit
f69d3e474e
3 changed files with 10 additions and 1 deletions
|
@ -18,10 +18,13 @@ class AngelWebSocket extends AngelPlugin {
|
|||
List<WebSocket> _clients = [];
|
||||
StreamController<WebSocketContext> _onConnection =
|
||||
new StreamController<WebSocketContext>.broadcast();
|
||||
StreamController<WebSocketContext> _onDisconnect =
|
||||
new StreamController<WebSocketContext>.broadcast();
|
||||
List<WebSocket> get clients => new List.from(_clients, growable: false);
|
||||
List<String> servicesAlreadyWired = [];
|
||||
String endpoint;
|
||||
Stream<WebSocketContext> get onConnection => _onConnection.stream;
|
||||
Stream<WebSocketContext> 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);
|
||||
});
|
||||
|
|
|
@ -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) {}
|
||||
|
|
|
@ -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 <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_websocket
|
||||
dependencies:
|
||||
|
|
Loading…
Reference in a new issue