Skip to content

Commit fe47b6e

Browse files
authored
UPDATE react-native-hms-nearby 5.2.1-300 (#97)
* UPDATE react-native-hms-nearby 5.2.1-300
1 parent 750210e commit fe47b6e

51 files changed

Lines changed: 775 additions & 2294 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

react-native-hms-nearby/README.md

Lines changed: 23 additions & 1809 deletions
Large diffs are not rendered by default.

react-native-hms-nearby/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ repositories {
4747
dependencies {
4848
implementation fileTree(include: ['*.jar'], dir: 'libs')
4949
implementation 'com.facebook.react:react-native:+'
50-
implementation 'com.huawei.hms:nearby:5.0.4.302'
50+
implementation 'com.huawei.hms:nearby:5.2.1.300'
5151
}
5252

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

react-native-hms-nearby/android/gradlew

Lines changed: 14 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react-native-hms-nearby/android/gradlew.bat

Lines changed: 7 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react-native-hms-nearby/android/src/main/java/com/huawei/hms/rn/nearby/HMSNearby.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
2+
Copyright 2020-2021. Huawei Technologies Co., Ltd. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License")
55
you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
import com.facebook.react.bridge.NativeModule;
2323
import com.facebook.react.bridge.ReactApplicationContext;
2424
import com.facebook.react.uimanager.ViewManager;
25-
import com.huawei.hms.rn.nearby.modules.HMSApplication;
25+
import com.huawei.hms.rn.nearby.modules.HMSNearbyApplication;
2626
import com.huawei.hms.rn.nearby.modules.HMSDiscovery;
2727
import com.huawei.hms.rn.nearby.modules.HMSMessage;
2828
import com.huawei.hms.rn.nearby.modules.HMSTransfer;
@@ -38,7 +38,7 @@ public class HMSNearby implements ReactPackage {
3838
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
3939
List<NativeModule> modules = new ArrayList<>();
4040

41-
modules.add(new HMSApplication(reactContext));
41+
modules.add(new HMSNearbyApplication(reactContext));
4242
modules.add(new HMSTransfer(reactContext));
4343
modules.add(new HMSDiscovery(reactContext));
4444
modules.add(new HMSMessage(reactContext));

react-native-hms-nearby/android/src/main/java/com/huawei/hms/rn/nearby/constants/HMSConstants.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
2+
Copyright 2020-2021. Huawei Technologies Co., Ltd. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License")
55
you may not use this file except in compliance with the License.
@@ -24,16 +24,20 @@
2424
import com.huawei.hms.nearby.transfer.Data;
2525
import com.huawei.hms.nearby.transfer.TransferEngine;
2626
import com.huawei.hms.nearby.transfer.TransferStateUpdate;
27+
import com.huawei.hms.rn.nearby.modules.HMSNearbyApplication;
2728

2829
import java.util.HashMap;
2930
import java.util.Map;
3031

32+
import static com.huawei.hms.rn.nearby.utils.HMSResult.ANDROID_HMS_RESTRICTED;
3133
import static com.huawei.hms.rn.nearby.utils.HMSResult.BYTES_DATA_FAIL;
3234
import static com.huawei.hms.rn.nearby.utils.HMSResult.ENDPOINT_ID_FAIL;
3335
import static com.huawei.hms.rn.nearby.utils.HMSResult.FAILURE;
3436
import static com.huawei.hms.rn.nearby.utils.HMSResult.POLICY_FAIL;
3537
import static com.huawei.hms.rn.nearby.utils.HMSResult.STRING_PARAM_FAIL;
3638
import static com.huawei.hms.rn.nearby.utils.HMSResult.SUCCESS;
39+
import static com.huawei.hms.rn.nearby.utils.HMSResult.WIFI_MUST_BE_ENABLED;
40+
import static com.huawei.hms.rn.nearby.utils.HMSResult.WIFI_NOT_SUPPORT_SHARE;
3741

3842
public final class HMSConstants {
3943
/**
@@ -44,6 +48,9 @@ public final class HMSConstants {
4448
public static final int POLICY_STAR = 3;
4549
public static final int POLICY_SHARE = 1;
4650
public static final int POLICY_SET = 2;
51+
public static final int CHANNEL_AUTO = 1;
52+
public static final int CHANNEL_HIGH_THROUGHPUT = 2;
53+
public static final int CHANNEL_INSTANCE = 3;
4754

4855
/**
4956
* Discovery events
@@ -101,6 +108,9 @@ public final class HMSConstants {
101108
put("SCAN_ON_LOST", SCAN_ON_LOST);
102109
put("DATA_ON_RECEIVED", DATA_ON_RECEIVED);
103110
put("DATA_ON_TRANSFER_UPDATE", DATA_ON_TRANSFER_UPDATE);
111+
put("CHANNEL_AUTO", CHANNEL_AUTO);
112+
put("CHANNEL_HIGH_THROUGHPUT", CHANNEL_HIGH_THROUGHPUT);
113+
put("CHANNEL_INSTANCE", CHANNEL_INSTANCE);
104114
}
105115
});
106116

@@ -165,7 +175,7 @@ public final class HMSConstants {
165175
});
166176

167177
/**
168-
* {@link com.huawei.hms.rn.nearby.modules.HMSApplication} module constant values exposed to RN side.
178+
* {@link HMSNearbyApplication} module constant values exposed to RN side.
169179
*/
170180
public static final Map<String, Object> APPLICATION_CONSTANTS = ImmutableMap.copyOf(new HashMap<String, Object>() {
171181
{
@@ -175,6 +185,9 @@ public final class HMSConstants {
175185
put("STRING_PARAM_FAIL", STRING_PARAM_FAIL.getStatusCode());
176186
put("ENDPOINT_ID_FAIL", ENDPOINT_ID_FAIL.getStatusCode());
177187
put("BYTES_DATA_FAIL", BYTES_DATA_FAIL.getStatusCode());
188+
put("WIFI_NOT_SUPPORT_SHARE", WIFI_NOT_SUPPORT_SHARE.getStatusCode());
189+
put("WIFI_MUST_BE_ENABLED", WIFI_MUST_BE_ENABLED.getStatusCode());
190+
put("ANDROID_HMS_RESTRICTED", ANDROID_HMS_RESTRICTED.getStatusCode());
178191
}
179192
});
180193

react-native-hms-nearby/android/src/main/java/com/huawei/hms/rn/nearby/modules/HMSBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
2+
Copyright 2020-2021. Huawei Technologies Co., Ltd. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License")
55
you may not use this file except in compliance with the License.

react-native-hms-nearby/android/src/main/java/com/huawei/hms/rn/nearby/modules/HMSDiscovery.java

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
2+
Copyright 2020-2021. Huawei Technologies Co., Ltd. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License")
55
you may not use this file except in compliance with the License.
@@ -22,11 +22,13 @@
2222
import com.facebook.react.bridge.Promise;
2323
import com.facebook.react.bridge.ReactApplicationContext;
2424
import com.facebook.react.bridge.ReactMethod;
25+
import com.facebook.react.bridge.ReadableMap;
2526
import com.facebook.react.bridge.WritableMap;
2627
import com.huawei.hms.nearby.Nearby;
2728
import com.huawei.hms.nearby.discovery.BroadcastOption;
2829
import com.huawei.hms.nearby.discovery.ConnectCallback;
2930
import com.huawei.hms.nearby.discovery.ConnectInfo;
31+
import com.huawei.hms.nearby.discovery.ConnectOption;
3032
import com.huawei.hms.nearby.discovery.ConnectResult;
3133
import com.huawei.hms.nearby.discovery.Policy;
3234
import com.huawei.hms.nearby.discovery.ScanEndpointCallback;
@@ -83,7 +85,7 @@ public void acceptConnect(String endpointId, final Promise promise) {
8385
}
8486

8587
handleResult("acceptConnect",
86-
Nearby.getDiscoveryEngine(getCurrentActivity()).acceptConnect(endpointId, getDataCallback()),
88+
Nearby.getDiscoveryEngine(getContext()).acceptConnect(endpointId, getDataCallback()),
8789
promise);
8890
}
8991

@@ -102,7 +104,7 @@ public void disconnect(String endpointId, final Promise promise) {
102104
return;
103105
}
104106

105-
Nearby.getDiscoveryEngine(getCurrentActivity()).disconnect(endpointId);
107+
Nearby.getDiscoveryEngine(getContext()).disconnect(endpointId);
106108
handleResult("disconnect", SUCCESS, promise);
107109
}
108110

@@ -122,7 +124,7 @@ public void rejectConnect(String endpointId, final Promise promise) {
122124
}
123125

124126
handleResult("rejectConnect",
125-
Nearby.getDiscoveryEngine(getCurrentActivity()).rejectConnect(endpointId),
127+
Nearby.getDiscoveryEngine(getContext()).rejectConnect(endpointId),
126128
promise);
127129
}
128130

@@ -143,8 +145,34 @@ public void requestConnect(String name, String endpointId, final Promise promise
143145
return;
144146
}
145147

146-
handleResult("rejectConnect",
147-
Nearby.getDiscoveryEngine(getCurrentActivity()).requestConnect(name, endpointId, getConnectCallback()),
148+
handleResult("requestConnect",
149+
Nearby.getDiscoveryEngine(getContext()).requestConnect(name, endpointId, getConnectCallback()),
150+
promise);
151+
}
152+
153+
/**
154+
* Sends a connection request carrying specific connection options to the remote endpoint.
155+
* This is an extended method for requestConnect(String, String, ConnectCallback).
156+
* Sets {@link #getConnectCallback()} : A callback listener class called during connection.
157+
* Promise Resolve : Result Object
158+
*
159+
* @param name Local endpoint name.
160+
* @param endpointId ID of the remote endpoint.
161+
* @param connectOptionMap Options Map.
162+
*/
163+
@ReactMethod
164+
public void requestConnectEx(String name, String endpointId, ReadableMap connectOptionMap, final Promise promise) {
165+
startMethodExecTimer("requestConnectEx");
166+
167+
if (TextUtils.isEmpty(name) || TextUtils.isEmpty(endpointId)) {
168+
handleResult("requestConnectEx", STRING_PARAM_FAIL, promise);
169+
return;
170+
}
171+
172+
ConnectOption connectOption = HMSUtils.getInstance().getConnectOptionFromReadableMap(connectOptionMap);
173+
174+
handleResult("requestConnectEx",
175+
Nearby.getDiscoveryEngine(getContext()).requestConnectEx(name, endpointId, getConnectCallback(), connectOption),
148176
promise);
149177
}
150178

@@ -173,7 +201,7 @@ public void startBroadcasting(String name, String serviceId, int policy, final P
173201
}
174202

175203
handleResult("startBroadCasting",
176-
Nearby.getDiscoveryEngine(getCurrentActivity()).startBroadcasting(name,
204+
Nearby.getDiscoveryEngine(getContext()).startBroadcasting(name,
177205
serviceId,
178206
getConnectCallback(),
179207
new BroadcastOption.Builder().setPolicy(broadcastPolicy).build()),
@@ -205,7 +233,7 @@ public void startScan(String serviceId, int policy, final Promise promise) {
205233
}
206234

207235
handleResult("startScan",
208-
Nearby.getDiscoveryEngine(getCurrentActivity()).startScan(serviceId,
236+
Nearby.getDiscoveryEngine(getContext()).startScan(serviceId,
209237
getScanEndpointCallback(),
210238
new ScanOption.Builder().setPolicy(scanPolicy).build()),
211239
promise);
@@ -218,7 +246,7 @@ public void startScan(String serviceId, int policy, final Promise promise) {
218246
@ReactMethod
219247
public void stopBroadCasting(final Promise promise) {
220248
startMethodExecTimer("stopBroadCasting");
221-
Nearby.getDiscoveryEngine(getCurrentActivity()).stopBroadcasting();
249+
Nearby.getDiscoveryEngine(getContext()).stopBroadcasting();
222250
handleResult("stopBroadCasting", SUCCESS, promise);
223251
}
224252

@@ -229,7 +257,7 @@ public void stopBroadCasting(final Promise promise) {
229257
@ReactMethod
230258
public void disconnectAll(final Promise promise) {
231259
startMethodExecTimer("disconnectAll");
232-
Nearby.getDiscoveryEngine(getCurrentActivity()).disconnectAll();
260+
Nearby.getDiscoveryEngine(getContext()).disconnectAll();
233261
handleResult("disconnectAll", SUCCESS, promise);
234262
}
235263

@@ -240,7 +268,7 @@ public void disconnectAll(final Promise promise) {
240268
@ReactMethod
241269
public void stopScan(final Promise promise) {
242270
startMethodExecTimer("stopScan");
243-
Nearby.getDiscoveryEngine(getCurrentActivity()).stopScan();
271+
Nearby.getDiscoveryEngine(getContext()).stopScan();
244272
handleResult("stopScan", SUCCESS, promise);
245273
}
246274

@@ -260,7 +288,10 @@ public void onReceived(String endpointId, Data data) {
260288

261289
if (data.getType() == Data.Type.FILE) {
262290
wm.putString("size", Long.toString(data.asFile().getSize()));
263-
wm.putString("fileUri", data.asFile().asJavaFile().toURI().toString());
291+
String fileUri = HMSUtils.getInstance().getFileUri(data.asFile());
292+
if(fileUri != null){
293+
wm.putString("fileUri", fileUri);
294+
}
264295
} else if (data.getType() == Data.Type.BYTES) {
265296
wm.putArray("data", HMSUtils.getInstance().convertByteArrayToWritableArray(data.asBytes()));
266297
} else if (data.getType() == Data.Type.STREAM) {
@@ -311,6 +342,7 @@ public void onResult(String endpointId, ConnectResult connectResult) {
311342
onResult.putString("endpointId", endpointId);
312343
onResult.putInt("statusCode", connectResult.getStatus().getStatusCode());
313344
onResult.putString("statusMessage", connectResult.getStatus().getStatusMessage());
345+
onResult.putString("channelPolicy", connectResult.getChannelPolicy().toString());
314346
sendEvent(CONNECT_ON_RESULT, CONNECT_CALLBACK, onResult);
315347
}
316348

0 commit comments

Comments
 (0)