Merge branch '0.227' into universalBuild
This commit is contained in:
@@ -35,6 +35,10 @@
|
||||
[self sendInternal:method withParams:params];
|
||||
}
|
||||
|
||||
- (void)send:(NSString*)method withRawParams:(NSString*)params {
|
||||
conn_->sendRaw([method UTF8String], [params UTF8String]);
|
||||
}
|
||||
|
||||
- (void)send:(NSString*)method withArrayParams:(NSArray*)params {
|
||||
[self sendInternal:method withParams:params];
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#import "FlipperStateUpdateListener.h"
|
||||
|
||||
/**
|
||||
Represents a connection between the Sonar desktop och client side. Manages the
|
||||
Represents a connection between the Flipper desktop client side. Manages the
|
||||
lifecycle of attached plugin instances.
|
||||
*/
|
||||
@interface FlipperClient : NSObject
|
||||
@@ -41,41 +41,48 @@ this client.
|
||||
- (NSObject<FlipperPlugin>*)pluginWithIdentifier:(NSString*)identifier;
|
||||
|
||||
/**
|
||||
Establish a connection to the Sonar desktop.
|
||||
Establish a connection to the Flipper desktop.
|
||||
*/
|
||||
- (void)start;
|
||||
|
||||
/**
|
||||
Stop the connection to the Sonar desktop.
|
||||
Stop the connection to the Flipper desktop.
|
||||
*/
|
||||
- (void)stop;
|
||||
|
||||
/**
|
||||
Get the log of state changes from the sonar client
|
||||
Get the log of state changes from the Flipper client.
|
||||
*/
|
||||
- (NSString*)getState;
|
||||
|
||||
/**
|
||||
Get the current summarized state of the sonar client
|
||||
Get the current summarized state of the Flipper client.
|
||||
*/
|
||||
- (NSArray<NSDictionary*>*)getStateElements;
|
||||
|
||||
/**
|
||||
Subscribe a ViewController to state update change notifications
|
||||
Return true if the app is connected to Flipper desktop. Otherwise, returns
|
||||
false.
|
||||
|
||||
*/
|
||||
- (BOOL)isConnected;
|
||||
|
||||
/**
|
||||
Subscribe a ViewController to state update change notifications.
|
||||
*/
|
||||
- (void)subscribeForUpdates:(id<FlipperStateUpdateListener>)controller;
|
||||
|
||||
/**
|
||||
Sets the certificate provider responsible for obtaining certificates
|
||||
Sets the certificate provider responsible for obtaining certificates.
|
||||
*/
|
||||
- (void)setCertificateProvider:(id<FlipperKitCertificateProvider>)provider;
|
||||
|
||||
/**
|
||||
Get the certificate provider of Flipper Client
|
||||
Get the certificate provider of Flipper Client.
|
||||
*/
|
||||
- (id<FlipperKitCertificateProvider>)getCertificateProvider;
|
||||
|
||||
// initializers are disabled. You must use `+[FlipperClient sharedClient]`
|
||||
// Initializers are disabled. You must use `+[FlipperClient sharedClient]`
|
||||
// instance.
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
@@ -182,6 +182,10 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (BOOL)isConnected {
|
||||
return _cppClient->isConnected();
|
||||
}
|
||||
|
||||
- (NSString*)getState {
|
||||
return @(_cppClient->getState().c_str());
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ Invoke a method on the Sonar desktop plugin with with a matching identifier.
|
||||
*/
|
||||
- (void)send:(NSString*)method withParams:(NSDictionary*)params;
|
||||
|
||||
/**
|
||||
Invoke a method on the Sonar desktop plugin with with a matching identifier.
|
||||
*/
|
||||
- (void)send:(NSString*)method withRawParams:(NSString*)params;
|
||||
|
||||
/**
|
||||
Invoke a method on the Sonar desktop plugin with with a matching identifier.
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,7 @@ static NSString* const kSKCellIdentifier =
|
||||
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10];
|
||||
cell.textLabel.text = [self.elements[row][@"state"]
|
||||
stringByAppendingString:self.elements[row][@"name"]];
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
@@ -52,12 +53,19 @@ static NSString* const kSKCellIdentifier =
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
self.stateTable = [[UITableView alloc]
|
||||
initWithFrame:CGRectMake(
|
||||
0, 0, self.view.bounds.size.width, STATE_VIEW_HEIGHT)];
|
||||
|
||||
self.scrollView = [[UIScrollView alloc]
|
||||
initWithFrame:CGRectMake(
|
||||
0,
|
||||
STATE_VIEW_HEIGHT,
|
||||
self.view.frame.size.width,
|
||||
self.view.frame.size.height - 100 - STATE_VIEW_HEIGHT)];
|
||||
|
||||
self.logLabel =
|
||||
[[UILabel alloc] initWithFrame:CGRectMake(
|
||||
0,
|
||||
@@ -66,11 +74,9 @@ static NSString* const kSKCellIdentifier =
|
||||
self.scrollView.frame.size.height)];
|
||||
self.logLabel.numberOfLines = 0;
|
||||
self.logLabel.font = [UIFont systemFontOfSize:10.0f];
|
||||
|
||||
[self.scrollView addSubview:self.logLabel];
|
||||
|
||||
self.stateTable = [[UITableView alloc]
|
||||
initWithFrame:CGRectMake(
|
||||
0, 0, self.view.bounds.size.width, STATE_VIEW_HEIGHT)];
|
||||
[self.stateTable registerClass:[UITableViewCell class]
|
||||
forCellReuseIdentifier:kSKCellIdentifier];
|
||||
self.stateTable.rowHeight = 14;
|
||||
@@ -104,10 +110,11 @@ static NSString* const kSKCellIdentifier =
|
||||
[self.logLabel sizeToFit];
|
||||
self.scrollView.contentSize = self.logLabel.frame.size;
|
||||
|
||||
// Scroll to bottom
|
||||
CGPoint bottomOffset = CGPointMake(
|
||||
0,
|
||||
self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
|
||||
CGFloat y = 0;
|
||||
if (self.scrollView.contentSize.height > self.scrollView.bounds.size.height) {
|
||||
y = self.scrollView.contentSize.height - self.scrollView.bounds.size.height;
|
||||
}
|
||||
CGPoint bottomOffset = CGPointMake(0, y);
|
||||
[self.scrollView setContentOffset:bottomOffset animated:YES];
|
||||
}
|
||||
|
||||
|
||||
@@ -166,25 +166,26 @@ static constexpr int connectionKeepaliveSeconds = 10;
|
||||
}
|
||||
|
||||
- (void)disconnect {
|
||||
[_dispatchQueue cancelAllOperations];
|
||||
|
||||
if ([_keepAlive isValid]) {
|
||||
[_keepAlive invalidate];
|
||||
}
|
||||
_keepAlive = nil;
|
||||
|
||||
// Manually trigger a 'close' event as SocketRocket close method will
|
||||
// not notify the delegate. SocketRocket only triggers the close event
|
||||
// when the connection is closed from the server.
|
||||
_eventHandler(facebook::flipper::SocketEvent::CLOSE);
|
||||
__weak auto weakSelf = self;
|
||||
NSBlockOperation* disconnectOperation =
|
||||
[NSBlockOperation blockOperationWithBlock:^{
|
||||
__strong auto strongSelf = weakSelf;
|
||||
// Clear the socket delegate before close. Ensures that we won't get
|
||||
// any messages after the disconnect takes place.
|
||||
if (strongSelf->_socket) {
|
||||
[strongSelf->_socket setDelegate:nil];
|
||||
[strongSelf->_socket close];
|
||||
|
||||
if (_socket) {
|
||||
// Clear the socket delegate before close. Ensures that we won't get
|
||||
// any messages after the disconnect takes place.
|
||||
_socket.delegate = nil;
|
||||
[_socket close];
|
||||
_socket = nil;
|
||||
};
|
||||
strongSelf->_socket = nil;
|
||||
}
|
||||
}];
|
||||
|
||||
[_dispatchQueue addOperations:@[ disconnectOperation ] waitUntilFinished:YES];
|
||||
}
|
||||
|
||||
- (void)send:(NSString*)message
|
||||
@@ -192,10 +193,12 @@ static constexpr int connectionKeepaliveSeconds = 10;
|
||||
__weak auto weakSelf = self;
|
||||
[_dispatchQueue addOperationWithBlock:^{
|
||||
__strong auto strongSelf = weakSelf;
|
||||
NSError* error = nil;
|
||||
[strongSelf->_socket sendString:message error:&error];
|
||||
if (completionHandler) {
|
||||
completionHandler(error);
|
||||
if (strongSelf) {
|
||||
NSError* error = nil;
|
||||
[strongSelf->_socket sendString:message error:&error];
|
||||
if (completionHandler) {
|
||||
completionHandler(error);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
@@ -210,7 +213,9 @@ static constexpr int connectionKeepaliveSeconds = 10;
|
||||
__weak auto weakSelf = self;
|
||||
[_dispatchQueue addOperationWithBlock:^{
|
||||
__strong auto strongSelf = weakSelf;
|
||||
[strongSelf->_socket sendPing:nil error:nil];
|
||||
if (strongSelf) {
|
||||
[strongSelf->_socket sendPing:nil error:nil];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -251,7 +256,6 @@ static constexpr int connectionKeepaliveSeconds = 10;
|
||||
_keepAlive = nil;
|
||||
|
||||
_eventHandler(facebook::flipper::SocketEvent::CLOSE);
|
||||
_socket = nil;
|
||||
}
|
||||
|
||||
- (void)_webSocketDidReceiveMessage:(id)message {
|
||||
|
||||
@@ -39,7 +39,7 @@ class FlipperWebSocket : public FlipperSocket {
|
||||
virtual void setEventHandler(SocketEventHandler eventHandler) override;
|
||||
virtual void setMessageHandler(SocketMessageHandler messageHandler) override;
|
||||
|
||||
virtual bool connect(FlipperConnectionManager* manager) override;
|
||||
virtual void connect(FlipperConnectionManager* manager) override;
|
||||
virtual void disconnect() override;
|
||||
|
||||
virtual void send(const folly::dynamic& message, SocketSendHandler completion)
|
||||
|
||||
@@ -53,9 +53,9 @@ void FlipperWebSocket::setMessageHandler(SocketMessageHandler messageHandler) {
|
||||
messageHandler_ = std::move(messageHandler);
|
||||
}
|
||||
|
||||
bool FlipperWebSocket::connect(FlipperConnectionManager* manager) {
|
||||
void FlipperWebSocket::connect(FlipperConnectionManager* manager) {
|
||||
if (socket_ != NULL) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string connectionURL = endpoint_.secure ? "wss://" : "ws://";
|
||||
@@ -72,43 +72,16 @@ bool FlipperWebSocket::connect(FlipperConnectionManager* manager) {
|
||||
connectionURL += payload;
|
||||
}
|
||||
|
||||
__block bool fullfilled = false;
|
||||
__block std::promise<bool> promise;
|
||||
auto connected = promise.get_future();
|
||||
|
||||
NSURL* urlObjc = [NSURL
|
||||
URLWithString:[NSString stringWithUTF8String:connectionURL.c_str()]];
|
||||
|
||||
auto eventHandler = eventHandler_;
|
||||
socket_ = [[FlipperPlatformWebSocket alloc] initWithURL:urlObjc];
|
||||
socket_.eventHandler = ^(SocketEvent event) {
|
||||
/**
|
||||
Only fulfill the promise the first time the event handler is used. If the
|
||||
open event is received, then set the promise value to true. For any other
|
||||
event, consider a failure and set to false.
|
||||
*/
|
||||
if (!fullfilled) {
|
||||
fullfilled = true;
|
||||
if (event == SocketEvent::OPEN) {
|
||||
promise.set_value(true);
|
||||
} else if (event == SocketEvent::SSL_ERROR) {
|
||||
try {
|
||||
promise.set_exception(
|
||||
std::make_exception_ptr(SSLException("SSL handshake failed")));
|
||||
} catch (...) {
|
||||
// set_exception() may throw an exception
|
||||
// In that case, just set the value to false.
|
||||
promise.set_value(false);
|
||||
}
|
||||
} else {
|
||||
promise.set_value(false);
|
||||
}
|
||||
}
|
||||
eventHandler(event);
|
||||
eventHandler_(event);
|
||||
};
|
||||
auto messageHandler = messageHandler_;
|
||||
|
||||
socket_.messageHandler = ^(const std::string& message) {
|
||||
messageHandler(message);
|
||||
messageHandler_(message);
|
||||
};
|
||||
|
||||
if (endpoint_.secure) {
|
||||
@@ -119,19 +92,12 @@ bool FlipperWebSocket::connect(FlipperConnectionManager* manager) {
|
||||
return std::string("");
|
||||
}
|
||||
strncpy(password, pkcs12.second.c_str(), length);
|
||||
password[length - 1] = '\0';
|
||||
return pkcs12.first;
|
||||
};
|
||||
}
|
||||
|
||||
[socket_ connect];
|
||||
|
||||
auto state = connected.wait_for(std::chrono::seconds(10));
|
||||
if (state == std::future_status::ready) {
|
||||
return connected.get();
|
||||
}
|
||||
|
||||
disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
void FlipperWebSocket::disconnect() {
|
||||
@@ -155,6 +121,14 @@ void FlipperWebSocket::send(
|
||||
if (socket_ == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure the payload size is valid before sending.
|
||||
// The maximum allowed size for a message payload is 2^53 - 1. But that is
|
||||
// for the entire message, including any additional metadata.
|
||||
if (message.length() > pow(2, 53) - 1) {
|
||||
throw std::length_error("Payload is too big to send");
|
||||
}
|
||||
|
||||
NSString* messageObjc = [NSString stringWithUTF8String:message.c_str()];
|
||||
[socket_ send:messageObjc
|
||||
withCompletionHandler:^(NSError*) {
|
||||
@@ -163,9 +137,9 @@ void FlipperWebSocket::send(
|
||||
}
|
||||
|
||||
/**
|
||||
Only ever used for insecure connections to receive the device_id from a
|
||||
signCertificate request. If the intended usage ever changes, then a better
|
||||
approach needs to be put in place.
|
||||
* Only ever used for insecure connections to receive the device_id from a
|
||||
* signCertificate request. If the intended usage ever changes, then a better
|
||||
* approach needs to be put in place.
|
||||
*/
|
||||
void FlipperWebSocket::sendExpectResponse(
|
||||
const std::string& message,
|
||||
|
||||
Reference in New Issue
Block a user