react-native-gleapsdk 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/reactnativegleapsdk/GleapUtil.java +66 -0
- package/android/src/main/java/com/reactnativegleapsdk/GleapsdkModule.java +450 -0
- package/android/src/main/java/com/reactnativegleapsdk/GleapsdkPackage.java +28 -0
- package/ios/Gleapsdk.h +7 -0
- package/ios/Gleapsdk.m +229 -0
- package/ios/Gleapsdk.xcodeproj/project.pbxproj +282 -0
- package/lib/commonjs/index.js +96 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/networklogger.js +274 -0
- package/lib/commonjs/networklogger.js.map +1 -0
- package/lib/module/index.js +84 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/networklogger.js +266 -0
- package/lib/module/networklogger.js.map +1 -0
- package/lib/typescript/index.d.ts +28 -0
- package/lib/typescript/networklogger.d.ts +14 -0
- package/package.json +147 -0
- package/react-native-gleapsdk.podspec +20 -0
- package/src/index.tsx +115 -0
- package/src/networklogger.ts +292 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 gleap
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Gleap ReactNative SDK
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
The Gleap SDK for ReactNative is the easiest way to integrate Gleap into your apps!
|
|
6
|
+
|
|
7
|
+
You have two ways to set up the Gleap SDK for ReactNative. The easiest way ist to use the maven repository to add Gleap SDK to your project. (it's super easy to get started & worth using 😍)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install react-native-gleapsdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// Import the SDK
|
|
19
|
+
import Gleap from "react-native-gleapsdk";
|
|
20
|
+
|
|
21
|
+
// Initialize it
|
|
22
|
+
Gleap.initialize('ogWhNhuiZcGWrva5nlDS8l7a78OfaLlV');
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Need help?
|
|
26
|
+
|
|
27
|
+
Checkout our full [documentation](https://docs.gleap.io/react-native/getting-started) or [contact us](https://gleap.io/) - we are always here to help 👋.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
if (project == rootProject) {
|
|
3
|
+
repositories {
|
|
4
|
+
google()
|
|
5
|
+
mavenCentral()
|
|
6
|
+
jcenter()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
dependencies {
|
|
10
|
+
classpath 'com.android.tools.build:gradle:3.5.3'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
apply plugin: 'com.android.library'
|
|
16
|
+
|
|
17
|
+
def safeExtGet(prop, fallback) {
|
|
18
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
android {
|
|
22
|
+
compileSdkVersion safeExtGet('Gleapsdk_compileSdkVersion', 29)
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion safeExtGet('Gleapsdk_minSdkVersion', 16)
|
|
25
|
+
targetSdkVersion safeExtGet('Gleapsdk_targetSdkVersion', 29)
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
buildTypes {
|
|
32
|
+
release {
|
|
33
|
+
minifyEnabled false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
disable 'GradleCompatible'
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
mavenLocal()
|
|
47
|
+
maven {
|
|
48
|
+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
49
|
+
url("$rootDir/../node_modules/react-native/android")
|
|
50
|
+
}
|
|
51
|
+
google()
|
|
52
|
+
mavenCentral()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
dependencies {
|
|
56
|
+
//noinspection GradleDynamicVersion
|
|
57
|
+
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
58
|
+
// https://mvnrepository.com/artifact/io.gleap/gleap-android-sdk
|
|
59
|
+
implementation group: 'io.gleap', name: 'gleap-android-sdk', version: '6.0.52'
|
|
60
|
+
|
|
61
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package com.reactnativegleapsdk;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
5
|
+
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
6
|
+
|
|
7
|
+
import org.json.JSONArray;
|
|
8
|
+
import org.json.JSONException;
|
|
9
|
+
import org.json.JSONObject;
|
|
10
|
+
|
|
11
|
+
public class GleapUtil {
|
|
12
|
+
protected static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException {
|
|
13
|
+
JSONObject object = new JSONObject();
|
|
14
|
+
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
|
|
15
|
+
while (iterator.hasNextKey()) {
|
|
16
|
+
String key = iterator.nextKey();
|
|
17
|
+
switch (readableMap.getType(key)) {
|
|
18
|
+
case Null:
|
|
19
|
+
object.put(key, JSONObject.NULL);
|
|
20
|
+
break;
|
|
21
|
+
case Boolean:
|
|
22
|
+
object.put(key, readableMap.getBoolean(key));
|
|
23
|
+
break;
|
|
24
|
+
case Number:
|
|
25
|
+
object.put(key, readableMap.getDouble(key));
|
|
26
|
+
break;
|
|
27
|
+
case String:
|
|
28
|
+
object.put(key, readableMap.getString(key));
|
|
29
|
+
break;
|
|
30
|
+
case Map:
|
|
31
|
+
object.put(key, convertMapToJson(readableMap.getMap(key)));
|
|
32
|
+
break;
|
|
33
|
+
case Array:
|
|
34
|
+
object.put(key, convertArrayToJson(readableMap.getArray(key)));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return object;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
|
|
42
|
+
JSONArray array = new JSONArray();
|
|
43
|
+
for (int i = 0; i < readableArray.size(); i++) {
|
|
44
|
+
switch (readableArray.getType(i)) {
|
|
45
|
+
case Null:
|
|
46
|
+
break;
|
|
47
|
+
case Boolean:
|
|
48
|
+
array.put(readableArray.getBoolean(i));
|
|
49
|
+
break;
|
|
50
|
+
case Number:
|
|
51
|
+
array.put(readableArray.getDouble(i));
|
|
52
|
+
break;
|
|
53
|
+
case String:
|
|
54
|
+
array.put(readableArray.getString(i));
|
|
55
|
+
break;
|
|
56
|
+
case Map:
|
|
57
|
+
array.put(convertMapToJson(readableArray.getMap(i)));
|
|
58
|
+
break;
|
|
59
|
+
case Array:
|
|
60
|
+
array.put(convertArrayToJson(readableArray.getArray(i)));
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return array;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
package com.reactnativegleapsdk;
|
|
2
|
+
|
|
3
|
+
import static com.reactnativegleapsdk.GleapUtil.convertMapToJson;
|
|
4
|
+
|
|
5
|
+
import android.app.Activity;
|
|
6
|
+
import android.os.Build;
|
|
7
|
+
import android.os.Handler;
|
|
8
|
+
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
10
|
+
import androidx.annotation.RequiresApi;
|
|
11
|
+
|
|
12
|
+
import com.facebook.react.ReactApplication;
|
|
13
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
14
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
15
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
16
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
17
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
18
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
19
|
+
|
|
20
|
+
import org.json.JSONArray;
|
|
21
|
+
import org.json.JSONException;
|
|
22
|
+
import org.json.JSONObject;
|
|
23
|
+
|
|
24
|
+
import java.io.File;
|
|
25
|
+
import java.io.FileOutputStream;
|
|
26
|
+
import java.io.OutputStream;
|
|
27
|
+
import java.util.Base64;
|
|
28
|
+
import java.util.regex.Matcher;
|
|
29
|
+
import java.util.regex.Pattern;
|
|
30
|
+
|
|
31
|
+
import io.gleap.APPLICATIONTYPE;
|
|
32
|
+
import io.gleap.ConfigLoadedCallback;
|
|
33
|
+
import io.gleap.CustomActionCallback;
|
|
34
|
+
import io.gleap.FeedbackSentCallback;
|
|
35
|
+
import io.gleap.FeedbackWillBeSentCallback;
|
|
36
|
+
import io.gleap.Gleap;
|
|
37
|
+
import io.gleap.GleapUserProperties;
|
|
38
|
+
import io.gleap.RequestType;
|
|
39
|
+
|
|
40
|
+
@ReactModule(name = GleapsdkModule.NAME)
|
|
41
|
+
public class GleapsdkModule extends ReactContextBaseJavaModule {
|
|
42
|
+
public static final String NAME = "Gleapsdk";
|
|
43
|
+
private boolean isSilentBugReport = false;
|
|
44
|
+
|
|
45
|
+
public GleapsdkModule(ReactApplicationContext reactContext) {
|
|
46
|
+
super(reactContext);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Override
|
|
50
|
+
@NonNull
|
|
51
|
+
public String getName() {
|
|
52
|
+
return NAME;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Auto-configures the Gleap SDK from the remote config.
|
|
57
|
+
*
|
|
58
|
+
* @param sdkKey The SDK key, which can be found on dashboard.Gleap.io
|
|
59
|
+
*/
|
|
60
|
+
@ReactMethod
|
|
61
|
+
public void initialize(String sdkKey) {
|
|
62
|
+
try {
|
|
63
|
+
Activity activity = getReactApplicationContext()
|
|
64
|
+
.getCurrentActivity();
|
|
65
|
+
if (activity != null) {
|
|
66
|
+
Gleap.getInstance().setApplicationType(APPLICATIONTYPE.REACTNATIVE);
|
|
67
|
+
Gleap.getInstance().setFeedbackWillBeSentCallback(new FeedbackWillBeSentCallback() {
|
|
68
|
+
@Override
|
|
69
|
+
public void flowInvoced() {
|
|
70
|
+
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("feedbackWillBeSent", null);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Gleap.initialize(sdkKey, activity.getApplication());
|
|
74
|
+
Gleap.getInstance().setConfigLoadedCallback(new ConfigLoadedCallback() {
|
|
75
|
+
@Override
|
|
76
|
+
public void configLoaded(JSONObject jsonObject) {
|
|
77
|
+
System.out.println(jsonObject);
|
|
78
|
+
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("configLoaded", jsonObject.toString());
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
Gleap.getInstance().registerCustomAction(new CustomActionCallback() {
|
|
83
|
+
@Override
|
|
84
|
+
public void invoke(String message) {
|
|
85
|
+
JSONObject obj = new JSONObject();
|
|
86
|
+
try {
|
|
87
|
+
obj.put("name", message);
|
|
88
|
+
} catch (JSONException e) {
|
|
89
|
+
e.printStackTrace();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("customActionTriggered", obj.toString());
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
Gleap.getInstance().setFeedbackSentCallback(new FeedbackSentCallback() {
|
|
96
|
+
@Override
|
|
97
|
+
public void close() {
|
|
98
|
+
new java.util.Timer().schedule(
|
|
99
|
+
new java.util.TimerTask() {
|
|
100
|
+
@Override
|
|
101
|
+
public void run() {
|
|
102
|
+
showDevMenu();
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
500
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
} catch (Exception ex) {
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Start bug report manually by calling this function.
|
|
116
|
+
*/
|
|
117
|
+
@ReactMethod
|
|
118
|
+
public void startFeedbackFlow() {
|
|
119
|
+
try {
|
|
120
|
+
Gleap.getInstance().startFeedbackFlow();
|
|
121
|
+
Gleap.getInstance().setFeedbackSentCallback(new FeedbackSentCallback() {
|
|
122
|
+
@Override
|
|
123
|
+
public void close() {
|
|
124
|
+
new java.util.Timer().schedule(
|
|
125
|
+
new java.util.TimerTask() {
|
|
126
|
+
@Override
|
|
127
|
+
public void run() {
|
|
128
|
+
if (!isSilentBugReport) {
|
|
129
|
+
showDevMenu();
|
|
130
|
+
} else {
|
|
131
|
+
isSilentBugReport = false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
500
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
} catch (Exception e) {
|
|
140
|
+
System.out.println(e);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Manually start a silent bug reporting workflow.
|
|
146
|
+
*/
|
|
147
|
+
@ReactMethod
|
|
148
|
+
public void sendSilentBugReport(
|
|
149
|
+
String description,
|
|
150
|
+
String priority
|
|
151
|
+
) {
|
|
152
|
+
isSilentBugReport = true;
|
|
153
|
+
Gleap.SEVERITY severity = Gleap.SEVERITY.LOW;
|
|
154
|
+
if (priority == "MEDIUM") {
|
|
155
|
+
severity = Gleap.SEVERITY.MEDIUM;
|
|
156
|
+
}
|
|
157
|
+
if (priority == "HIGH") {
|
|
158
|
+
severity = Gleap.SEVERITY.HIGH;
|
|
159
|
+
}
|
|
160
|
+
Gleap.getInstance().sendSilentBugReport(description, severity);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@ReactMethod
|
|
164
|
+
public void setLanguage(String language) {
|
|
165
|
+
Gleap.getInstance().setLanguage(language);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@ReactMethod
|
|
169
|
+
public void identify(String userid, ReadableMap data) {
|
|
170
|
+
JSONObject jsonObject = null;
|
|
171
|
+
String name = "";
|
|
172
|
+
String email ="";
|
|
173
|
+
try {
|
|
174
|
+
jsonObject = convertMapToJson(data);
|
|
175
|
+
if(jsonObject.has("name")) {
|
|
176
|
+
name = jsonObject.getString("name");
|
|
177
|
+
}
|
|
178
|
+
if(jsonObject.has("email")) {
|
|
179
|
+
email = jsonObject.getString("email");
|
|
180
|
+
}
|
|
181
|
+
} catch (JSONException e) {
|
|
182
|
+
e.printStackTrace();
|
|
183
|
+
}
|
|
184
|
+
GleapUserProperties gleapUserSession = new GleapUserProperties(name, email);
|
|
185
|
+
Gleap.getInstance().identifyUser(userid, gleapUserSession);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@ReactMethod
|
|
189
|
+
public void clearIdentity() {
|
|
190
|
+
Gleap.getInstance().clearIdentity();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Attaches custom data, which can be viewed in the BugBattle dashboard. New data will be merged with existing custom data.
|
|
195
|
+
*
|
|
196
|
+
* @param customData The data to attach to a bug report.
|
|
197
|
+
* @author BugBattle
|
|
198
|
+
*/
|
|
199
|
+
@ReactMethod
|
|
200
|
+
public void attachCustomData(ReadableMap customData) {
|
|
201
|
+
try {
|
|
202
|
+
JSONObject jsonObject = convertMapToJson(customData);
|
|
203
|
+
Gleap.getInstance().appendCustomData(jsonObject);
|
|
204
|
+
} catch (Exception e) {
|
|
205
|
+
System.out.println(e);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Used for dedicated server. Set the url, where bugs are reported to.
|
|
212
|
+
*
|
|
213
|
+
* @param apiUrl Url to the dedicated server.
|
|
214
|
+
*/
|
|
215
|
+
@ReactMethod
|
|
216
|
+
public void setApiUrl(String apiUrl) {
|
|
217
|
+
try {
|
|
218
|
+
Gleap.getInstance().setApiUrl(apiUrl);
|
|
219
|
+
} catch (Exception e) {
|
|
220
|
+
System.out.println(e);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Used for dedicated server. Set the url, where the widget is loaded from.
|
|
226
|
+
*
|
|
227
|
+
* @param widgetUrl Url to the dedicated server.
|
|
228
|
+
*/
|
|
229
|
+
@ReactMethod
|
|
230
|
+
public void setWidgetUrl(String widgetUrl) {
|
|
231
|
+
try {
|
|
232
|
+
Gleap.getInstance().setApiUrl(widgetUrl);
|
|
233
|
+
} catch (Exception e) {
|
|
234
|
+
System.out.println(e);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Attaches custom data, which can be viewed in the Gleap dashboard. New data will be merged with existing custom data.
|
|
240
|
+
*
|
|
241
|
+
* @param customData The data to attach to a bug report.
|
|
242
|
+
* @author Gleap
|
|
243
|
+
*/
|
|
244
|
+
@ReactMethod
|
|
245
|
+
public void appendCustomData(ReadableMap customData) {
|
|
246
|
+
try {
|
|
247
|
+
JSONObject jsonObject = convertMapToJson(customData);
|
|
248
|
+
Gleap.getInstance().appendCustomData(jsonObject);
|
|
249
|
+
} catch (Exception e) {
|
|
250
|
+
System.out.println(e);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Attach one key value pair to existing custom data.
|
|
256
|
+
*
|
|
257
|
+
* @param value The value you want to add
|
|
258
|
+
* @param key The key of the attribute
|
|
259
|
+
* @author Gleap
|
|
260
|
+
*/
|
|
261
|
+
@ReactMethod
|
|
262
|
+
public void setCustomData(String key, String value) {
|
|
263
|
+
Gleap.getInstance().setCustomData(key, value);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Removes one key from existing custom data.
|
|
269
|
+
*
|
|
270
|
+
* @param key The key of the attribute
|
|
271
|
+
* @author Gleap
|
|
272
|
+
*/
|
|
273
|
+
@ReactMethod
|
|
274
|
+
public void removeCustomDataForKey(String key) {
|
|
275
|
+
Gleap.getInstance().removeCustomDataForKey(key);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Clears all custom data.
|
|
280
|
+
*/
|
|
281
|
+
@ReactMethod
|
|
282
|
+
public void clearCustomData() {
|
|
283
|
+
Gleap.getInstance().clearCustomData();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Log network traffic by logging it manually.
|
|
288
|
+
*
|
|
289
|
+
* @param networkLog Logs collected by rn
|
|
290
|
+
*/
|
|
291
|
+
@ReactMethod
|
|
292
|
+
public void attachNetworkLog(String networkLog) {
|
|
293
|
+
try {
|
|
294
|
+
JSONArray object = new JSONArray(networkLog);
|
|
295
|
+
for (int i = 0; i < object.length(); i++) {
|
|
296
|
+
JSONObject currentRequest = (JSONObject) object.get(i);
|
|
297
|
+
JSONObject response = (JSONObject) currentRequest.get("response");
|
|
298
|
+
JSONObject request = new JSONObject();
|
|
299
|
+
if (currentRequest.has("request")) {
|
|
300
|
+
request = (JSONObject) currentRequest.get("request");
|
|
301
|
+
}
|
|
302
|
+
Gleap.getInstance().logNetwork(currentRequest.getString("url"), RequestType.valueOf(currentRequest.getString("type")), response.getInt("status"), currentRequest.getInt("duration"), request, response);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
} catch (Exception ex) {
|
|
306
|
+
System.out.println(ex);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Logs a custom event
|
|
312
|
+
*
|
|
313
|
+
* @param name Name of the event
|
|
314
|
+
* @author Gleap
|
|
315
|
+
*/
|
|
316
|
+
@ReactMethod
|
|
317
|
+
void logEvent(String name) {
|
|
318
|
+
Gleap.getInstance().logEvent(name);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Logs a custom event with data
|
|
323
|
+
*
|
|
324
|
+
* @param name Name of the event
|
|
325
|
+
* @param data Data passed with the event.
|
|
326
|
+
* @author Gleap
|
|
327
|
+
*/
|
|
328
|
+
@ReactMethod
|
|
329
|
+
void logEvent(String name, ReadableMap data) {
|
|
330
|
+
JSONObject jsonObject = null;
|
|
331
|
+
try {
|
|
332
|
+
jsonObject = convertMapToJson(data);
|
|
333
|
+
Gleap.getInstance().logEvent(name, jsonObject);
|
|
334
|
+
} catch (JSONException e) {
|
|
335
|
+
e.printStackTrace();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
341
|
+
@ReactMethod
|
|
342
|
+
/**
|
|
343
|
+
* Attaches a file to the bug report
|
|
344
|
+
*
|
|
345
|
+
* @param file The file to attach to the bug report
|
|
346
|
+
* @author Gleap
|
|
347
|
+
*/
|
|
348
|
+
void addAttachment(String base64file, String fileName) {
|
|
349
|
+
try {
|
|
350
|
+
if (checkAllowedEndings(fileName)) {
|
|
351
|
+
String[] splittedBase64File = base64file.split(",");
|
|
352
|
+
byte[] data;
|
|
353
|
+
if (splittedBase64File.length == 2) {
|
|
354
|
+
data = Base64.getDecoder().decode(splittedBase64File[1]);
|
|
355
|
+
} else {
|
|
356
|
+
data = Base64.getDecoder().decode(splittedBase64File[0]);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
String mimetype = extractMimeType(base64file);
|
|
360
|
+
String[] splitted = mimetype.split("/");
|
|
361
|
+
String fileNameConcated = fileName;
|
|
362
|
+
if (splitted.length == 2 && !fileName.contains(".")) {
|
|
363
|
+
fileNameConcated += "." + splitted[1];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
File file = new File(getReactApplicationContext().getCacheDir() + "/" + fileNameConcated);
|
|
367
|
+
if (!file.exists()) {
|
|
368
|
+
file.createNewFile();
|
|
369
|
+
}
|
|
370
|
+
try (OutputStream stream = new FileOutputStream(file)) {
|
|
371
|
+
stream.write(data);
|
|
372
|
+
} catch (Exception e) {
|
|
373
|
+
e.printStackTrace();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (file.exists()) {
|
|
377
|
+
Gleap.getInstance().addAttachment(file);
|
|
378
|
+
} else {
|
|
379
|
+
System.err.println("Gleap: The file is not existing.");
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
} catch (Exception e) {
|
|
384
|
+
e.printStackTrace();
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Extract the MIME type from a base64 string
|
|
391
|
+
*
|
|
392
|
+
* @param encoded Base64 string
|
|
393
|
+
* @return MIME type string
|
|
394
|
+
*/
|
|
395
|
+
private String extractMimeType(final String encoded) {
|
|
396
|
+
final Pattern mime = Pattern.compile("^data:([a-zA-Z0-9]+/[a-zA-Z0-9]+).*,.*");
|
|
397
|
+
final Matcher matcher = mime.matcher(encoded);
|
|
398
|
+
if (!matcher.find())
|
|
399
|
+
return "";
|
|
400
|
+
return matcher.group(1).toLowerCase();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
@ReactMethod
|
|
404
|
+
public void registerConfigLoadedAction(ConfigLoadedCallback configLoadedCallback) {
|
|
405
|
+
Gleap.getInstance().setConfigLoadedCallback(configLoadedCallback);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
;
|
|
409
|
+
|
|
410
|
+
private boolean checkAllowedEndings(String fileName) {
|
|
411
|
+
String[] fileType = fileName.split("\\.");
|
|
412
|
+
String[] allowedTypes = {"jpeg", "svg", "png", "mp4", "webp", "xml", "plain", "xml", "json"};
|
|
413
|
+
if (fileType.length <= 1) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
boolean found = false;
|
|
417
|
+
for (String type : allowedTypes) {
|
|
418
|
+
if (type.equals(fileType[1])) {
|
|
419
|
+
found = true;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return found;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Show dev menu after shaking the phone.
|
|
428
|
+
*/
|
|
429
|
+
private void showDevMenu() {
|
|
430
|
+
final ReactApplication application = (ReactApplication) getReactApplicationContext()
|
|
431
|
+
.getCurrentActivity()
|
|
432
|
+
.getApplication();
|
|
433
|
+
Handler mainHandler = new Handler(this.getReactApplicationContext().getMainLooper());
|
|
434
|
+
Runnable myRunnable = new Runnable() {
|
|
435
|
+
@Override
|
|
436
|
+
public void run() {
|
|
437
|
+
try {
|
|
438
|
+
application
|
|
439
|
+
.getReactNativeHost()
|
|
440
|
+
.getReactInstanceManager()
|
|
441
|
+
.getDevSupportManager()
|
|
442
|
+
.showDevOptionsDialog();
|
|
443
|
+
} catch (Exception e) {
|
|
444
|
+
e.printStackTrace();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
mainHandler.post(myRunnable);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package com.reactnativegleapsdk;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.ReactPackage;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
|
|
14
|
+
public class GleapsdkPackage implements ReactPackage {
|
|
15
|
+
@NonNull
|
|
16
|
+
@Override
|
|
17
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
19
|
+
modules.add(new GleapsdkModule(reactContext));
|
|
20
|
+
return modules;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@NonNull
|
|
24
|
+
@Override
|
|
25
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
26
|
+
return Collections.emptyList();
|
|
27
|
+
}
|
|
28
|
+
}
|