Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
Merge pull request #27 from taras-omelchuk/master
Browse files Browse the repository at this point in the history
Implement ability for AppKinetics module to provide multiple app-based sevices.
  • Loading branch information
matt-falkner authored Sep 7, 2023
2 parents 8928921 + 82a89e2 commit a464543
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2022 BlackBerry Limited. All Rights Reserved.
* Copyright (c) 2023 BlackBerry Limited. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -173,6 +173,7 @@ public void readyToProvideService(final ReadableMap arguments, final Promise pro
final String serviceId = arguments.getString("serviceId");
final String version = arguments.getString("version");

serviceHelper.setService(serviceId, version);
serviceHelper.setServiceId(serviceId);
serviceHelper.setServiceVersion(version);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 BlackBerry Limited. All Rights Reserved.
* Copyright (c) 2023 BlackBerry Limited. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,10 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
* Helper class to interact with GDService and GDServiceClient.
Expand All @@ -61,6 +64,8 @@ public class RNBbdServiceHelper implements GDServiceListener, GDServiceClientLis
private static RNBbdServiceHelper instance = null;
private Promise promise = null;
private ReactApplicationContext reactContext = null;

private List<AppBasedService> providedServices = new ArrayList<AppBasedService>();
private String serviceId = null;
private String serviceVersion = null;

Expand All @@ -72,6 +77,16 @@ public static RNBbdServiceHelper getInstance() {
return instance;
}

private class AppBasedService {
String serviceId;
String serviceVersion;

AppBasedService(String service, String version) {
this.serviceId = service;
this.serviceVersion = version;
}
}

/**
* Constructs RNBbdServiceHelper.
*/
Expand Down Expand Up @@ -105,6 +120,16 @@ public void setRNContext(final ReactApplicationContext reactContext) {
RNBbdServiceSpoolHelper.getInstance().setRNContext(reactContext);
}

/**
* Sets service to proceed with.
*
* @param serviceId serviceId to proceed with.
* @param serviceVersion serviceVersion to proceed with.
*/
public void setService(final String serviceId, final String serviceVersion) {
providedServices.add(new AppBasedService(serviceId, serviceVersion));
}

/**
* Sets serviceId to proceed with.
*
Expand Down Expand Up @@ -187,34 +212,35 @@ public void onReceiveMessage(final String application,
RNBbdServiceSpoolHelper.getInstance().proceedSimpleReceive(service, version, attachments);
return;
}
if (serviceId.equals(service) && serviceVersion.equals(version)) {

final JSONObject resultObject = new JSONObject();

try {
resultObject.put(APP_KINETICS_APPLICATION_NAME_KEY, application);
resultObject.put(APP_KINETICS_SERVICE_NAME_KEY, service);
resultObject.put(APP_KINETICS_VERSION_KEY, version);
resultObject.put(APP_KINETICS_METHOD_KEY, method);

if (attachments != null) {
resultObject.put(APP_KINETICS_ATTACHMENT_KEY, attachments);
}

if (params != null) {
resultObject.put(APP_KINETICS_PARAMETERS_KEY, params);
}

if (reactContext != null) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onReceivedMessage", convertJsonToMap(resultObject));
providedServices.forEach((AppBasedService providedService) -> {
if (providedService.serviceId.equals(service) && providedService.serviceVersion.equals(version)) {
final JSONObject resultObject = new JSONObject();

try {
resultObject.put(APP_KINETICS_APPLICATION_NAME_KEY, application);
resultObject.put(APP_KINETICS_SERVICE_NAME_KEY, service);
resultObject.put(APP_KINETICS_VERSION_KEY, version);
resultObject.put(APP_KINETICS_METHOD_KEY, method);

if (attachments != null) {
resultObject.put(APP_KINETICS_ATTACHMENT_KEY, attachments);
}

if (params != null) {
resultObject.put(APP_KINETICS_PARAMETERS_KEY, params);
}

if (reactContext != null) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onReceivedMessage", convertJsonToMap(resultObject));
}
} catch (final JSONException exception) {
// Should not get here
}
} catch (final JSONException exception) {
// Should not get here
}

}
});
} catch (final NullPointerException nullPointerException) {
if (reactContext != null) {
reactContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"framework": {
"name": "ReactNative",
"bbdSdkForReactNativeVersion": "11.1.0.5",
"bbdSdkForReactNativeVersion": "11.1.1.6",
"react-native": "",
"react": "",
"system": {
Expand Down

0 comments on commit a464543

Please sign in to comment.