unsubscribe method
Unsubscribe from a channel
Implementation
Future<void> unsubscribe(String channel) async {
if (_state != connected) {
throw FayeError.network('Not connected');
}
_logger.info('Unsubscribing from $channel');
try {
final response = await _dispatcher.unsubscribe(channel);
final responseMessage = extractBayeuxMessage(response);
if (responseMessage['successful'] == true) {
// Remove all subscriptions for this channel
_subscriptions.removeWhere(
(id, subscription) => subscription.channel.name == channel);
_logger.info('Unsubscribed from $channel successfully');
} else {
throw FayeError.fromBayeux(responseMessage['error'] ?? {});
}
} catch (e) {
_logger.severe('Unsubscription from $channel failed: $e');
rethrow;
}
}