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 = [];
|
List<WebSocket> _clients = [];
|
||||||
StreamController<WebSocketContext> _onConnection =
|
StreamController<WebSocketContext> _onConnection =
|
||||||
new StreamController<WebSocketContext>.broadcast();
|
new StreamController<WebSocketContext>.broadcast();
|
||||||
|
StreamController<WebSocketContext> _onDisconnect =
|
||||||
|
new StreamController<WebSocketContext>.broadcast();
|
||||||
List<WebSocket> get clients => new List.from(_clients, growable: false);
|
List<WebSocket> get clients => new List.from(_clients, growable: false);
|
||||||
List<String> servicesAlreadyWired = [];
|
List<String> servicesAlreadyWired = [];
|
||||||
String endpoint;
|
String endpoint;
|
||||||
Stream<WebSocketContext> get onConnection => _onConnection.stream;
|
Stream<WebSocketContext> get onConnection => _onConnection.stream;
|
||||||
|
Stream<WebSocketContext> get onDisconnection => _onDisconnect.stream;
|
||||||
|
|
||||||
AngelWebSocket(String this.endpoint);
|
AngelWebSocket(String this.endpoint);
|
||||||
|
|
||||||
|
@ -208,8 +211,10 @@ class AngelWebSocket extends AngelPlugin {
|
||||||
ws.listen((data) {
|
ws.listen((data) {
|
||||||
onData(socket, data);
|
onData(socket, data);
|
||||||
}, onDone: () {
|
}, onDone: () {
|
||||||
|
_onDisconnect.add(socket);
|
||||||
_clients.remove(ws);
|
_clients.remove(ws);
|
||||||
}, onError: (e) {
|
}, onError: (e) {
|
||||||
|
_onDisconnect.add(socket);
|
||||||
_clients.remove(ws);
|
_clients.remove(ws);
|
||||||
}, cancelOnError: true);
|
}, cancelOnError: true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -89,6 +89,8 @@ class WebSocketController extends Controller {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ws.onDisconnection.listen(onDisconnect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcast(String eventName, data) {
|
void broadcast(String eventName, data) {
|
||||||
|
@ -97,6 +99,8 @@ class WebSocketController extends Controller {
|
||||||
|
|
||||||
Future onConnect(WebSocketContext socket) async {}
|
Future onConnect(WebSocketContext socket) async {}
|
||||||
|
|
||||||
|
Future onDisconnect(WebSocketContext socket) async {}
|
||||||
|
|
||||||
Future onAllEvents(Map data) async {}
|
Future onAllEvents(Map data) async {}
|
||||||
|
|
||||||
void onData(data) {}
|
void onData(data) {}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: angel_websocket
|
name: angel_websocket
|
||||||
description: WebSocket plugin for Angel
|
description: WebSocket plugin for Angel
|
||||||
version: 1.0.0-dev+3
|
version: 1.0.0-dev+4
|
||||||
author: thosakwe <thosakwe@gmail.com>
|
author: thosakwe <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_websocket
|
homepage: https://github.com/angel-dart/angel_websocket
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in a new issue