@@ -22,8 +22,10 @@ import 'package:dart_rfb/src/protocol/server_init_message.dart';
2222import 'package:fpdart/fpdart.dart' ;
2323import 'package:logging/logging.dart' ;
2424
25+ /// A client that implements communication according to
26+ /// The Remote Framebuffer Protocol, aka RFC 6143, aka VNC).
2527class RemoteFrameBufferClient {
26- static final Logger _logger = Logger ('RemoteFrameBufferClient' );
28+ static final Logger logger = Logger ('RemoteFrameBufferClient' );
2729
2830 final StreamController <RemoteFrameBufferClientUpdate >
2931 _updateStreamController =
@@ -33,10 +35,6 @@ class RemoteFrameBufferClient {
3335
3436 Option <RawSocket > _socket = none ();
3537
36- bool _loggingEnabled = false ;
37-
38- Option <StreamSubscription <LogRecord >> _loggingSubscription = none ();
39-
4038 bool _readLoopRunning = false ;
4139
4240 Option <String > _password = none ();
@@ -45,35 +43,9 @@ class RemoteFrameBufferClient {
4543
4644 Option <RemoteFrameBufferSecurityType > _selectedSecurityType = none ();
4745
48- /// A client that implements communication according to
49- /// The Remote Framebuffer Protocol, aka RFC 6143, aka VNC).
50- RemoteFrameBufferClient () {
51- loggingEnabled = false ;
52- _loggingSubscription = some (
53- Logger .root.onRecord.listen (
54- (final LogRecord logRecord) {
55- // ignore: avoid_print
56- print ('${logRecord .loggerName }: ${logRecord .message }' );
57- },
58- ),
59- );
60- }
61-
6246 /// The config used by the underlying session.
6347 Option <Config > get config => _config;
6448
65- /// Wether logging messages should be printed.
66- bool get loggingEnabled => _loggingEnabled;
67-
68- set loggingEnabled (final bool enabled) {
69- _loggingEnabled = enabled;
70- if (enabled) {
71- Logger .root.level = Level .ALL ;
72- } else {
73- Logger .root.level = Level .OFF ;
74- }
75- }
76-
7749 /// A [Stream] that will give access to all incoming framebuffer updates.
7850 Stream <RemoteFrameBufferClientUpdate > get updateStream =>
7951 _updateStreamController.stream;
@@ -82,11 +54,6 @@ class RemoteFrameBufferClient {
8254 Future <void > close () async {
8355 _readLoopRunning = false ;
8456 await _updateStreamController.close ();
85- await _loggingSubscription.match (
86- () {},
87- (final StreamSubscription <LogRecord > subscription) =>
88- subscription.cancel (),
89- );
9057 }
9158
9259 /// Connect to [hostname] on [port] and perform the protocol handshake,
@@ -133,7 +100,7 @@ class RemoteFrameBufferClient {
133100 x: 0 ,
134101 y: 0 ,
135102 );
136- _logger .log (Level .INFO , '> $requestMessage ' );
103+ logger .log (Level .INFO , '> $requestMessage ' );
137104 socket.write (
138105 requestMessage.toBytes ().asUint8List (),
139106 );
@@ -197,7 +164,7 @@ class RemoteFrameBufferClient {
197164 'Error reading incoming message type' ,
198165 ),
199166 );
200- _logger .log (Level .INFO , '< messageType: $messageType ' );
167+ logger .log (Level .INFO , '< messageType: $messageType ' );
201168 switch (messageType) {
202169 case 0 :
203170 while (socket.available () < 1 ) {
@@ -213,15 +180,15 @@ class RemoteFrameBufferClient {
213180 .readFromSocket (config: config, socket: socket)
214181 .run ())
215182 .match (
216- (final Object error) => _logger .log (
183+ (final Object error) => logger .log (
217184 Level .INFO ,
218185 'Error reading and handling update message: $error ' ,
219186 ),
220187 (
221188 final RemoteFrameBufferFrameBufferUpdateMessage
222189 updateMessage,
223190 ) {
224- _logger .log (
191+ logger .log (
225192 Level .INFO ,
226193 '< ${updateMessage .rectangles .length } update rectangles' ,
227194 );
@@ -296,7 +263,7 @@ class RemoteFrameBufferClient {
296263 );
297264 break ;
298265 default :
299- _logger .log (
266+ logger .log (
300267 Level .INFO ,
301268 'Receive unsupported message type: $messageType ' ,
302269 );
@@ -328,7 +295,7 @@ class RemoteFrameBufferClient {
328295 () => throw Exception ('Error reading security challenge' ),
329296 ),
330297 );
331- _logger .info ('< Security challenge' );
298+ logger .info ('< Security challenge' );
332299 final ByteData encodedAndTruncatedPassword = ByteData .sublistView (
333300 Uint8List .fromList (ascii.encode (password).take (8 ).toList ()),
334301 );
@@ -354,7 +321,7 @@ class RemoteFrameBufferClient {
354321 0 ,
355322 16 ,
356323 );
357- _logger .info ('> Security challenge response' );
324+ logger .info ('> Security challenge response' );
358325 socket.write (
359326 response.buffer
360327 .asUint8List (response.offsetInBytes, response.lengthInBytes),
@@ -400,7 +367,7 @@ class RemoteFrameBufferClient {
400367 ),
401368 ),
402369 );
403- _logger .log (Level .INFO , '< $protocolVersionHandshakeMessage ' );
370+ logger .log (Level .INFO , '< $protocolVersionHandshakeMessage ' );
404371 if (protocolVersionHandshakeMessage.version
405372 is RemoteFrameBufferProtocolVersionUnknown ) {
406373 throw Exception (
@@ -426,7 +393,7 @@ class RemoteFrameBufferClient {
426393 final int numberOfSecurityTypes = optionOf (socket.read (1 )).getOrElse (
427394 () => throw Exception ('Error reading number of security types' ),
428395 )[0 ];
429- _logger .log (
396+ logger .log (
430397 Level .INFO ,
431398 '< numberOfSecurityTypes=$numberOfSecurityTypes ' ,
432399 );
@@ -473,7 +440,7 @@ class RemoteFrameBufferClient {
473440 ),
474441 ),
475442 );
476- _logger .log (Level .INFO , '< $securityResultHandshakeMessage ' );
443+ logger .log (Level .INFO , '< $securityResultHandshakeMessage ' );
477444 if (_password.isNone () &&
478445 securityResultHandshakeMessage.securityTypes.notElem (
479446 const RemoteFrameBufferSecurityType .none (),
@@ -508,7 +475,7 @@ class RemoteFrameBufferClient {
508475 ),
509476 ),
510477 );
511- _logger .info ('< $securityType ' );
478+ logger .info ('< $securityType ' );
512479
513480 if (_password.isNone () &&
514481 securityType != const RemoteFrameBufferSecurityType .none ()) {
@@ -559,7 +526,7 @@ class RemoteFrameBufferClient {
559526 ),
560527 ),
561528 );
562- _logger .log (Level .INFO , '< $securityResultHandshakeMessage ' );
529+ logger .log (Level .INFO , '< $securityResultHandshakeMessage ' );
563530 if (! securityResultHandshakeMessage.success) {
564531 while (socket.available () < 4 ) {
565532 await Future <void >.delayed (Constants .socketReadWaitDuration);
@@ -600,7 +567,7 @@ class RemoteFrameBufferClient {
600567 ),
601568 ),
602569 );
603- _logger .log (Level .INFO , '< $securityResultHandshakeMessage ' );
570+ logger .log (Level .INFO , '< $securityResultHandshakeMessage ' );
604571 if (! securityResultHandshakeMessage.success) {
605572 throw Exception ('Security handshake failed' );
606573 }
@@ -648,7 +615,7 @@ class RemoteFrameBufferClient {
648615 }) =>
649616 TaskEither <Object , void >.tryCatch (
650617 () async {
651- _logger .log (
618+ logger .log (
652619 Level .INFO ,
653620 '> ${const RemoteFrameBufferClientInitMessage (sharedFlag : true )}' ,
654621 );
@@ -672,7 +639,7 @@ class RemoteFrameBufferClient {
672639 () => throw Exception ('Error selecting protocol version' ),
673640 ),
674641 );
675- _logger .log (Level .INFO , '> $message ' );
642+ logger .log (Level .INFO , '> $message ' );
676643 socket.write (message.toBytes ().asUint8List ());
677644 },
678645 (final Object error, final _) => error,
@@ -688,7 +655,7 @@ class RemoteFrameBufferClient {
688655 () => const RemoteFrameBufferSecurityType .none (),
689656 (final _) => const RemoteFrameBufferSecurityType .vncAuthentication (),
690657 );
691- _logger .info ('> $securityType ' );
658+ logger .info ('> $securityType ' );
692659 _selectedSecurityType = some (securityType);
693660 socket.write (securityType.toBytes ().asUint8List ());
694661 },
0 commit comments