disconnect method
Implementation
Future<void> disconnect({String? reason}) async {
print('Disconnecting WebSocket${reason != null ? ': $reason' : ''}');
_heartbeatTimer?.cancel();
_reconnectTimer?.cancel();
if (_channel != null) {
try {
await _channel!.sink.close(1000, reason);
} catch (e) {
print('Error closing WebSocket: $e');
}
_channel = null;
}
_updateState(WebSocketState.disconnected);
}