@@ -17,8 +17,7 @@ class ProtocolDiscovery {
1717 this .portForwarder,
1818 this .hostPort,
1919 this .ipv6,
20- }) : assert (logReader != null ),
21- _prefix = '$serviceName listening on ' {
20+ }) : assert (logReader != null ) {
2221 _deviceLogSubscription = logReader.logLines.listen (_handleLine);
2322 }
2423
@@ -30,7 +29,8 @@ class ProtocolDiscovery {
3029 }) {
3130 const String kObservatoryService = 'Observatory' ;
3231 return new ProtocolDiscovery ._(
33- logReader, kObservatoryService,
32+ logReader,
33+ kObservatoryService,
3434 portForwarder: portForwarder,
3535 hostPort: hostPort,
3636 ipv6: ipv6,
@@ -43,7 +43,6 @@ class ProtocolDiscovery {
4343 final int hostPort;
4444 final bool ipv6;
4545
46- final String _prefix;
4746 final Completer <Uri > _completer = new Completer <Uri >();
4847
4948 StreamSubscription <String > _deviceLogSubscription;
@@ -60,10 +59,13 @@ class ProtocolDiscovery {
6059
6160 void _handleLine (String line) {
6261 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 ) {
6567 try {
66- uri = Uri .parse (line. substring (index + _prefix.length) );
68+ uri = Uri .parse (match[ 1 ] );
6769 } catch (error) {
6870 _stopScrapingLogs ();
6971 _completer.completeError (error);
@@ -75,6 +77,7 @@ class ProtocolDiscovery {
7577 _stopScrapingLogs ();
7678 _completer.complete (_forwardPort (uri));
7779 }
80+
7881 }
7982
8083 Future <Uri > _forwardPort (Uri deviceUri) async {
0 commit comments