@@ -17,8 +17,7 @@ class ProtocolDiscovery {
17
17
this .portForwarder,
18
18
this .hostPort,
19
19
this .ipv6,
20
- }) : assert (logReader != null ),
21
- _prefix = '$serviceName listening on ' {
20
+ }) : assert (logReader != null ) {
22
21
_deviceLogSubscription = logReader.logLines.listen (_handleLine);
23
22
}
24
23
@@ -30,7 +29,8 @@ class ProtocolDiscovery {
30
29
}) {
31
30
const String kObservatoryService = 'Observatory' ;
32
31
return new ProtocolDiscovery ._(
33
- logReader, kObservatoryService,
32
+ logReader,
33
+ kObservatoryService,
34
34
portForwarder: portForwarder,
35
35
hostPort: hostPort,
36
36
ipv6: ipv6,
@@ -43,7 +43,6 @@ class ProtocolDiscovery {
43
43
final int hostPort;
44
44
final bool ipv6;
45
45
46
- final String _prefix;
47
46
final Completer <Uri > _completer = new Completer <Uri >();
48
47
49
48
StreamSubscription <String > _deviceLogSubscription;
@@ -60,10 +59,13 @@ class ProtocolDiscovery {
60
59
61
60
void _handleLine (String line) {
62
61
Uri uri;
63
- final int index = line.indexOf (_prefix + 'http://' );
64
- if (index >= 0 ) {
62
+
63
+ final RegExp r = new RegExp ('${RegExp .escape (serviceName )} listening on (http://[^ \n ]+)' );
64
+ final Match match = r.firstMatch (line);
65
+
66
+ if (match != null ) {
65
67
try {
66
- uri = Uri .parse (line. substring (index + _prefix.length) );
68
+ uri = Uri .parse (match[ 1 ] );
67
69
} catch (error) {
68
70
_stopScrapingLogs ();
69
71
_completer.completeError (error);
@@ -75,6 +77,7 @@ class ProtocolDiscovery {
75
77
_stopScrapingLogs ();
76
78
_completer.complete (_forwardPort (uri));
77
79
}
80
+
78
81
}
79
82
80
83
Future <Uri > _forwardPort (Uri deviceUri) async {
0 commit comments