diff --git a/CHANGELOG.md b/CHANGELOG.md index aff35596..8958e40a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.0-alpha.7 +* Replace `WebSocketSynchronizer` with `StreamChannel`. + # 2.0.0-alpha.6 * Explicit import of `import 'package:http/io_client.dart' as http;` diff --git a/lib/server.dart b/lib/server.dart index 1fcde714..75295e5f 100644 --- a/lib/server.dart +++ b/lib/server.dart @@ -53,7 +53,7 @@ class AngelWebSocket { new List.unmodifiable(_servicesAlreadyWired); /// Used to notify other nodes of an event's firing. Good for scaled applications. - final WebSocketSynchronizer synchronizer; + final StreamChannel synchronizationChannel; /// Fired on any [WebSocketAction]. Stream get onAction => _onAction.stream; @@ -77,7 +77,7 @@ class AngelWebSocket { {this.sendErrors: false, this.allowClientParams: false, this.allowAuth: true, - this.synchronizer, + this.synchronizationChannel, this.serializer, this.deserializer}) { if (serializer == null) serializer = json.encode; @@ -116,8 +116,8 @@ class AngelWebSocket { } }); - if (synchronizer != null && notify != false) - synchronizer.notifyOthers(event); + if (synchronizationChannel != null && notify != false) + synchronizationChannel.sink.add(event); } /// Returns a list of events yet to be sent. @@ -326,11 +326,11 @@ class AngelWebSocket { wireAllServices(app); }); - if (synchronizer != null) { - synchronizer.stream.listen((e) => batchEvent(e, notify: false)); + if (synchronizationChannel != null) { + synchronizationChannel.stream.listen((e) => batchEvent(e, notify: false)); } - app.shutdownHooks.add((_) => synchronizer?.close()); + app.shutdownHooks.add((_) => synchronizationChannel?.sink?.close()); } /// Handles an incoming [WebSocketContext]. @@ -375,13 +375,3 @@ class AngelWebSocket { } } } - -/// Notifies other nodes of outgoing WWebSocket events, and listens for -/// notifications from other nodes. -abstract class WebSocketSynchronizer { - Stream get stream; - - Future close() => new Future.value(); - - void notifyOthers(WebSocketEvent e); -} diff --git a/pubspec.yaml b/pubspec.yaml index 7205679a..582696c3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: angel_websocket description: WebSocket plugin for Angel. environment: sdk: ">=2.0.0-dev <3.0.0" -version: 2.0.0-alpha.6 +version: 2.0.0-alpha.7 author: Tobe O homepage: https://github.com/angel-dart/angel_websocket dependencies: