Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
737a55ef
Commit
737a55ef
authored
Nov 28, 2016
by
Dan Rubel
Committed by
GitHub
Nov 28, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle new Observatory URL (#6992)
parent
27cceff2
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
153 additions
and
125 deletions
+153
-125
android_device.dart
packages/flutter_tools/lib/src/android/android_device.dart
+22
-21
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+2
-2
trace.dart
packages/flutter_tools/lib/src/commands/trace.dart
+7
-3
device.dart
packages/flutter_tools/lib/src/device.dart
+9
-9
hot.dart
packages/flutter_tools/lib/src/hot.dart
+6
-6
devices.dart
packages/flutter_tools/lib/src/ios/devices.dart
+39
-32
simulators.dart
packages/flutter_tools/lib/src/ios/simulators.dart
+5
-5
protocol_discovery.dart
packages/flutter_tools/lib/src/protocol_discovery.dart
+13
-12
resident_runner.dart
packages/flutter_tools/lib/src/resident_runner.dart
+6
-6
run.dart
packages/flutter_tools/lib/src/run.dart
+8
-9
vmservice.dart
packages/flutter_tools/lib/src/vmservice.dart
+11
-8
protocol_discovery_test.dart
packages/flutter_tools/test/protocol_discovery_test.dart
+25
-12
No files found.
packages/flutter_tools/lib/src/android/android_device.dart
View file @
737a55ef
...
...
@@ -259,14 +259,15 @@ class AndroidDevice extends Device {
return
true
;
}
Future
<
int
>
_forwardPort
(
String
service
,
int
devicePort
,
int
port
)
async
{
Future
<
Uri
>
_forwardUriToNewPort
(
String
service
,
Uri
deviceUri
,
int
port
)
async
{
try
{
// Set up port forwarding for observatory.
port
=
await
portForwarder
.
forward
(
devicePort
,
hostPort:
port
);
printTrace
(
'
$service
listening on http://127.0.0.1:
$port
'
);
return
port
;
port
=
await
portForwarder
.
forward
(
deviceUri
.
port
,
hostPort:
port
);
Uri
localUri
=
deviceUri
.
replace
(
port:
port
);
printTrace
(
'
$service
listening on
$localUri
'
);
return
localUri
;
}
catch
(
e
)
{
printError
(
'Unable to forward
port
$port
:
$e
'
);
printError
(
'Unable to forward
device port
${deviceUri.port}
to
$port
:
$e
'
);
}
return
null
;
}
...
...
@@ -355,35 +356,35 @@ class AndroidDevice extends Device {
printTrace
(
'Waiting for observatory port to be available...'
);
try
{
int
observatoryDevicePort
,
diagnosticDevicePort
;
Uri
observatoryDeviceUri
,
diagnosticDeviceUri
;
if
(
debuggingOptions
.
buildMode
==
BuildMode
.
debug
)
{
Future
<
List
<
int
>>
scrapeServicePort
s
=
Future
.
wait
(
<
Future
<
int
>>[
observatoryDiscovery
.
nextPort
(),
diagnosticDiscovery
.
nextPort
()]
Future
<
List
<
Uri
>>
scrapeServiceUri
s
=
Future
.
wait
(
<
Future
<
Uri
>>[
observatoryDiscovery
.
nextUri
(),
diagnosticDiscovery
.
nextUri
()]
);
List
<
int
>
devicePorts
=
await
scrapeServicePort
s
.
timeout
(
new
Duration
(
seconds:
20
));
observatoryDevice
Port
=
devicePort
s
[
0
];
diagnosticDevice
Port
=
devicePort
s
[
1
];
List
<
Uri
>
deviceUris
=
await
scrapeServiceUri
s
.
timeout
(
new
Duration
(
seconds:
20
));
observatoryDevice
Uri
=
deviceUri
s
[
0
];
diagnosticDevice
Uri
=
deviceUri
s
[
1
];
}
else
{
observatoryDevice
Port
=
await
observatoryDiscovery
.
nextPort
().
timeout
(
new
Duration
(
seconds:
20
));
observatoryDevice
Uri
=
await
observatoryDiscovery
.
nextUri
().
timeout
(
new
Duration
(
seconds:
20
));
}
printTrace
(
'
observatory port on device:
$observatoryDevicePort
'
);
printTrace
(
'
Observatory Uri on device:
$observatoryDeviceUri
'
);
int
observatoryLocalPort
=
await
debuggingOptions
.
findBestObservatoryPort
();
// TODO(devoncarew): Remember the forwarding information (so we can later remove the
// port forwarding).
observatoryLocalPort
=
await
_forwardPort
(
ProtocolDiscovery
.
kObservatoryService
,
observatoryDevicePort
,
observatoryLocalPort
);
Uri
observatoryLocalUri
=
await
_forwardUriToNewPort
(
ProtocolDiscovery
.
kObservatoryService
,
observatoryDeviceUri
,
observatoryLocalPort
);
int
diagnosticLocalPort
;
if
(
diagnosticDevice
Port
!=
null
)
{
printTrace
(
'
diagnostic port on device:
$diagnosticDevicePort
'
);
diagnosticLocalPort
=
await
debuggingOptions
.
findBestDiagnosticPort
();
diagnosticLocal
Port
=
await
_forwardPort
(
ProtocolDiscovery
.
kDiagnosticService
,
diagnosticDevicePort
,
diagnosticLocalPort
);
Uri
diagnosticLocalUri
;
if
(
diagnosticDevice
Uri
!=
null
)
{
printTrace
(
'
Diagnostic Server Uri on device:
$diagnosticDeviceUri
'
);
int
diagnosticLocalPort
=
await
debuggingOptions
.
findBestDiagnosticPort
();
diagnosticLocal
Uri
=
await
_forwardUriToNewPort
(
ProtocolDiscovery
.
kDiagnosticService
,
diagnosticDeviceUri
,
diagnosticLocalPort
);
}
return
new
LaunchResult
.
succeeded
(
observatory
Port:
observatoryLocalPort
,
diagnostic
Port:
diagnosticLocalPort
observatory
Uri:
observatoryLocalUri
,
diagnostic
Uri:
diagnosticLocalUri
,
);
}
catch
(
error
)
{
if
(
error
is
TimeoutException
)
...
...
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
737a55ef
...
...
@@ -359,8 +359,8 @@ class AppDomain extends Domain {
connectionInfoCompleter
=
new
Completer
<
DebugConnectionInfo
>();
connectionInfoCompleter
.
future
.
then
((
DebugConnectionInfo
info
)
{
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>{
'port'
:
info
.
port
,
'wsUri'
:
info
.
wsUri
'port'
:
info
.
httpUri
.
port
,
'wsUri'
:
info
.
wsUri
.
toString
(),
};
if
(
info
.
baseUri
!=
null
)
params
[
'baseUri'
]
=
info
.
baseUri
;
...
...
packages/flutter_tools/lib/src/commands/trace.dart
View file @
737a55ef
...
...
@@ -55,10 +55,14 @@ class TraceCommand extends FlutterCommand {
Future
<
Null
>
runCommand
()
async
{
int
observatoryPort
=
int
.
parse
(
argResults
[
'debug-port'
]);
// TODO(danrubel): this will break if we move to the new observatory URL
// See https://github.com/flutter/flutter/issues/7038
Uri
observatoryUri
=
Uri
.
parse
(
'http://127.0.0.1:
$observatoryPort
'
);
Tracing
tracing
;
try
{
tracing
=
await
Tracing
.
connect
(
observatory
Port
);
tracing
=
await
Tracing
.
connect
(
observatory
Uri
);
}
catch
(
error
)
{
throwToolExit
(
'Error connecting to observatory:
$error
'
);
}
...
...
@@ -100,8 +104,8 @@ class TraceCommand extends FlutterCommand {
class
Tracing
{
Tracing
(
this
.
vmService
);
static
Future
<
Tracing
>
connect
(
int
port
)
{
return
VMService
.
connect
(
port
).
then
((
VMService
observatory
)
=>
new
Tracing
(
observatory
));
static
Future
<
Tracing
>
connect
(
Uri
uri
)
{
return
VMService
.
connect
(
uri
).
then
((
VMService
observatory
)
=>
new
Tracing
(
observatory
));
}
final
VMService
vmService
;
...
...
packages/flutter_tools/lib/src/device.dart
View file @
737a55ef
...
...
@@ -296,22 +296,22 @@ class DebuggingOptions {
}
class
LaunchResult
{
LaunchResult
.
succeeded
({
this
.
observatory
Port
,
this
.
diagnosticPort
})
:
started
=
true
;
LaunchResult
.
failed
()
:
started
=
false
,
observatory
Port
=
null
,
diagnosticPort
=
null
;
LaunchResult
.
succeeded
({
this
.
observatory
Uri
,
this
.
diagnosticUri
})
:
started
=
true
;
LaunchResult
.
failed
()
:
started
=
false
,
observatory
Uri
=
null
,
diagnosticUri
=
null
;
bool
get
hasObservatory
=>
observatory
Port
!=
null
;
bool
get
hasObservatory
=>
observatory
Uri
!=
null
;
final
bool
started
;
final
int
observatoryPort
;
final
int
diagnosticPort
;
final
Uri
observatoryUri
;
final
Uri
diagnosticUri
;
@override
String
toString
()
{
StringBuffer
buf
=
new
StringBuffer
(
'started=
$started
'
);
if
(
observatory
Port
!=
null
)
buf
.
write
(
', observatory=
$observatory
Port
'
);
if
(
diagnostic
Port
!=
null
)
buf
.
write
(
', diagnostic=
$diagnostic
Port
'
);
if
(
observatory
Uri
!=
null
)
buf
.
write
(
', observatory=
$observatory
Uri
'
);
if
(
diagnostic
Uri
!=
null
)
buf
.
write
(
', diagnostic=
$diagnostic
Uri
'
);
return
buf
.
toString
();
}
}
...
...
packages/flutter_tools/lib/src/hot.dart
View file @
737a55ef
...
...
@@ -108,7 +108,7 @@ class HotRunner extends ResidentRunner {
final
String
applicationBinary
;
bool
get
prebuiltMode
=>
applicationBinary
!=
null
;
Set
<
String
>
_dartDependencies
;
int
_observatoryPort
;
Uri
_observatoryUri
;
AssetBundle
_bundle
;
AssetBundle
get
bundle
=>
_bundle
;
final
bool
benchmarkMode
;
...
...
@@ -216,9 +216,9 @@ class HotRunner extends ResidentRunner {
return
2
;
}
_observatory
Port
=
result
.
observatoryPort
;
_observatory
Uri
=
result
.
observatoryUri
;
try
{
await
connectToServiceProtocol
(
_observatory
Port
);
await
connectToServiceProtocol
(
_observatory
Uri
);
}
catch
(
error
)
{
printError
(
'Error connecting to the service protocol:
$error
'
);
return
2
;
...
...
@@ -230,8 +230,8 @@ class HotRunner extends ResidentRunner {
if
(
connectionInfoCompleter
!=
null
)
{
connectionInfoCompleter
.
complete
(
new
DebugConnectionInfo
(
port:
_observatoryPort
,
wsUri:
'ws://localhost:
$_observatoryPort
/ws'
,
httpUri:
_observatoryUri
,
wsUri:
vmService
.
wsAddress
,
baseUri:
baseUri
.
toString
()
)
);
...
...
@@ -533,7 +533,7 @@ class HotRunner extends ResidentRunner {
ansiAlternative:
'
$red$fire$bold
To hot reload your app on the fly, '
'press "r" or F5. To restart the app entirely, press "R".
$reset
'
);
printStatus
(
'The Observatory debugger and profiler is available at:
http://127.0.0.1:
$_observatoryPort
/
'
);
printStatus
(
'The Observatory debugger and profiler is available at:
$_observatoryUri
'
);
if
(
details
)
{
printHelpDetails
();
printStatus
(
'To repeat this help message, press "h" or F1. To quit, press "q", F10, or Ctrl-C.'
);
...
...
packages/flutter_tools/lib/src/ios/devices.dart
View file @
737a55ef
...
...
@@ -244,8 +244,8 @@ class IOSDevice extends Device {
}
int
installationResult
=
-
1
;
int
localObsPort
;
int
localDiagPort
;
Uri
localObsUri
;
Uri
localDiagUri
;
if
(!
debuggingOptions
.
debuggingEnabled
)
{
// If debugging is not enabled, just launch the application and continue.
...
...
@@ -256,30 +256,34 @@ class IOSDevice extends Device {
// ports post launch.
printTrace
(
"Debugging is enabled, connecting to observatory and the diagnostic server"
);
Future
<
int
>
forwardObsPort
=
_acquireAndForwardPort
(
app
,
ProtocolDiscovery
.
kObservatoryService
,
debuggingOptions
.
observatoryPort
);
Future
<
int
>
forwardDiagPort
;
Future
<
Uri
>
forwardObsUri
=
_acquireAndForwardUriToNewPort
(
app
,
ProtocolDiscovery
.
kObservatoryService
,
debuggingOptions
.
observatoryPort
,
);
Future
<
Uri
>
forwardDiagUri
;
if
(
debuggingOptions
.
buildMode
==
BuildMode
.
debug
)
{
forwardDiagPort
=
_acquireAndForwardPort
(
app
,
ProtocolDiscovery
.
kDiagnosticService
,
debuggingOptions
.
diagnosticPort
);
forwardDiagUri
=
_acquireAndForwardUriToNewPort
(
app
,
ProtocolDiscovery
.
kDiagnosticService
,
debuggingOptions
.
diagnosticPort
,
);
}
else
{
forwardDiag
Port
=
new
Future
<
int
>.
value
(
null
);
forwardDiag
Uri
=
new
Future
<
Uri
>.
value
(
null
);
}
Future
<
int
>
launch
=
runCommandAndStreamOutput
(
launchCommand
,
trace:
true
);
List
<
int
>
port
s
=
await
launch
.
then
((
int
result
)
async
{
List
<
Uri
>
uri
s
=
await
launch
.
then
((
int
result
)
async
{
installationResult
=
result
;
if
(
result
!=
0
)
{
printTrace
(
"Failed to launch the application on device."
);
return
<
int
>[
null
,
null
];
return
<
Uri
>[
null
,
null
];
}
printTrace
(
"Application launched on the device. Attempting to forward ports."
);
return
await
Future
.
wait
(<
Future
<
int
>>[
forwardObsPort
,
forwardDiagPort
])
return
await
Future
.
wait
(<
Future
<
Uri
>>[
forwardObsUri
,
forwardDiagUri
])
.
timeout
(
kPortForwardTimeout
,
onTimeout:
()
{
...
...
@@ -288,11 +292,11 @@ class IOSDevice extends Device {
);
});
printTrace
(
"
Local Observatory Port:
${port
s[0]}
"
);
printTrace
(
"
Local Diagnostic Server Port:
${port
s[1]}
"
);
printTrace
(
"
Observatory Uri on device:
${uri
s[0]}
"
);
printTrace
(
"
Diagnostic Server Uri on device:
${uri
s[1]}
"
);
localObs
Port
=
port
s
[
0
];
localDiag
Port
=
port
s
[
1
];
localObs
Uri
=
uri
s
[
0
];
localDiag
Uri
=
uri
s
[
1
];
}
if
(
installationResult
!=
0
)
{
...
...
@@ -303,25 +307,25 @@ class IOSDevice extends Device {
return
new
LaunchResult
.
failed
();
}
return
new
LaunchResult
.
succeeded
(
observatory
Port:
localObsPort
,
diagnosticPort:
localDiagPort
);
return
new
LaunchResult
.
succeeded
(
observatory
Uri:
localObsUri
,
diagnosticUri:
localDiagUri
);
}
Future
<
int
>
_acquireAndForward
Port
(
Future
<
Uri
>
_acquireAndForwardUriToNew
Port
(
ApplicationPackage
app
,
String
serviceName
,
int
localPort
)
async
{
Duration
stepTimeout
=
const
Duration
(
seconds:
60
);
Future
<
int
>
remote
=
new
ProtocolDiscovery
(
getLogReader
(
app:
app
),
serviceName
).
nextPort
();
Future
<
Uri
>
remote
=
new
ProtocolDiscovery
(
getLogReader
(
app:
app
),
serviceName
).
nextUri
();
int
remotePort
=
await
remote
.
timeout
(
stepTimeout
,
Uri
remoteUri
=
await
remote
.
timeout
(
stepTimeout
,
onTimeout:
()
{
printTrace
(
"Timeout while attempting to retrieve remote
port
for
$serviceName
"
);
printTrace
(
"Timeout while attempting to retrieve remote
Uri
for
$serviceName
"
);
return
null
;
});
if
(
remote
Port
==
null
)
{
printTrace
(
"Could not read
port
on device for
$serviceName
"
);
if
(
remote
Uri
==
null
)
{
printTrace
(
"Could not read
Uri
on device for
$serviceName
"
);
return
null
;
}
...
...
@@ -330,19 +334,22 @@ class IOSDevice extends Device {
printTrace
(
"Auto selected local port to
$localPort
"
);
}
int
forwardResult
=
await
portForwarder
.
forward
(
remotePort
,
hostPort:
localPort
).
timeout
(
stepTimeout
,
onTimeout:
()
{
printTrace
(
"Timeout while atempting to foward port for
$serviceName
"
);
return
null
;
});
int
forwardResult
=
await
portForwarder
.
forward
(
remoteUri
.
port
,
hostPort:
localPort
)
.
timeout
(
stepTimeout
,
onTimeout:
()
{
printTrace
(
"Timeout while atempting to foward port for
$serviceName
"
);
return
null
;
});
if
(
forwardResult
==
null
)
{
printTrace
(
"Could not foward remote
$serviceName
port
$remote
Port
to local port
$localPort
"
);
printTrace
(
"Could not foward remote
$serviceName
port
$remote
Uri
to local port
$localPort
"
);
return
null
;
}
printStatus
(
'
$serviceName
listening on http://127.0.0.1:
$localPort
'
);
return
localPort
;
Uri
forwardUri
=
remoteUri
.
replace
(
port:
forwardResult
);
printStatus
(
'
$serviceName
listening on
$forwardUri
'
);
return
forwardUri
;
}
@override
...
...
packages/flutter_tools/lib/src/ios/simulators.dart
View file @
737a55ef
...
...
@@ -474,12 +474,12 @@ class IOSSimulator extends Device {
printTrace
(
'Waiting for observatory port to be available...'
);
try
{
int
devicePort
=
await
observatoryDiscovery
.
next
Port
()
Uri
deviceUri
=
await
observatoryDiscovery
.
next
Uri
()
.
timeout
(
new
Duration
(
seconds:
20
));
printTrace
(
'
service protocol port =
$devicePort
'
);
printStatus
(
'Observatory listening on
http://127.0.0.1:
$devicePort
'
);
return
new
LaunchResult
.
succeeded
(
observatory
Port:
devicePort
);
printTrace
(
'
Observatory Uri on simulator:
$deviceUri
'
);
printStatus
(
'Observatory listening on
$deviceUri
'
);
return
new
LaunchResult
.
succeeded
(
observatory
Uri:
deviceUri
);
}
catch
(
error
)
{
if
(
error
is
TimeoutException
)
printError
(
'Timed out while waiting for a debug connection.'
);
...
...
packages/flutter_tools/lib/src/protocol_discovery.dart
View file @
737a55ef
...
...
@@ -21,37 +21,38 @@ class ProtocolDiscovery {
final
DeviceLogReader
_logReader
;
final
String
_serviceName
;
Completer
<
int
>
_completer
=
new
Completer
<
int
>();
Completer
<
Uri
>
_completer
=
new
Completer
<
Uri
>();
StreamSubscription
<
String
>
_subscription
;
/// The [Future] returned by this function will complete when the next service
///
protocol port
is found.
Future
<
int
>
nextPort
()
=>
_completer
.
future
;
///
Uri
is found.
Future
<
Uri
>
nextUri
()
=>
_completer
.
future
;
void
cancel
()
{
_subscription
.
cancel
();
}
void
_onLine
(
String
line
)
{
int
portNumber
=
0
;
Uri
uri
;
if
(
line
.
contains
(
'
$_serviceName
listening on http://'
))
{
RegExp
portExp
=
new
RegExp
(
r"http://\d+.\d+.\d+.\d+:\d+\S*"
);
try
{
RegExp
portExp
=
new
RegExp
(
r"\d+.\d+.\d+.\d+:(\d+)"
);
String
port
=
portExp
.
firstMatch
(
line
).
group
(
1
);
portNumber
=
int
.
parse
(
port
);
String
match
=
portExp
.
stringMatch
(
line
);
if
(
match
!=
null
)
uri
=
Uri
.
parse
(
match
);
}
catch
(
_
)
{
// Ignore errors.
}
}
if
(
portNumber
!=
0
)
_located
(
portNumber
);
if
(
uri
!=
null
)
_located
(
uri
);
}
void
_located
(
int
port
)
{
void
_located
(
Uri
uri
)
{
assert
(
_completer
!=
null
);
assert
(!
_completer
.
isCompleted
);
_completer
.
complete
(
port
);
_completer
=
new
Completer
<
int
>();
_completer
.
complete
(
uri
);
_completer
=
new
Completer
<
Uri
>();
}
}
packages/flutter_tools/lib/src/resident_runner.dart
View file @
737a55ef
...
...
@@ -119,12 +119,12 @@ abstract class ResidentRunner {
_loggingSubscription
=
null
;
}
Future
<
Null
>
connectToServiceProtocol
(
int
port
)
async
{
Future
<
Null
>
connectToServiceProtocol
(
Uri
uri
)
async
{
if
(!
debuggingOptions
.
debuggingEnabled
)
{
return
new
Future
<
Null
>.
error
(
'Error the service protocol is not enabled.'
);
}
vmService
=
await
VMService
.
connect
(
port
);
printTrace
(
'Connected to service protocol
on port
$port
'
);
vmService
=
await
VMService
.
connect
(
uri
);
printTrace
(
'Connected to service protocol
:
$uri
'
);
await
vmService
.
getVM
();
// Refresh the view list.
...
...
@@ -287,9 +287,9 @@ String getMissingPackageHintForPlatform(TargetPlatform platform) {
}
class
DebugConnectionInfo
{
DebugConnectionInfo
({
this
.
port
,
this
.
wsUri
,
this
.
baseUri
});
DebugConnectionInfo
({
this
.
httpUri
,
this
.
wsUri
,
this
.
baseUri
});
final
int
port
;
final
String
wsUri
;
final
Uri
httpUri
;
final
Uri
wsUri
;
final
String
baseUri
;
}
packages/flutter_tools/lib/src/run.dart
View file @
737a55ef
...
...
@@ -119,19 +119,18 @@ class RunAndStayResident extends ResidentRunner {
startTime
.
stop
();
// Connect to observatory.
if
(
debuggingOptions
.
debuggingEnabled
)
{
await
connectToServiceProtocol
(
_result
.
observatoryUri
);
}
if
(
_result
.
hasObservatory
)
{
int
port
=
_result
.
observatoryPort
;
connectionInfoCompleter
?.
complete
(
new
DebugConnectionInfo
(
port:
port
,
wsUri:
'ws://localhost:
$port
/ws'
httpUri:
_result
.
observatoryUri
,
wsUri:
vmService
.
wsAddress
,
));
}
// Connect to observatory.
if
(
debuggingOptions
.
debuggingEnabled
)
{
await
connectToServiceProtocol
(
_result
.
observatoryPort
);
}
printTrace
(
'Application running.'
);
if
(
vmService
!=
null
)
{
...
...
@@ -176,7 +175,7 @@ class RunAndStayResident extends ResidentRunner {
void
printHelp
({
@required
bool
details
})
{
bool
haveDetails
=
false
;
if
(
_result
.
hasObservatory
)
printStatus
(
'The Observatory debugger and profiler is available at:
http://127.0.0.1:
${_result.observatoryPort}
/
'
);
printStatus
(
'The Observatory debugger and profiler is available at:
${_result.observatoryUri}
'
);
if
(
supportsServiceProtocol
)
{
haveDetails
=
true
;
if
(
details
)
...
...
packages/flutter_tools/lib/src/vmservice.dart
View file @
737a55ef
...
...
@@ -14,7 +14,7 @@ import 'globals.dart';
/// A connection to the Dart VM Service.
class
VMService
{
VMService
.
_
(
this
.
peer
,
this
.
port
,
this
.
http
Address
)
{
VMService
.
_
(
this
.
peer
,
this
.
httpAddress
,
this
.
ws
Address
)
{
_vm
=
new
VM
.
_empty
(
this
);
peer
.
registerMethod
(
'streamNotify'
,
(
rpc
.
Parameters
event
)
{
...
...
@@ -23,21 +23,24 @@ class VMService {
}
/// Connect to '127.0.0.1' at [port].
static
Future
<
VMService
>
connect
(
int
port
)
async
{
Uri
uri
=
new
Uri
(
scheme:
'ws'
,
host:
'127.0.0.1'
,
port:
port
,
path:
'ws'
);
static
Future
<
VMService
>
connect
(
Uri
httpUri
)
async
{
String
wsPath
=
httpUri
.
path
;
if
(!
wsPath
.
endsWith
(
'/'
))
wsPath
+=
'/'
;
wsPath
+=
'ws'
;
Uri
wsUri
=
httpUri
.
replace
(
scheme:
'ws'
,
path:
wsPath
);
WebSocket
ws
;
try
{
ws
=
await
WebSocket
.
connect
(
u
ri
.
toString
());
ws
=
await
WebSocket
.
connect
(
wsU
ri
.
toString
());
}
catch
(
e
)
{
return
new
Future
<
VMService
>.
error
(
'Failed to connect to
$
u
ri
\n
$e
'
);
return
new
Future
<
VMService
>.
error
(
'Failed to connect to
$
wsU
ri
\n
$e
'
);
}
rpc
.
Peer
peer
=
new
rpc
.
Peer
(
new
IOWebSocketChannel
(
ws
).
cast
());
peer
.
listen
();
Uri
httpAddress
=
new
Uri
(
scheme:
'http'
,
host:
'127.0.0.1'
,
port:
port
);
return
new
VMService
.
_
(
peer
,
port
,
httpAddress
);
return
new
VMService
.
_
(
peer
,
httpUri
,
wsUri
);
}
final
Uri
httpAddress
;
final
int
port
;
final
Uri
wsAddress
;
final
rpc
.
Peer
peer
;
VM
_vm
;
...
...
packages/flutter_tools/test/protocol_discovery_test.dart
View file @
737a55ef
...
...
@@ -17,35 +17,48 @@ void main() {
new
ProtocolDiscovery
(
logReader
,
ProtocolDiscovery
.
kObservatoryService
);
// Get next port future.
Future
<
int
>
nextPort
=
discoverer
.
nextPort
();
expect
(
next
Port
,
isNotNull
);
Future
<
Uri
>
nextUri
=
discoverer
.
nextUri
();
expect
(
next
Uri
,
isNotNull
);
// Inject some lines.
logReader
.
addLine
(
'HELLO WORLD'
);
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1:9999'
);
// Await the port.
expect
(
await
nextPort
,
9999
);
Uri
uri
=
await
nextUri
;
expect
(
uri
.
port
,
9999
);
expect
(
'
$uri
'
,
'http://127.0.0.1:9999'
);
// Get next port future.
next
Port
=
discoverer
.
nextPort
();
next
Uri
=
discoverer
.
nextUri
();
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1:3333'
);
expect
(
await
nextPort
,
3333
);
uri
=
await
nextUri
;
expect
(
uri
.
port
,
3333
);
expect
(
'
$uri
'
,
'http://127.0.0.1:3333'
);
// Get next port future.
next
Port
=
discoverer
.
nextPort
();
next
Uri
=
discoverer
.
nextUri
();
// Inject some bad lines.
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1'
);
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1:'
);
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1:apple'
);
int
port
=
await
nextPort
.
timeout
(
const
Duration
(
milliseconds:
100
),
onTimeout:
()
=>
77
);
// Expect the timeout port.
expect
(
port
,
77
);
Uri
timeoutUri
=
Uri
.
parse
(
'http://timeout'
);
Uri
actualUri
=
await
nextUri
.
timeout
(
const
Duration
(
milliseconds:
100
),
onTimeout:
()
=>
timeoutUri
);
expect
(
actualUri
,
timeoutUri
);
// Get next port future.
next
Port
=
discoverer
.
nextPort
();
next
Uri
=
discoverer
.
nextUri
();
logReader
.
addLine
(
'I/flutter : Observatory listening on http://127.0.0.1:52584'
);
expect
(
await
nextPort
,
52584
);
uri
=
await
nextUri
;
expect
(
uri
.
port
,
52584
);
expect
(
'
$uri
'
,
'http://127.0.0.1:52584'
);
// Get next port future.
nextUri
=
discoverer
.
nextUri
();
logReader
.
addLine
(
'I/flutter : Observatory listening on http://127.0.0.1:54804/PTwjm8Ii8qg=/'
);
uri
=
await
nextUri
;
expect
(
uri
.
port
,
54804
);
expect
(
'
$uri
'
,
'http://127.0.0.1:54804/PTwjm8Ii8qg=/'
);
discoverer
.
cancel
();
logReader
.
dispose
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment