From 9a18040272099e9a59a0807d5c8f1879e0523b0a Mon Sep 17 00:00:00 2001 From: "thomashii@dukefirehawk.com" Date: Sun, 25 Apr 2021 12:38:24 +0800 Subject: [PATCH] Fixed incompatible return type --- packages/websocket/lib/server.dart | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/websocket/lib/server.dart b/packages/websocket/lib/server.dart index d12ab449..38b048c8 100644 --- a/packages/websocket/lib/server.dart +++ b/packages/websocket/lib/server.dart @@ -95,10 +95,37 @@ class AngelWebSocket { deserializer ??= (params) => params; } - HookedServiceEventListener serviceHook(String path) { + /* + * Deprecated as the return type caused compile time failure. + */ + HookedServiceEventListener _serviceHookOriginal(String path) { return (HookedServiceEvent e) async { - if (e.params != null && e.params['broadcast'] == false) return; + if (e.params != null && e.params['broadcast'] == false) { + return; + } + var event = await transformEvent(e); + event.eventName = '$path::${event.eventName}'; + dynamic _filter(WebSocketContext socket) { + if (e.service.configuration.containsKey('ws:filter')) { + return e.service.configuration['ws:filter'](e, socket); + } else if (e.params != null && e.params.containsKey('ws:filter')) { + return e.params['ws:filter'](e, socket); + } else { + return true; + } + } + + await batchEvent(event, filter: _filter); + }; + } + + FutureOr Function(HookedServiceEvent e) + serviceHook(String path) { + return (HookedServiceEvent e) async { + if (e.params != null && e.params['broadcast'] == false) { + return; + } var event = await transformEvent(e); event.eventName = '$path::${event.eventName}';