platform/packages/websocket/lib/hooks.dart

30 lines
924 B
Dart
Raw Normal View History

2021-05-15 07:19:35 +00:00
import 'package:angel3_framework/angel3_framework.dart';
2017-04-10 01:45:45 +00:00
2017-04-10 01:50:35 +00:00
/// Prevents a WebSocket event from being broadcasted, to any client from the given [provider].
///
/// [provider] can be a String, a [Provider], or an Iterable.
2017-04-23 18:40:30 +00:00
/// If [provider] is `null`, any provider will be blocked.
HookedServiceEventListener doNotBroadcast([provider]) {
2017-04-10 01:45:45 +00:00
return (HookedServiceEvent e) {
2022-02-22 00:07:01 +00:00
if (e.params.containsKey('provider')) {
var eParam = e.params;
2021-04-10 15:12:43 +00:00
var deny = false;
var providers = provider is Iterable ? provider : [provider];
2017-04-10 01:50:35 +00:00
for (var p in providers) {
if (deny) break;
if (p is Providers) {
2021-07-10 04:32:42 +00:00
deny = deny || p == eParam['provider'] || eParam['provider'] == p.via;
2017-04-23 18:40:30 +00:00
} else if (p == null) {
deny = true;
2021-04-10 15:12:43 +00:00
} else {
2021-07-10 04:32:42 +00:00
deny = deny || (eParam['provider'] as Providers).via == p.toString();
2021-04-10 15:12:43 +00:00
}
2017-04-10 01:50:35 +00:00
}
2021-07-10 04:32:42 +00:00
eParam['broadcast'] = false;
2017-04-10 01:50:35 +00:00
}
2017-04-10 01:45:45 +00:00
};
}