listen method
Listen in on the stream, executing the handler for each message. Optionally filtering the messages that the handler is executed on.
Implementation
StreamSubscription<dynamic> listen(
void Function(Map<String, dynamic>) handler, {
bool Function(Map<String, dynamic>)? filter,
}) {
return stream.listen((msg) {
Map<String, dynamic> json =
jsonDecode(msg as String) as Map<String, dynamic>;
if (filter != null) {
if (filter(json)) {
handler(json);
}
} else {
handler(json);
}
});
}