Moved to WebSocketChannel
This commit is contained in:
parent
3c01c4b360
commit
6eed138927
3 changed files with 15 additions and 10 deletions
|
@ -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<WebSocketEvent> get stream;
|
||||
|
||||
Future close() => new Future.value();
|
||||
|
||||
void notifyOthers(WebSocketEvent e);
|
||||
}
|
||||
|
|
|
@ -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<Null> 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.
|
||||
|
|
|
@ -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 <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_websocket
|
||||
dependencies:
|
||||
|
|
Loading…
Reference in a new issue