add observatoryUrl property to FlutterEngine (flutter/engine#8987)
This commit is contained in:
@@ -228,6 +228,15 @@ FLUTTER_EXPORT
|
||||
*/
|
||||
@property(nonatomic, readonly) FlutterBasicMessageChannel* settingsChannel;
|
||||
|
||||
/**
|
||||
* The `NSURL` of the observatory for the service isolate.
|
||||
*
|
||||
* This is only set in debug and profile runtime modes, and only after the
|
||||
* observatory service is ready. In release mode or before the observatory has
|
||||
* started, it returns `nil`.
|
||||
*/
|
||||
@property(nonatomic, readonly) NSURL* observatoryUrl;
|
||||
|
||||
@end
|
||||
|
||||
#endif // FLUTTER_FLUTTERENGINE_H_
|
||||
|
||||
@@ -207,6 +207,10 @@
|
||||
return _settingsChannel.get();
|
||||
}
|
||||
|
||||
- (NSURL*)observatoryUrl {
|
||||
return [_publisher.get() url];
|
||||
}
|
||||
|
||||
- (void)resetChannels {
|
||||
_localizationChannel.reset();
|
||||
_navigationChannel.reset();
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
@interface FlutterObservatoryPublisher : NSObject
|
||||
|
||||
@property(nonatomic, readonly) NSURL* url;
|
||||
|
||||
@end
|
||||
|
||||
#endif // FLUTTER_FLUTTEROBSERVATORYPUBLISHER_H_
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
@end
|
||||
|
||||
@implementation FlutterObservatoryPublisher {
|
||||
fml::scoped_nsobject<NSURL> _url;
|
||||
#if TARGET_IPHONE_SIMULATOR
|
||||
DNSServiceRef _dnsServiceRef;
|
||||
#else // TARGET_IPHONE_SIMULATOR
|
||||
@@ -46,6 +47,10 @@
|
||||
std::unique_ptr<fml::WeakPtrFactory<FlutterObservatoryPublisher>> _weakFactory;
|
||||
}
|
||||
|
||||
- (NSURL*)url {
|
||||
return _url.get();
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
NSAssert(self, @"Super must not return null on init.");
|
||||
@@ -92,15 +97,14 @@
|
||||
}
|
||||
// uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port
|
||||
// number.
|
||||
NSURL* url =
|
||||
[[[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]] autorelease];
|
||||
_url.reset([[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]]);
|
||||
|
||||
NSString* serviceName =
|
||||
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
|
||||
|
||||
// Check to see if there's an authentication code. If there is, we'll provide
|
||||
// it as a txt record so flutter tools can establish a connection.
|
||||
auto path = std::string{[[url path] UTF8String]};
|
||||
auto path = std::string{[[_url path] UTF8String]};
|
||||
if (!path.empty()) {
|
||||
// Remove leading "/"
|
||||
path = path.substr(1);
|
||||
@@ -116,7 +120,7 @@
|
||||
uint32_t interfaceIndex = if_nametoindex("lo0");
|
||||
const char* registrationType = "_dartobservatory._tcp";
|
||||
const char* domain = "local."; // default domain
|
||||
uint16_t port = [[url port] intValue];
|
||||
uint16_t port = [[_url port] intValue];
|
||||
|
||||
int err = DNSServiceRegister(&_dnsServiceRef, flags, interfaceIndex, [serviceName UTF8String],
|
||||
registrationType, domain, NULL, htons(port), txtData.length,
|
||||
@@ -131,7 +135,7 @@
|
||||
NSNetService* netServiceTmp = [[NSNetService alloc] initWithDomain:@"local."
|
||||
type:@"_dartobservatory._tcp."
|
||||
name:serviceName
|
||||
port:[[url port] intValue]];
|
||||
port:[[_url port] intValue]];
|
||||
[netServiceTmp setTXTRecordData:txtData];
|
||||
_netService.reset(netServiceTmp);
|
||||
[_netService.get() setDelegate:self];
|
||||
|
||||
Reference in New Issue
Block a user