react-native-mosquito-transport 0.0.48 → 0.0.49
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/CONTRIBUTING.md +37 -19
- package/MosquitoTransport.podspec +20 -0
- package/android/build.gradle +32 -42
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/java/com/mosquitotransport/MosquitoTransportModule.kt +101 -0
- package/android/src/main/java/com/mosquitotransport/MosquitoTransportPackage.kt +31 -0
- package/android/src/main/java/com/mosquitotransport/utils/FileUploader.kt +106 -0
- package/android/src/main/java/com/mosquitotransport/utils/UploadCallback.kt +7 -0
- package/ios/MosquitoTransport-Bridging-Header.h +1 -0
- package/ios/MosquitoTransport.h +6 -0
- package/ios/MosquitoTransport.mm +81 -0
- package/ios/{Mosquitodb.swift → MosquitoTransport.swift} +39 -42
- package/package.json +10 -2
- package/src/NativeMosquitoTransport.js +24 -0
- package/src/helpers/fs_manager.js +1 -1
- package/src/helpers/utils.js +2 -4
- package/src/helpers/variables.js +2 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +15 -10
- package/src/products/auth/accessor.js +118 -94
- package/src/products/auth/index.js +7 -6
- package/src/products/database/index.js +1 -0
- package/src/products/storage/index.js +9 -23
- package/.jshintignore +0 -4
- package/.jshintrc +0 -16
- package/TODO +0 -35
- package/android/gradle.properties +0 -5
- package/android/src/main/java/com/mosquitodb/MosquitodbModule.java +0 -82
- package/android/src/main/java/com/mosquitodb/MosquitodbPackage.java +0 -28
- package/android/src/main/java/com/mosquitodb/utils/FileUploader.java +0 -101
- package/android/src/main/java/com/mosquitodb/utils/UploadCallback.java +0 -7
- package/example/.bundle/config +0 -2
- package/example/.node-version +0 -1
- package/example/.watchmanconfig +0 -1
- package/example/Gemfile +0 -6
- package/example/android/app/build.gradle +0 -170
- package/example/android/app/debug.keystore +0 -0
- package/example/android/app/proguard-rules.pro +0 -10
- package/example/android/app/src/debug/AndroidManifest.xml +0 -13
- package/example/android/app/src/debug/java/com/mosquitodbexample/ReactNativeFlipper.java +0 -75
- package/example/android/app/src/main/AndroidManifest.xml +0 -25
- package/example/android/app/src/main/java/com/mosquitodbexample/MainActivity.java +0 -35
- package/example/android/app/src/main/java/com/mosquitodbexample/MainApplication.java +0 -62
- package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +0 -36
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +0 -3
- package/example/android/app/src/main/res/values/styles.xml +0 -9
- package/example/android/app/src/release/java/com/mosquitodbexample/ReactNativeFlipper.java +0 -20
- package/example/android/build.gradle +0 -21
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/example/android/gradle.properties +0 -44
- package/example/android/gradlew +0 -234
- package/example/android/gradlew.bat +0 -89
- package/example/android/settings.gradle +0 -4
- package/example/app.json +0 -4
- package/example/babel.config.js +0 -17
- package/example/index.js +0 -5
- package/example/ios/.xcode.env +0 -11
- package/example/ios/File.swift +0 -6
- package/example/ios/MosquitodbExample/AppDelegate.h +0 -6
- package/example/ios/MosquitodbExample/AppDelegate.mm +0 -36
- package/example/ios/MosquitodbExample/Images.xcassets/AppIcon.appiconset/Contents.json +0 -53
- package/example/ios/MosquitodbExample/Images.xcassets/Contents.json +0 -6
- package/example/ios/MosquitodbExample/Info.plist +0 -55
- package/example/ios/MosquitodbExample/LaunchScreen.storyboard +0 -47
- package/example/ios/MosquitodbExample/main.m +0 -10
- package/example/ios/MosquitodbExample-Bridging-Header.h +0 -3
- package/example/ios/MosquitodbExample.xcodeproj/project.pbxproj +0 -703
- package/example/ios/MosquitodbExample.xcodeproj/xcshareddata/xcschemes/MosquitodbExample.xcscheme +0 -88
- package/example/ios/MosquitodbExample.xcworkspace/contents.xcworkspacedata +0 -10
- package/example/ios/MosquitodbExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/example/ios/MosquitodbExample.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +0 -8
- package/example/ios/MosquitodbExample.xcworkspace/xcuserdata/anthony.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/example/ios/MosquitodbExample.xcworkspace/xcuserdata/anthony.xcuserdatad/WorkspaceSettings.xcsettings +0 -14
- package/example/ios/MosquitodbExampleTests/Info.plist +0 -24
- package/example/ios/MosquitodbExampleTests/MosquitodbExampleTests.m +0 -66
- package/example/ios/Podfile +0 -60
- package/example/metro.config.js +0 -40
- package/example/package.json +0 -22
- package/example/react-native.config.js +0 -10
- package/example/src/App.tsx +0 -31
- package/ios/Mosquitodb-Bridging-Header.h +0 -2
- package/ios/Mosquitodb.m +0 -22
- package/ios/Mosquitodb.xcodeproj/project.pbxproj +0 -283
- package/ios/Mosquitodb.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/react-native-mosquitodb.podspec +0 -35
|
@@ -59,10 +59,11 @@ export default class MTAuth {
|
|
|
59
59
|
onError?.(simplifyError('user_login_required', 'You must be signed-in to use this method').simpleError);
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
if (processID !== lastInitRef) return;
|
|
62
|
+
if (processID !== lastInitRef || hasCancelled) return;
|
|
63
63
|
const mtoken = Scoped.AuthJWTToken[projectUrl],
|
|
64
64
|
[reqBuilder, [privateKey]] = uglify ? await serializeE2E({ mtoken }, undefined, serverE2E_PublicKey) : [null, []];
|
|
65
65
|
|
|
66
|
+
if (processID !== lastInitRef || hasCancelled) return;
|
|
66
67
|
socket = io(`${wsPrefix}://${baseUrl}`, {
|
|
67
68
|
transports: ['websocket', 'polling', 'flashsocket'],
|
|
68
69
|
auth: {
|
|
@@ -159,7 +160,7 @@ export default class MTAuth {
|
|
|
159
160
|
|
|
160
161
|
signOut = () => doSignOut(this.builder);
|
|
161
162
|
|
|
162
|
-
forceRefreshToken = () => initTokenRefresher(this.builder, true);
|
|
163
|
+
forceRefreshToken = () => initTokenRefresher({ config: this.builder, forceRefresh: true });
|
|
163
164
|
|
|
164
165
|
emulate = async (projectUrl) => {
|
|
165
166
|
await injectEmulatedAuth(this.builder, projectUrl);
|
|
@@ -189,8 +190,8 @@ const doCustomSignin = (builder, email, password) => new Promise(async (resolve,
|
|
|
189
190
|
token: r.result.token,
|
|
190
191
|
refreshToken: r.result.refreshToken
|
|
191
192
|
});
|
|
192
|
-
await injectFreshToken(builder, r.result);
|
|
193
193
|
revokeAuthIntance(builder, thisAuthStore);
|
|
194
|
+
await injectFreshToken(builder, r.result);
|
|
194
195
|
} catch (e) {
|
|
195
196
|
reject(simplifyCaughtError(e).simpleError);
|
|
196
197
|
}
|
|
@@ -223,8 +224,8 @@ const doCustomSignup = (builder, email, password, name, metadata) => new Promise
|
|
|
223
224
|
refreshToken: r.result.refreshToken,
|
|
224
225
|
isNewUser: !!r.result.isNewUser
|
|
225
226
|
});
|
|
226
|
-
await injectFreshToken(builder, r.result);
|
|
227
227
|
revokeAuthIntance(builder, thisAuthStore);
|
|
228
|
+
await injectFreshToken(builder, r.result);
|
|
228
229
|
} catch (e) {
|
|
229
230
|
reject(simplifyCaughtError(e).simpleError);
|
|
230
231
|
}
|
|
@@ -248,7 +249,7 @@ const clearCacheForSignout = (builder, disposeEmulated) => {
|
|
|
248
249
|
|
|
249
250
|
purgeCache(projectUrl, true);
|
|
250
251
|
if (disposeEmulated) getEmulatedLinks(projectUrl).forEach(e => purgeCache(e));
|
|
251
|
-
initTokenRefresher(builder);
|
|
252
|
+
initTokenRefresher({ config: builder });
|
|
252
253
|
};
|
|
253
254
|
|
|
254
255
|
export const doSignOut = async (builder) => {
|
|
@@ -335,8 +336,8 @@ const doProviderSignin = (builder, token, metadata, endpointer) => new Promise(a
|
|
|
335
336
|
refreshToken: f.result.refreshToken,
|
|
336
337
|
isNewUser: f.result.isNewUser
|
|
337
338
|
});
|
|
338
|
-
await injectFreshToken(builder, f.result);
|
|
339
339
|
revokeAuthIntance(builder, thisAuthStore);
|
|
340
|
+
await injectFreshToken(builder, f.result);
|
|
340
341
|
} catch (e) {
|
|
341
342
|
reject(simplifyCaughtError(e).simpleError);
|
|
342
343
|
}
|
|
@@ -206,6 +206,7 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
206
206
|
|
|
207
207
|
const [encPlate, [privateKey]] = uglify ? await serializeE2E({ _body: authObj }, mtoken, serverE2E_PublicKey) : ['', []];
|
|
208
208
|
|
|
209
|
+
if (hasCancelled || processID !== lastInitRef) return;
|
|
209
210
|
socket = io(`${wsPrefix}://${baseUrl}`, {
|
|
210
211
|
transports: ['websocket', 'polling', 'flashsocket'],
|
|
211
212
|
extraHeaders,
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
import EngineApi from "../../helpers/engine_api";
|
|
2
2
|
import { deserializeE2E, prefixStoragePath } from "../../helpers/peripherals";
|
|
3
3
|
import { Scoped } from "../../helpers/variables";
|
|
4
|
-
import {
|
|
4
|
+
import { NativeEventEmitter } from 'react-native';
|
|
5
|
+
import NativeMosquitoTransport from '../../NativeMosquitoTransport';
|
|
5
6
|
import { awaitReachableServer, buildFetchInterface, buildFetchResult } from "../../helpers/utils";
|
|
6
7
|
import { awaitRefreshToken } from "../auth/accessor";
|
|
7
8
|
import { simplifyError } from "simplify-error";
|
|
8
9
|
import { Validator } from "guard-object";
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
`The package 'react-native-mosquito-transport' doesn't seem to be linked. Make sure: \n\n` +
|
|
12
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
13
|
-
'- You rebuilt the app after installing the package\n' +
|
|
14
|
-
'- You are not using Expo Go\n';
|
|
15
|
-
|
|
16
|
-
const RNMTModule = NativeModules.Mosquitodb || (
|
|
17
|
-
new Proxy({}, {
|
|
18
|
-
get() {
|
|
19
|
-
throw new Error(LINKING_ERROR);
|
|
20
|
-
},
|
|
21
|
-
})
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const emitter = Platform.OS === 'android' ?
|
|
25
|
-
DeviceEventEmitter : new NativeEventEmitter(RNMTModule);
|
|
11
|
+
const emitter = new NativeEventEmitter(NativeMosquitoTransport);
|
|
26
12
|
|
|
27
13
|
export class MTStorage {
|
|
28
14
|
constructor(config) {
|
|
@@ -48,7 +34,7 @@ export class MTStorage {
|
|
|
48
34
|
|
|
49
35
|
promise.abort = () => {
|
|
50
36
|
if (hasFinished || hasCancelled) return;
|
|
51
|
-
|
|
37
|
+
NativeMosquitoTransport.cancelDownload(processID);
|
|
52
38
|
hasCancelled = true;
|
|
53
39
|
onComplete?.({ error: 'download_aborted', message: 'The download process was aborted' });
|
|
54
40
|
}
|
|
@@ -82,12 +68,12 @@ export class MTStorage {
|
|
|
82
68
|
isPaused: !!isPaused,
|
|
83
69
|
pause: () => {
|
|
84
70
|
if (hasFinished || isPaused || hasCancelled) return;
|
|
85
|
-
|
|
71
|
+
NativeMosquitoTransport.pauseDownload(processID);
|
|
86
72
|
isPaused = true;
|
|
87
73
|
},
|
|
88
74
|
resume: () => {
|
|
89
75
|
if (hasFinished || !isPaused || hasCancelled) return;
|
|
90
|
-
|
|
76
|
+
NativeMosquitoTransport.resumeDownload(processID);
|
|
91
77
|
isPaused = false;
|
|
92
78
|
}
|
|
93
79
|
});
|
|
@@ -107,7 +93,7 @@ export class MTStorage {
|
|
|
107
93
|
progressListener.remove();
|
|
108
94
|
});
|
|
109
95
|
|
|
110
|
-
|
|
96
|
+
NativeMosquitoTransport.downloadFile({
|
|
111
97
|
url: link,
|
|
112
98
|
authToken: Scoped.AuthJWTToken[projectUrl],
|
|
113
99
|
...destination ? {
|
|
@@ -145,7 +131,7 @@ export class MTStorage {
|
|
|
145
131
|
setTimeout(() => {
|
|
146
132
|
thisComplete?.({ error: 'upload_aborted', message: 'The upload process was aborted' });
|
|
147
133
|
}, 0);
|
|
148
|
-
|
|
134
|
+
NativeMosquitoTransport.cancelUpload(processID);
|
|
149
135
|
};
|
|
150
136
|
|
|
151
137
|
if (typeof file !== 'string' || !file.trim()) {
|
|
@@ -191,7 +177,7 @@ export class MTStorage {
|
|
|
191
177
|
});
|
|
192
178
|
const authToken = Scoped.AuthJWTToken[projectUrl];
|
|
193
179
|
|
|
194
|
-
|
|
180
|
+
NativeMosquitoTransport.uploadFile({
|
|
195
181
|
url: EngineApi._uploadFile(thisProjectUrl, uglify),
|
|
196
182
|
file: isAsset ? file : file.substring('file://'.length),
|
|
197
183
|
...authToken ? { authToken } : {},
|
package/.jshintignore
DELETED
package/.jshintrc
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"undef": true, // Warns on variables used before declaration
|
|
3
|
-
"esversion": 12,
|
|
4
|
-
"globals": {
|
|
5
|
-
"process": true,
|
|
6
|
-
"clearTimeout": true,
|
|
7
|
-
"setTimeout": true,
|
|
8
|
-
"console": true,
|
|
9
|
-
"Buffer": true,
|
|
10
|
-
"clearInterval": true,
|
|
11
|
-
"setInterval": true,
|
|
12
|
-
"AbortController": true,
|
|
13
|
-
"URLSearchParams": true,
|
|
14
|
-
"URL": true
|
|
15
|
-
}
|
|
16
|
-
}
|
package/TODO
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
- fix local cache query on sqlite ✅
|
|
2
|
-
- fix and add all mongodb query and update operator ✅
|
|
3
|
-
- reauthenticate
|
|
4
|
-
- change `Object` in d.ts to [key: string]: any
|
|
5
|
-
- add `getServerTimeOffset` method
|
|
6
|
-
- change undefined to null in `value` ✅
|
|
7
|
-
- `provide functionality to add extra header to MT instance (all outgoing request)` ✅
|
|
8
|
-
- borrowToken ✅
|
|
9
|
-
- `add sqlite` ✅
|
|
10
|
-
- minimize extraction data ✅
|
|
11
|
-
- change `collection().onDisconnect()` to `collection().socket().onDisconnect()` and `collection().socket().onConnect()` ✅
|
|
12
|
-
- add `_foreign_doc` to d.ts ✅
|
|
13
|
-
- tree shake dependencies
|
|
14
|
-
- dynamic import for fs ✅
|
|
15
|
-
- new URL() work around ✅
|
|
16
|
-
- fetchHttp, default retrieval if has body ✅
|
|
17
|
-
- native hashing ✅
|
|
18
|
-
- TextEncoder
|
|
19
|
-
- native storage upload ✅
|
|
20
|
-
- lodashes ✅
|
|
21
|
-
- switch to events package
|
|
22
|
-
- serverTimeOffset
|
|
23
|
-
- avoid sending cookies ✅
|
|
24
|
-
- add timeout in fetchHttp
|
|
25
|
-
- transform undefined to void instead of null
|
|
26
|
-
- add metadata to provider auth login
|
|
27
|
-
<!-- - error: "refreshToken retry limit exceeded" <--- no need -->
|
|
28
|
-
|
|
29
|
-
- _areYouOk() should timeout max 5000
|
|
30
|
-
- .json() should be parse nicely
|
|
31
|
-
- when server is offline and suddenly comes online, fetchHttp throw some error
|
|
32
|
-
- string to Buffer may be in utf16
|
|
33
|
-
|
|
34
|
-
# changes made
|
|
35
|
-
storage uploadFile method and others
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
package com.mosquitodb;
|
|
2
|
-
|
|
3
|
-
import android.util.ArrayMap;
|
|
4
|
-
|
|
5
|
-
import androidx.annotation.NonNull;
|
|
6
|
-
import androidx.annotation.Nullable;
|
|
7
|
-
|
|
8
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
10
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
11
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
-
import com.facebook.react.bridge.WritableMap;
|
|
13
|
-
import com.facebook.react.bridge.WritableNativeMap;
|
|
14
|
-
import com.facebook.react.module.annotations.ReactModule;
|
|
15
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
16
|
-
import com.mosquitodb.utils.FileUploader;
|
|
17
|
-
import com.mosquitodb.utils.UploadCallback;
|
|
18
|
-
|
|
19
|
-
@ReactModule(name = MosquitodbModule.NAME)
|
|
20
|
-
public class MosquitodbModule extends ReactContextBaseJavaModule {
|
|
21
|
-
public static final String NAME = "Mosquitodb";
|
|
22
|
-
private final ArrayMap<String, FileUploader> uploaderMap = new ArrayMap<>();
|
|
23
|
-
|
|
24
|
-
public MosquitodbModule(ReactApplicationContext reactContext) {
|
|
25
|
-
super(reactContext);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@Override
|
|
29
|
-
@NonNull
|
|
30
|
-
public String getName() {
|
|
31
|
-
return NAME;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@ReactMethod
|
|
35
|
-
public void uploadFile(ReadableMap readable) {
|
|
36
|
-
String processId = readable.getString("processID");
|
|
37
|
-
FileUploader uploader = new FileUploader();
|
|
38
|
-
|
|
39
|
-
uploader.uploadFile(readable, new UploadCallback() {
|
|
40
|
-
@Override
|
|
41
|
-
public void onProgress(long sentBytes, long totalBytes) {
|
|
42
|
-
WritableMap progress = new WritableNativeMap();
|
|
43
|
-
progress.putInt("sentBytes", (int) sentBytes);
|
|
44
|
-
progress.putInt("totalBytes", (int) totalBytes);
|
|
45
|
-
progress.putString("processID", processId);
|
|
46
|
-
sendEvent("mt-uploading-progress", progress);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Override
|
|
50
|
-
public void onComplete(int responseCode, String responseBody) {
|
|
51
|
-
WritableMap statusData = new WritableNativeMap();
|
|
52
|
-
statusData.putString("processID", processId);
|
|
53
|
-
statusData.putString("result", responseBody);
|
|
54
|
-
sendEvent("mt-uploading-status", statusData);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@Override
|
|
58
|
-
public void onError(Exception e) {
|
|
59
|
-
WritableMap statusData = new WritableNativeMap();
|
|
60
|
-
statusData.putString("processID", processId);
|
|
61
|
-
statusData.putString("error", "internal_error");
|
|
62
|
-
statusData.putString("errorDes", e.getLocalizedMessage());
|
|
63
|
-
sendEvent("mt-uploading-status", statusData);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
uploaderMap.put(processId, uploader);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
@ReactMethod
|
|
70
|
-
public void cancelUpload(String processID) {
|
|
71
|
-
FileUploader uploader = uploaderMap.get(processID);
|
|
72
|
-
if (uploader != null) {
|
|
73
|
-
uploader.cancelUpload();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private void sendEvent(String eventName, @Nullable WritableMap params) {
|
|
78
|
-
getReactApplicationContext()
|
|
79
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
80
|
-
.emit(eventName, params);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
package com.mosquitodb;
|
|
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 MosquitodbPackage implements ReactPackage {
|
|
15
|
-
@NonNull
|
|
16
|
-
@Override
|
|
17
|
-
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
|
-
List<NativeModule> modules = new ArrayList<>();
|
|
19
|
-
modules.add(new MosquitodbModule(reactContext));
|
|
20
|
-
return modules;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@NonNull
|
|
24
|
-
@Override
|
|
25
|
-
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
26
|
-
return Collections.emptyList();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
package com.mosquitodb.utils;
|
|
2
|
-
|
|
3
|
-
import java.io.*;
|
|
4
|
-
import java.net.*;
|
|
5
|
-
import java.util.Objects;
|
|
6
|
-
|
|
7
|
-
import android.net.Uri;
|
|
8
|
-
|
|
9
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
10
|
-
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
11
|
-
|
|
12
|
-
public class FileUploader {
|
|
13
|
-
|
|
14
|
-
private volatile boolean isCancelled = false;
|
|
15
|
-
|
|
16
|
-
public void cancelUpload() {
|
|
17
|
-
isCancelled = true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public void uploadFile(ReadableMap config, UploadCallback callback) {
|
|
21
|
-
new Thread(() -> {
|
|
22
|
-
try {
|
|
23
|
-
Uri fileUri = Uri.parse(config.getString("file"));
|
|
24
|
-
File file = new File(Objects.requireNonNull(fileUri.getPath()));
|
|
25
|
-
|
|
26
|
-
if (!file.exists()) {
|
|
27
|
-
throw new FileNotFoundException("File not found: " + file.getAbsolutePath());
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
long totalBytes = file.length();
|
|
31
|
-
HttpURLConnection connection = (HttpURLConnection) new URL(config.getString("url")).openConnection();
|
|
32
|
-
connection.setDoOutput(true);
|
|
33
|
-
connection.setRequestMethod("POST");
|
|
34
|
-
|
|
35
|
-
ReadableMap extraHeaders = config.getMap("extraHeaders");
|
|
36
|
-
ReadableMapKeySetIterator iterator = Objects.requireNonNull(extraHeaders).keySetIterator();
|
|
37
|
-
while (iterator.hasNextKey()) {
|
|
38
|
-
String key = iterator.nextKey();
|
|
39
|
-
connection.setRequestProperty(key, extraHeaders.getString(key));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
connection.setRequestProperty("Content-Type", "buffer/upload");
|
|
43
|
-
connection.setRequestProperty("hash-upload", config.getString("createHash"));
|
|
44
|
-
connection.setRequestProperty("Mosquito-Destination", config.getString("destination"));
|
|
45
|
-
if (config.hasKey("authToken")) {
|
|
46
|
-
connection.setRequestProperty("mtoken", config.getString("authToken"));
|
|
47
|
-
}
|
|
48
|
-
connection.setFixedLengthStreamingMode((int) totalBytes);
|
|
49
|
-
|
|
50
|
-
OutputStream out = connection.getOutputStream();
|
|
51
|
-
FileInputStream in = new FileInputStream(file);
|
|
52
|
-
|
|
53
|
-
byte[] buffer = new byte[8192];
|
|
54
|
-
long sentBytes = 0;
|
|
55
|
-
int bytesRead;
|
|
56
|
-
|
|
57
|
-
while ((bytesRead = in.read(buffer)) != -1) {
|
|
58
|
-
if (isCancelled) {
|
|
59
|
-
in.close();
|
|
60
|
-
out.close();
|
|
61
|
-
connection.disconnect();
|
|
62
|
-
callback.onError(new IOException("Upload cancelled"));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
out.write(buffer, 0, bytesRead);
|
|
67
|
-
sentBytes += bytesRead;
|
|
68
|
-
callback.onProgress(sentBytes, totalBytes);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
out.flush();
|
|
72
|
-
in.close();
|
|
73
|
-
out.close();
|
|
74
|
-
|
|
75
|
-
int responseCode = connection.getResponseCode();
|
|
76
|
-
InputStream responseStream = (responseCode >= 200 && responseCode < 400)
|
|
77
|
-
? connection.getInputStream()
|
|
78
|
-
: connection.getErrorStream();
|
|
79
|
-
String responseBody = readStream(responseStream);
|
|
80
|
-
|
|
81
|
-
callback.onComplete(responseCode, responseBody);
|
|
82
|
-
connection.disconnect();
|
|
83
|
-
} catch (Exception e) {
|
|
84
|
-
callback.onError(e);
|
|
85
|
-
}
|
|
86
|
-
}).start();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private String readStream(InputStream stream) throws IOException {
|
|
90
|
-
if (stream == null) return "";
|
|
91
|
-
|
|
92
|
-
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
|
93
|
-
StringBuilder result = new StringBuilder();
|
|
94
|
-
String line;
|
|
95
|
-
while ((line = reader.readLine()) != null) {
|
|
96
|
-
result.append(line).append("\n");
|
|
97
|
-
}
|
|
98
|
-
reader.close();
|
|
99
|
-
return result.toString().trim();
|
|
100
|
-
}
|
|
101
|
-
}
|
package/example/.bundle/config
DELETED
package/example/.node-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
18
|
package/example/.watchmanconfig
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
package/example/Gemfile
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
apply plugin: "com.android.application"
|
|
2
|
-
apply plugin: "com.facebook.react"
|
|
3
|
-
|
|
4
|
-
import com.android.build.OutputFile
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This is the configuration block to customize your React Native Android app.
|
|
8
|
-
* By default you don't need to apply any configuration, just uncomment the lines you need.
|
|
9
|
-
*/
|
|
10
|
-
react {
|
|
11
|
-
/* Folders */
|
|
12
|
-
// The root of your project, i.e. where "package.json" lives. Default is '..'
|
|
13
|
-
// root = file("../")
|
|
14
|
-
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
|
|
15
|
-
// reactNativeDir = file("../node_modules/react-native")
|
|
16
|
-
// The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
|
|
17
|
-
// codegenDir = file("../node_modules/react-native-codegen")
|
|
18
|
-
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
|
|
19
|
-
// cliFile = file("../node_modules/react-native/cli.js")
|
|
20
|
-
|
|
21
|
-
/* Variants */
|
|
22
|
-
// The list of variants to that are debuggable. For those we're going to
|
|
23
|
-
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
|
|
24
|
-
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
|
|
25
|
-
// debuggableVariants = ["liteDebug", "prodDebug"]
|
|
26
|
-
|
|
27
|
-
/* Bundling */
|
|
28
|
-
// A list containing the node command and its flags. Default is just 'node'.
|
|
29
|
-
// nodeExecutableAndArgs = ["node"]
|
|
30
|
-
//
|
|
31
|
-
// The command to run when bundling. By default is 'bundle'
|
|
32
|
-
// bundleCommand = "ram-bundle"
|
|
33
|
-
//
|
|
34
|
-
// The path to the CLI configuration file. Default is empty.
|
|
35
|
-
// bundleConfig = file(../rn-cli.config.js)
|
|
36
|
-
//
|
|
37
|
-
// The name of the generated asset file containing your JS bundle
|
|
38
|
-
// bundleAssetName = "MyApplication.android.bundle"
|
|
39
|
-
//
|
|
40
|
-
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
|
|
41
|
-
// entryFile = file("../js/MyApplication.android.js")
|
|
42
|
-
//
|
|
43
|
-
// A list of extra flags to pass to the 'bundle' commands.
|
|
44
|
-
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
|
|
45
|
-
// extraPackagerArgs = []
|
|
46
|
-
|
|
47
|
-
/* Hermes Commands */
|
|
48
|
-
// The hermes compiler command to run. By default it is 'hermesc'
|
|
49
|
-
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
|
|
50
|
-
//
|
|
51
|
-
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
|
|
52
|
-
// hermesFlags = ["-O", "-output-source-map"]
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Set this to true to create four separate APKs instead of one,
|
|
57
|
-
* one for each native architecture. This is useful if you don't
|
|
58
|
-
* use App Bundles (https://developer.android.com/guide/app-bundle/)
|
|
59
|
-
* and want to have separate APKs to upload to the Play Store.
|
|
60
|
-
*/
|
|
61
|
-
def enableSeparateBuildPerCPUArchitecture = false
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
|
|
65
|
-
*/
|
|
66
|
-
def enableProguardInReleaseBuilds = false
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* The preferred build flavor of JavaScriptCore (JSC)
|
|
70
|
-
*
|
|
71
|
-
* For example, to use the international variant, you can use:
|
|
72
|
-
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
|
|
73
|
-
*
|
|
74
|
-
* The international variant includes ICU i18n library and necessary data
|
|
75
|
-
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
|
|
76
|
-
* give correct results when using with locales other than en-US. Note that
|
|
77
|
-
* this variant is about 6MiB larger per architecture than default.
|
|
78
|
-
*/
|
|
79
|
-
def jscFlavor = 'org.webkit:android-jsc:+'
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Private function to get the list of Native Architectures you want to build.
|
|
83
|
-
* This reads the value from reactNativeArchitectures in your gradle.properties
|
|
84
|
-
* file and works together with the --active-arch-only flag of react-native run-android.
|
|
85
|
-
*/
|
|
86
|
-
def reactNativeArchitectures() {
|
|
87
|
-
def value = project.getProperties().get("reactNativeArchitectures")
|
|
88
|
-
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
android {
|
|
92
|
-
ndkVersion rootProject.ext.ndkVersion
|
|
93
|
-
|
|
94
|
-
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
95
|
-
|
|
96
|
-
namespace "com.mosquitodbexample"
|
|
97
|
-
defaultConfig {
|
|
98
|
-
applicationId "com.mosquitodbexample"
|
|
99
|
-
minSdkVersion rootProject.ext.minSdkVersion
|
|
100
|
-
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
101
|
-
versionCode 1
|
|
102
|
-
versionName "1.0"
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
splits {
|
|
106
|
-
abi {
|
|
107
|
-
reset()
|
|
108
|
-
enable enableSeparateBuildPerCPUArchitecture
|
|
109
|
-
universalApk false // If true, also generate a universal APK
|
|
110
|
-
include (*reactNativeArchitectures())
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
signingConfigs {
|
|
114
|
-
debug {
|
|
115
|
-
storeFile file('debug.keystore')
|
|
116
|
-
storePassword 'android'
|
|
117
|
-
keyAlias 'androiddebugkey'
|
|
118
|
-
keyPassword 'android'
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
buildTypes {
|
|
122
|
-
debug {
|
|
123
|
-
signingConfig signingConfigs.debug
|
|
124
|
-
}
|
|
125
|
-
release {
|
|
126
|
-
// Caution! In production, you need to generate your own keystore file.
|
|
127
|
-
// see https://reactnative.dev/docs/signed-apk-android.
|
|
128
|
-
signingConfig signingConfigs.debug
|
|
129
|
-
minifyEnabled enableProguardInReleaseBuilds
|
|
130
|
-
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// applicationVariants are e.g. debug, release
|
|
135
|
-
applicationVariants.all { variant ->
|
|
136
|
-
variant.outputs.each { output ->
|
|
137
|
-
// For each separate APK per architecture, set a unique version code as described here:
|
|
138
|
-
// https://developer.android.com/studio/build/configure-apk-splits.html
|
|
139
|
-
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
|
|
140
|
-
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
|
|
141
|
-
def abi = output.getFilter(OutputFile.ABI)
|
|
142
|
-
if (abi != null) { // null for the universal-debug, universal-release variants
|
|
143
|
-
output.versionCodeOverride =
|
|
144
|
-
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
dependencies {
|
|
152
|
-
// The version of react-native is set by the React Native Gradle Plugin
|
|
153
|
-
implementation("com.facebook.react:react-android")
|
|
154
|
-
|
|
155
|
-
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
|
|
156
|
-
|
|
157
|
-
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
|
|
158
|
-
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
|
|
159
|
-
exclude group:'com.squareup.okhttp3', module:'okhttp'
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
|
|
163
|
-
if (hermesEnabled.toBoolean()) {
|
|
164
|
-
implementation("com.facebook.react:hermes-android")
|
|
165
|
-
} else {
|
|
166
|
-
implementation jscFlavor
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
|
|
Binary file
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# Add project specific ProGuard rules here.
|
|
2
|
-
# By default, the flags in this file are appended to flags specified
|
|
3
|
-
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
|
|
4
|
-
# You can edit the include path and order by changing the proguardFiles
|
|
5
|
-
# directive in build.gradle.
|
|
6
|
-
#
|
|
7
|
-
# For more details, see
|
|
8
|
-
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
9
|
-
|
|
10
|
-
# Add any project specific keep options here:
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
-
xmlns:tools="http://schemas.android.com/tools">
|
|
4
|
-
|
|
5
|
-
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
|
6
|
-
|
|
7
|
-
<application
|
|
8
|
-
android:usesCleartextTraffic="true"
|
|
9
|
-
tools:targetApi="28"
|
|
10
|
-
tools:ignore="GoogleAppIndexingWarning">
|
|
11
|
-
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
|
|
12
|
-
</application>
|
|
13
|
-
</manifest>
|