subscribeToEvents method
Subscribes to real-time events from the event log.
filter specifies the criteria for events to receive.
Returns a unique subscription ID that can be used to cancel the subscription.
Use getEventStream to receive the events.
Throws EventLogException if the subscription fails.
Implementation
@override
Future<String> subscribeToEvents(EventFilter filter) async {
try {
final result = await methodChannel.invokeMethod<String>(
'subscribeToEvents',
filter.toMap(),
);
if (result == null) {
throw const SubscriptionException('Failed to create subscription');
}
_subscriptionControllers.putIfAbsent(
result,
() => StreamController<EventRecord>.broadcast(
onCancel: _stopListeningIfIdle,
),
);
_ensureListening();
return result;
} on PlatformException catch (e) {
throw _handlePlatformException(e);
}
}