feat(core): Fix typing and remove logging parameter

This commit is contained in:
PapaTutuWawa 2023-03-30 16:17:12 +02:00
parent f355f01fc8
commit 1009a2f967

View File

@ -10,8 +10,6 @@ import 'package:moxxmpp_socket_tcp/src/rfc_2782.dart';
/// TCP socket implementation for XmppConnection /// TCP socket implementation for XmppConnection
class TCPSocketWrapper extends BaseSocketWrapper { class TCPSocketWrapper extends BaseSocketWrapper {
TCPSocketWrapper(this._logData);
/// The underlying Socket/SecureSocket instance. /// The underlying Socket/SecureSocket instance.
Socket? _socket; Socket? _socket;
@ -31,9 +29,6 @@ class TCPSocketWrapper extends BaseSocketWrapper {
/// Logger /// Logger
final Logger _log = Logger('TCPSocketWrapper'); final Logger _log = Logger('TCPSocketWrapper');
/// Flag to indicate if incoming and outgoing data should get logged.
final bool _logData;
/// Indiacted whether the connection is secure. /// Indiacted whether the connection is secure.
bool _secure = false; bool _secure = false;
@ -217,9 +212,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
_socketSubscription = _socket!.listen( _socketSubscription = _socket!.listen(
(List<int> event) { (List<int> event) {
final data = utf8.decode(event); final data = utf8.decode(event);
if (_logData) {
_log.finest('<== $data'); _log.finest('<== $data');
}
_dataStream.add(data); _dataStream.add(data);
}, },
onError: (Object error) { onError: (Object error) {
@ -296,19 +289,17 @@ class TCPSocketWrapper extends BaseSocketWrapper {
_eventStream.stream.asBroadcastStream(); _eventStream.stream.asBroadcastStream();
@override @override
void write(Object? data, {String? redact}) { void write(String data, {String? redact}) {
if (_socket == null) { if (_socket == null) {
_log.severe('Failed to write to socket as _socket is null'); _log.severe('Failed to write to socket as _socket is null');
return; return;
} }
if (data != null && data is String && _logData) {
if (redact != null) { if (redact != null) {
_log.finest('**> $redact'); _log.finest('**> $redact');
} else { } else {
_log.finest('==> $data'); _log.finest('==> $data');
} }
}
try { try {
_socket!.write(data); _socket!.write(data);