disconnect method
Disconnects from the STOMP server
Implementation
Future<void> disconnect() async {
if (_state == StompClientState.disconnected || _state == StompClientState.disconnecting) {
return;
}
_setState(StompClientState.disconnecting);
try {
if (_stream != null && !_stream!.isClosed) {
// Send DISCONNECT frame with receipt
final receiptId = _generateReceiptId();
final disconnectFrame = StompFrameFactory.disconnect(receipt: receiptId);
await _sendFrame(disconnectFrame);
// Wait for receipt
try {
await _waitForReceipt(receiptId, const Duration(seconds: 5));
} catch (e) {
_logger.warning('Did not receive DISCONNECT receipt: $e');
}
}
} catch (e) {
_logger.warning('Error during disconnect: $e');
} finally {
await _cleanup();
_setState(StompClientState.disconnected);
_logger.info('Disconnected from STOMP server $_serverPeerId');
}
}