diff --git a/lib/server.dart b/lib/server.dart index 8d6a8628..f2374acc 100644 --- a/lib/server.dart +++ b/lib/server.dart @@ -9,6 +9,8 @@ import 'package:angel_auth/angel_auth.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:json_god/json_god.dart' as god; import 'package:merge_map/merge_map.dart'; +import 'package:web_socket_channel/io.dart'; +import 'package:web_socket_channel/web_socket_channel.dart'; import 'angel_websocket.dart'; export 'angel_websocket.dart'; @@ -108,7 +110,7 @@ class AngelWebSocket { var result = true; if (filter != null) result = await filter(client); if (result == true) { - client.io.add((serializer ?? god.serialize)(event.toJson())); + client.channel.sink.add((serializer ?? god.serialize)(event.toJson())); } }); @@ -330,7 +332,8 @@ class AngelWebSocket { ..end(); var ws = await WebSocketTransformer.upgrade(req.io); - var socket = new WebSocketContext(ws, req, res); + var channel = new IOWebSocketChannel(ws); + var socket = new WebSocketContext(channel, req, res); _clients.add(socket); await handleConnect(socket); @@ -364,5 +367,7 @@ class AngelWebSocket { abstract class WebSocketSynchronizer { Stream get stream; + Future close() => new Future.value(); + void notifyOthers(WebSocketEvent e); } diff --git a/lib/websocket_context.dart b/lib/websocket_context.dart index 7c97689f..fb4196dd 100644 --- a/lib/websocket_context.dart +++ b/lib/websocket_context.dart @@ -6,8 +6,8 @@ class WebSocketContext { /// Use this to listen for events. _WebSocketEventTable on = new _WebSocketEventTable(); - /// The underlying [WebSocket] instance. - final WebSocket io; + /// The underlying [WebSocketChannel]. + final WebSocketChannel channel; /// The original [RequestContext]. final RequestContext request; @@ -28,15 +28,14 @@ class WebSocketContext { /// Fired once the underlying [WebSocket] closes. Stream get onClose => _onClose.stream; - /// Fired when any data is sent through [io]. + /// Fired when any data is sent through [channel]. Stream get onData => _onData.stream; - WebSocketContext(WebSocket this.io, RequestContext this.request, - ResponseContext this.response); + WebSocketContext(this.channel, this.request, this.response); /// Closes the underlying [WebSocket]. Future close([int code, String reason]) async { - await io.close(code, reason); + await channel.sink.close(code, reason); _onAction.close(); _onData.close(); _onClose.add(null); @@ -45,7 +44,8 @@ class WebSocketContext { /// Sends an arbitrary [WebSocketEvent]; void send(String eventName, data) { - io.add(god.serialize(new WebSocketEvent(eventName: eventName, data: data))); + channel.sink.add( + god.serialize(new WebSocketEvent(eventName: eventName, data: data))); } /// Sends an error event. diff --git a/pubspec.yaml b/pubspec.yaml index 828ce5d3..fc4e576d 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 +version: 1.1.0-alpha+1 author: Tobe O homepage: https://github.com/angel-dart/angel_websocket dependencies: