mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Updates GNCDiscoverer to allow requesting a connection with endpoint info as Data
and fixes bug where the discovered endpoint info was being sent in connection request instead of the discoverer's endpoint info PiperOrigin-RevId: 422568179
This commit is contained in:
committed by
Copybara-Service
parent
4d77e82e24
commit
04ec681865
@@ -24,7 +24,7 @@ objc_library(
|
||||
"Source/Internal/GNCCore.mm",
|
||||
"Source/Internal/GNCCoreConnection.mm",
|
||||
"Source/Internal/GNCDiscoverer.mm",
|
||||
"Source/Internal/GNCPayload.m",
|
||||
"Source/Internal/GNCPayload.mm",
|
||||
"Source/Internal/GNCPayloadListener.mm",
|
||||
"Source/Internal/GNCUtils.mm",
|
||||
"Source/Internal/platform.mm",
|
||||
|
||||
@@ -40,12 +40,13 @@ typedef GNCConnectionHandler _Nonnull (^GNCDiscovererConnectionInitializationHan
|
||||
/**
|
||||
* This handler should be called to request a connection with an advertiser.
|
||||
*
|
||||
* @param name A human readable name of this endpoint, to be displayed on the other endpoint.
|
||||
* @param endpointInfo A data for endpoint info which contains readable name of this endpoint,
|
||||
* to be displayed on other endpoints.
|
||||
* @param authorizationHandler This handler is called to establish authorization.
|
||||
* @param failureHandler This handler is called if there was an error making the connection.
|
||||
*/
|
||||
typedef void (^GNCConnectionRequester)(
|
||||
NSString *name, GNCDiscovererConnectionInitializationHandler connectionAuthorizationHandler,
|
||||
NSData *endpointInfo, GNCDiscovererConnectionInitializationHandler connectionAuthorizationHandler,
|
||||
GNCConnectionFailureHandler failureHandler);
|
||||
|
||||
/** Information about an endpoint when it's discovered. */
|
||||
|
||||
@@ -57,6 +57,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
+ (instancetype)payloadWithFileURL:(NSURL *)fileURL;
|
||||
|
||||
+ (instancetype)payloadWithFileURL:(NSURL *)fileURL identifier:(int64_t)identifier;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -138,7 +138,7 @@ class GNCInputStreamFromNSStream : public InputStream {
|
||||
completion:(GNCPayloadResultHandler)completion {
|
||||
NSProgress *progress = [NSProgress progressWithTotalUnitCount:-1];
|
||||
|
||||
PayloadId payloadId = Payload::GenerateId();
|
||||
PayloadId payloadId = payload.identifier;
|
||||
Payload corePayload(payloadId, [payload]() -> InputStream & {
|
||||
location::nearby::connections::GNCInputStreamFromNSStream *stream =
|
||||
new location::nearby::connections::GNCInputStreamFromNSStream(payload.stream);
|
||||
@@ -158,7 +158,7 @@ class GNCInputStreamFromNSStream : public InputStream {
|
||||
if (result == YES) {
|
||||
fileSize = fileSizeValue.longValue;
|
||||
}
|
||||
PayloadId payloadId = Payload::GenerateId();
|
||||
PayloadId payloadId = payload.identifier;
|
||||
// Add the pair of payloadId and fileURL to the map in the GNCCore.
|
||||
[_core insertURLToMapWithPayloadID:payloadId urlToSend:fileURL];
|
||||
Payload corePayload(payloadId, InputFile(payloadId, fileSize));
|
||||
|
||||
@@ -271,8 +271,6 @@ class GNCDiscoveryListener {
|
||||
GNCDiscovererEndpointInfo *endpointInfo = [[GNCDiscovererEndpointInfo alloc] init];
|
||||
[discoverer.endpoints setObject:endpointInfo forKey:endpointId];
|
||||
|
||||
// TODO(b/169292092): endpointInfo is an advertisement byte array. Need to implement to
|
||||
// extract the endpoint name not just force to cast string.
|
||||
NSString *name = ObjCStringFromCppString(std::string(endpoint_info));
|
||||
NSData *info = NSDataFromByteArray(endpoint_info);
|
||||
GNCCore *core = discoverer.core; // don't capture |this| or |discoverer|
|
||||
@@ -280,7 +278,7 @@ class GNCDiscoveryListener {
|
||||
GNCDiscoveredEndpointInfo *discEndpointInfo = [GNCDiscoveredEndpointInfo
|
||||
infoWithName:name
|
||||
endpointInfo:info
|
||||
requestConnection:^(NSString *name,
|
||||
requestConnection:^(NSData *info,
|
||||
GNCDiscovererConnectionInitializationHandler connInitHandler,
|
||||
GNCConnectionFailureHandler connFailureHandler) {
|
||||
endpointInfo.connInitHandler = connInitHandler;
|
||||
@@ -304,7 +302,7 @@ class GNCDiscoveryListener {
|
||||
|
||||
core->_core->RequestConnection(
|
||||
CppStringFromObjCString(endpointId),
|
||||
ConnectionRequestInfo{.endpoint_info = std::move(endpoint_info),
|
||||
ConnectionRequestInfo{.endpoint_info = ByteArrayFromNSData(info),
|
||||
.listener = std::move(listener)},
|
||||
ConnectionOptions{},
|
||||
ResultListener{.result_cb = [&connFailureHandler](Status status) {
|
||||
|
||||
+11
-5
@@ -14,12 +14,18 @@
|
||||
|
||||
#import "platform/impl/ios/Source/GNCPayload.h"
|
||||
|
||||
#include "core/payload.h"
|
||||
#include "platform/base/payload_id.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
using ::location::nearby::connections::Payload;
|
||||
using ::location::nearby::PayloadId;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
uint64_t GNCRandom64() {
|
||||
return ((uint64_t)arc4random() << 32) + arc4random();
|
||||
PayloadId GenerateId() {
|
||||
return Payload::GenerateId();
|
||||
}
|
||||
|
||||
@implementation GNCBytesPayload
|
||||
@@ -34,7 +40,7 @@ uint64_t GNCRandom64() {
|
||||
}
|
||||
|
||||
+ (instancetype)payloadWithBytes:(NSData *)bytes {
|
||||
return [[self alloc] initWithBytes:bytes identifier:GNCRandom64()];
|
||||
return [[self alloc] initWithBytes:bytes identifier:GenerateId()];
|
||||
}
|
||||
|
||||
+ (instancetype)payloadWithBytes:(NSData *)bytes identifier:(int64_t)identifier {
|
||||
@@ -55,7 +61,7 @@ uint64_t GNCRandom64() {
|
||||
}
|
||||
|
||||
+ (instancetype)payloadWithStream:(NSInputStream *)stream {
|
||||
return [[self alloc] initWithStream:stream identifier:GNCRandom64()];
|
||||
return [[self alloc] initWithStream:stream identifier:GenerateId()];
|
||||
}
|
||||
|
||||
+ (instancetype)payloadWithStream:(NSInputStream *)stream identifier:(int64_t)identifier {
|
||||
@@ -76,7 +82,7 @@ uint64_t GNCRandom64() {
|
||||
}
|
||||
|
||||
+ (instancetype)payloadWithFileURL:(NSURL *)fileURL {
|
||||
return [[self alloc] initWithFileURL:fileURL identifier:GNCRandom64()];
|
||||
return [[self alloc] initWithFileURL:fileURL identifier:GenerateId()];
|
||||
}
|
||||
|
||||
+ (instancetype)payloadWithFileURL:(NSURL *)fileURL identifier:(int64_t)identifier {
|
||||
Reference in New Issue
Block a user