@dittolive/ditto 4.7.4-rc.2 → 4.7.4
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/DittoReactNative.podspec +27 -0
- package/README.md +2 -2
- package/node/ditto.cjs.js +1 -1
- package/node/ditto.darwin-arm64.node +0 -0
- package/node/ditto.darwin-x64.node +0 -0
- package/node/ditto.linux-arm.node +0 -0
- package/node/ditto.linux-arm64.node +0 -0
- package/node/ditto.linux-x64.node +0 -0
- package/node/ditto.win32-x64.node +0 -0
- package/node/transports.darwin-arm64.node +0 -0
- package/node/transports.darwin-x64.node +0 -0
- package/package.json +5 -2
- package/react-native/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/react-native/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/react-native/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/react-native/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/react-native/android/.gradle/8.9/gc.properties +0 -0
- package/react-native/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/react-native/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/react-native/android/.gradle/vcs-1/gc.properties +0 -0
- package/react-native/android/CMakeLists.txt +36 -0
- package/react-native/android/build.gradle +190 -0
- package/react-native/android/cpp-adapter.cpp +259 -0
- package/react-native/android/gradle.properties +5 -0
- package/react-native/android/src/main/AndroidManifest.xml +4 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +120 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
- package/react-native/cpp/include/Arc.hpp +159 -0
- package/react-native/cpp/include/Attachment.h +20 -0
- package/react-native/cpp/include/Authentication.h +23 -0
- package/react-native/cpp/include/Collection.h +13 -0
- package/react-native/cpp/include/ConnectionRequest.h +18 -0
- package/react-native/cpp/include/DQL.h +21 -0
- package/react-native/cpp/include/Document.h +17 -0
- package/react-native/cpp/include/FFIUtils.h +16 -0
- package/react-native/cpp/include/IO.h +13 -0
- package/react-native/cpp/include/Identity.h +17 -0
- package/react-native/cpp/include/Lifecycle.h +16 -0
- package/react-native/cpp/include/LiveQuery.h +17 -0
- package/react-native/cpp/include/Logger.h +22 -0
- package/react-native/cpp/include/Misc.h +30 -0
- package/react-native/cpp/include/Presence.h +18 -0
- package/react-native/cpp/include/SmallPeerInfo.h +19 -0
- package/react-native/cpp/include/Transports.h +25 -0
- package/react-native/cpp/include/TypedArray.hpp +167 -0
- package/react-native/cpp/include/Utils.h +70 -0
- package/react-native/cpp/include/main.h +10 -0
- package/react-native/cpp/src/Attachment.cpp +272 -0
- package/react-native/cpp/src/Authentication.cpp +227 -0
- package/react-native/cpp/src/Collection.cpp +56 -0
- package/react-native/cpp/src/ConnectionRequest.cpp +123 -0
- package/react-native/cpp/src/DQL.cpp +256 -0
- package/react-native/cpp/src/Document.cpp +146 -0
- package/react-native/cpp/src/FFIUtils.cpp +122 -0
- package/react-native/cpp/src/IO.cpp +35 -0
- package/react-native/cpp/src/Identity.cpp +122 -0
- package/react-native/cpp/src/Lifecycle.cpp +93 -0
- package/react-native/cpp/src/LiveQuery.cpp +63 -0
- package/react-native/cpp/src/Logger.cpp +199 -0
- package/react-native/cpp/src/Misc.cpp +322 -0
- package/react-native/cpp/src/Presence.cpp +166 -0
- package/react-native/cpp/src/SmallPeerInfo.cpp +142 -0
- package/react-native/cpp/src/Transports.cpp +275 -0
- package/react-native/cpp/src/TypedArray.cpp +303 -0
- package/react-native/cpp/src/Utils.cpp +139 -0
- package/react-native/cpp/src/main.cpp +178 -0
- package/react-native/dittoffi/dittoffi.h +4873 -0
- package/react-native/dittoffi/ifaddrs.cpp +385 -0
- package/react-native/dittoffi/ifaddrs.h +206 -0
- package/react-native/ios/DittoRNSDK.h +7 -0
- package/react-native/ios/DittoRNSDK.mm +159 -0
- package/react-native/ios/YeetJSIUtils.h +60 -0
- package/react-native/ios/YeetJSIUtils.mm +196 -0
- package/react-native/lib/commonjs/ditto.rn.js +93 -0
- package/react-native/lib/commonjs/ditto.rn.js.map +1 -0
- package/react-native/lib/commonjs/index.js +61 -0
- package/react-native/lib/commonjs/index.js.map +1 -0
- package/react-native/lib/module/ditto.rn.js +89 -0
- package/react-native/lib/module/ditto.rn.js.map +1 -0
- package/react-native/lib/module/index.js +27 -0
- package/react-native/lib/module/index.js.map +1 -0
- package/react-native/lib/typescript/ditto.rn.d.ts +15 -0
- package/react-native/lib/typescript/ditto.rn.d.ts.map +1 -0
- package/react-native/lib/typescript/index.d.ts +1 -0
- package/react-native/lib/typescript/index.d.ts.map +1 -0
- package/react-native/src/ditto.rn.ts +123 -0
- package/react-native/src/environment/environment.fallback.ts +4 -0
- package/react-native/src/index.ts +29 -0
- package/react-native/src/sources/@cbor-redux.ts +2 -0
- package/react-native/src/sources/@ditto.core.ts +1 -0
- package/react-native/src/sources/@environment.ts +1 -0
- package/react-native/src/sources/attachment-fetch-event.ts +54 -0
- package/react-native/src/sources/attachment-fetcher-manager.ts +145 -0
- package/react-native/src/sources/attachment-fetcher.ts +265 -0
- package/react-native/src/sources/attachment-token.ts +129 -0
- package/react-native/src/sources/attachment.ts +121 -0
- package/react-native/src/sources/augment.ts +108 -0
- package/react-native/src/sources/authenticator.ts +314 -0
- package/react-native/src/sources/base-pending-cursor-operation.ts +255 -0
- package/react-native/src/sources/base-pending-id-specific-operation.ts +112 -0
- package/react-native/src/sources/bridge.ts +557 -0
- package/react-native/src/sources/build-time-constants.ts +8 -0
- package/react-native/src/sources/cbor.ts +20 -0
- package/react-native/src/sources/collection-interface.ts +73 -0
- package/react-native/src/sources/collection.ts +219 -0
- package/react-native/src/sources/collections-event.ts +99 -0
- package/react-native/src/sources/connection-request.ts +142 -0
- package/react-native/src/sources/counter.ts +82 -0
- package/react-native/src/sources/ditto.ts +991 -0
- package/react-native/src/sources/document-id.ts +163 -0
- package/react-native/src/sources/document-path.ts +308 -0
- package/react-native/src/sources/document.ts +237 -0
- package/react-native/src/sources/epilogue.ts +32 -0
- package/react-native/src/sources/error-codes.ts +114 -0
- package/react-native/src/sources/error.ts +256 -0
- package/react-native/src/sources/essentials.ts +81 -0
- package/react-native/src/sources/ffi-error.ts +134 -0
- package/react-native/src/sources/ffi.ts +2190 -0
- package/react-native/src/sources/identity.ts +163 -0
- package/react-native/src/sources/init.ts +71 -0
- package/react-native/src/sources/internal.ts +143 -0
- package/react-native/src/sources/keep-alive.ts +73 -0
- package/react-native/src/sources/key-path.ts +198 -0
- package/react-native/src/sources/live-query-event.ts +208 -0
- package/react-native/src/sources/live-query-manager.ts +110 -0
- package/react-native/src/sources/live-query.ts +167 -0
- package/react-native/src/sources/logger.ts +196 -0
- package/react-native/src/sources/main.ts +61 -0
- package/react-native/src/sources/observer-manager.ts +185 -0
- package/react-native/src/sources/observer.ts +79 -0
- package/react-native/src/sources/pending-collections-operation.ts +241 -0
- package/react-native/src/sources/pending-cursor-operation.ts +218 -0
- package/react-native/src/sources/pending-id-specific-operation.ts +218 -0
- package/react-native/src/sources/presence-manager.ts +170 -0
- package/react-native/src/sources/presence.ts +427 -0
- package/react-native/src/sources/query-result-item.ts +131 -0
- package/react-native/src/sources/query-result.ts +55 -0
- package/react-native/src/sources/register.ts +95 -0
- package/react-native/src/sources/small-peer-info.ts +166 -0
- package/react-native/src/sources/static-tcp-client.ts +8 -0
- package/react-native/src/sources/store-observer.ts +170 -0
- package/react-native/src/sources/store.ts +630 -0
- package/react-native/src/sources/subscription-manager.ts +99 -0
- package/react-native/src/sources/subscription.ts +89 -0
- package/react-native/src/sources/sync-subscription.ts +90 -0
- package/react-native/src/sources/sync.ts +561 -0
- package/react-native/src/sources/test-helpers.ts +24 -0
- package/react-native/src/sources/transport-conditions-manager.ts +104 -0
- package/react-native/src/sources/transport-config.ts +430 -0
- package/react-native/src/sources/update-result.ts +66 -0
- package/react-native/src/sources/update-results-map.ts +65 -0
- package/react-native/src/sources/websocket-client.ts +7 -0
- package/react-native/src/sources/write-transaction-collection.ts +122 -0
- package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +101 -0
- package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +74 -0
- package/react-native/src/sources/write-transaction.ts +121 -0
- package/react-native.config.js +9 -0
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Podspec *must* be located at package root level or it will not be find for React
|
|
2
|
+
# Native's autolinking.
|
|
3
|
+
#
|
|
4
|
+
# It would be great to move this to the RN folder and still have the
|
|
5
|
+
# relative paths work in production somehow. Maybe when RN will stop forcing
|
|
6
|
+
# the podspec to exist at root level or allow us to modify it via some property.
|
|
7
|
+
require "json"
|
|
8
|
+
|
|
9
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
10
|
+
|
|
11
|
+
Pod::Spec.new do |s|
|
|
12
|
+
s.name = "DittoReactNative"
|
|
13
|
+
s.version = package["version"]
|
|
14
|
+
s.summary = package["description"]
|
|
15
|
+
s.homepage = package["homepage"]
|
|
16
|
+
s.license = package["license"]
|
|
17
|
+
s.authors = package["author"]
|
|
18
|
+
|
|
19
|
+
s.platforms = { :ios => "14.0" }
|
|
20
|
+
s.source = { :http => 'https://ditto.live' }
|
|
21
|
+
|
|
22
|
+
s.source_files = "react-native/ios/**/*.{h,m,mm}", "react-native/cpp/**/*.{h,cpp,hpp}",
|
|
23
|
+
s.public_header_files = 'react-native/dittoffi/dittoffi.h', 'react-native/dittoffi/ifaddrs.h'
|
|
24
|
+
|
|
25
|
+
s.dependency "React-Core"
|
|
26
|
+
s.dependency 'DittoReactNativeIOS', "~> #{package["version"]}"
|
|
27
|
+
end
|
package/README.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
_Ditto is a cross-platform SDK that allows mobile, web, and IoT apps to sync
|
|
4
4
|
with and even without connectivity._
|
|
5
5
|
|
|
6
|
-
Version: **4.7.4
|
|
6
|
+
Version: **4.7.4**
|
|
7
7
|
|
|
8
8
|
For more information please visit [ditto.live](https://ditto.live), as well as the
|
|
9
|
-
[API Reference](https://software.ditto.live/js/Ditto/4.7.4
|
|
9
|
+
[API Reference](https://software.ditto.live/js/Ditto/4.7.4/api-reference/) for this particular version.
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
package/node/ditto.cjs.js
CHANGED
|
@@ -2222,7 +2222,7 @@ class AttachmentToken {
|
|
|
2222
2222
|
|
|
2223
2223
|
// NOTE: this is patched up with the actual build version by Jake task
|
|
2224
2224
|
// build:package and has to be a valid semantic version as defined here: https://semver.org.
|
|
2225
|
-
const fullBuildVersionString = '4.7.4
|
|
2225
|
+
const fullBuildVersionString = '4.7.4';
|
|
2226
2226
|
|
|
2227
2227
|
//
|
|
2228
2228
|
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dittolive/ditto",
|
|
3
|
-
"version": "4.7.4
|
|
3
|
+
"version": "4.7.4",
|
|
4
4
|
"description": "Ditto is a cross-platform embeddable NoSQL database that can sync with or without an internet connection.",
|
|
5
5
|
"homepage": "https://ditto.live",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"browser": "web/ditto.es6.js",
|
|
35
35
|
"browser/umd": "web/ditto.umd.js",
|
|
36
36
|
"types": "types/ditto.d.ts",
|
|
37
|
+
"react-native": "react-native/src/index.ts",
|
|
37
38
|
|
|
38
39
|
"scripts": {
|
|
39
40
|
"play:web": "npx serve --listen 5285",
|
|
@@ -41,7 +42,9 @@
|
|
|
41
42
|
},
|
|
42
43
|
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"cbor-redux": "^1.0.0"
|
|
45
|
+
"cbor-redux": "^1.0.0",
|
|
46
|
+
"@ungap/weakrefs": "^0.2.0",
|
|
47
|
+
"fastestsmallesttextencoderdecoder": "^1.0.22"
|
|
45
48
|
},
|
|
46
49
|
|
|
47
50
|
"devDependencies": {
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
2
|
+
|
|
3
|
+
set (PACKAGE_NAME "cpp")
|
|
4
|
+
project(PACKAGE_NAME)
|
|
5
|
+
set (BUILD_DIR ../../../)
|
|
6
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
7
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
8
|
+
|
|
9
|
+
include_directories(
|
|
10
|
+
../cpp/include
|
|
11
|
+
../dittoffi
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
file(GLOB SOURCES "../cpp/src/*.cpp")
|
|
15
|
+
add_library(
|
|
16
|
+
${PACKAGE_NAME}
|
|
17
|
+
SHARED
|
|
18
|
+
${SOURCES}
|
|
19
|
+
../dittoffi/ifaddrs.cpp
|
|
20
|
+
./cpp-adapter.cpp
|
|
21
|
+
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
|
25
|
+
find_library(log-lib log)
|
|
26
|
+
|
|
27
|
+
add_library(ditto STATIC IMPORTED)
|
|
28
|
+
set_target_properties(ditto PROPERTIES IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/../dittoffi/android/${ANDROID_ABI}/libdittoffi.a")
|
|
29
|
+
|
|
30
|
+
target_link_libraries(
|
|
31
|
+
${PACKAGE_NAME}
|
|
32
|
+
ditto
|
|
33
|
+
${log-lib}
|
|
34
|
+
ReactAndroid::jsi
|
|
35
|
+
android
|
|
36
|
+
)
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import java.nio.file.Paths
|
|
2
|
+
|
|
3
|
+
buildscript {
|
|
4
|
+
repositories {
|
|
5
|
+
google()
|
|
6
|
+
mavenCentral()
|
|
7
|
+
}
|
|
8
|
+
dependencies {
|
|
9
|
+
classpath 'com.android.tools.build:gradle:7.2.1'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
def isNewArchitectureEnabled() {
|
|
14
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
apply plugin: "com.android.library"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
21
|
+
|
|
22
|
+
if (isNewArchitectureEnabled()) {
|
|
23
|
+
apply plugin: 'com.facebook.react'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def getExtOrDefault(name) {
|
|
27
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["rnsdk_" + name]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def getExtOrIntegerDefault(name) {
|
|
31
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["rnsdk_" + name]).toInteger()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
def found = false
|
|
35
|
+
def basePath = projectDir.toPath().normalize()
|
|
36
|
+
|
|
37
|
+
// Find node_modules inside the example project
|
|
38
|
+
def nodeModulesDir = Paths.get(basePath.getParent().toString(), "example/node_modules")
|
|
39
|
+
def reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
|
|
40
|
+
if (nodeModulesDir.toFile().exists() && reactNativeDir.toFile().exists()) {
|
|
41
|
+
found = true
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if(!found){
|
|
45
|
+
// Node's module resolution algorithm searches up to the root directory,
|
|
46
|
+
// after which the base path will be null
|
|
47
|
+
while (basePath) {
|
|
48
|
+
nodeModulesDir = Paths.get(basePath.toString(), "node_modules")
|
|
49
|
+
reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
|
|
50
|
+
if (nodeModulesDir.toFile().exists() && reactNativeDir.toFile().exists()) {
|
|
51
|
+
found = true
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
basePath = basePath.getParent()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if(!found) {
|
|
59
|
+
throw new GradleException(
|
|
60
|
+
"${project.name}: unable to locate React Native android sources. " +
|
|
61
|
+
"Ensure you have you installed React Native as a dependency in your project and try again.")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
def nodeModulesPath = nodeModulesDir.toString().replace("\\", "/")
|
|
65
|
+
def reactNativePath = reactNativeDir.toString().replace("\\", "/")
|
|
66
|
+
|
|
67
|
+
def supportsNamespace() {
|
|
68
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
69
|
+
def major = parsed[0].toInteger()
|
|
70
|
+
def minor = parsed[1].toInteger()
|
|
71
|
+
|
|
72
|
+
// Namespace support was added in 7.3.0
|
|
73
|
+
if (major == 7 && minor >= 3) {
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return major >= 8
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
android {
|
|
81
|
+
if (supportsNamespace()) {
|
|
82
|
+
namespace "com.dittolive.rnsdk"
|
|
83
|
+
|
|
84
|
+
sourceSets {
|
|
85
|
+
main {
|
|
86
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ESSENTIAL for adding JSI
|
|
92
|
+
buildFeatures {
|
|
93
|
+
prefab true
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
ndkVersion getExtOrDefault("ndkVersion")
|
|
97
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
98
|
+
|
|
99
|
+
defaultConfig {
|
|
100
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
101
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
102
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
103
|
+
externalNativeBuild {
|
|
104
|
+
cmake {
|
|
105
|
+
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
|
|
106
|
+
// ESSENTIAL for adding JSI
|
|
107
|
+
arguments "-DANDROID_STL=c++_shared"
|
|
108
|
+
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
externalNativeBuild {
|
|
114
|
+
cmake {
|
|
115
|
+
path "CMakeLists.txt"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
buildTypes {
|
|
120
|
+
release {
|
|
121
|
+
minifyEnabled false
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
lintOptions {
|
|
126
|
+
disable "GradleCompatible"
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
compileOptions {
|
|
130
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
131
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
sourceSets {
|
|
135
|
+
main {
|
|
136
|
+
if (isNewArchitectureEnabled()) {
|
|
137
|
+
java.srcDirs += [
|
|
138
|
+
// This is needed to build Kotlin project with NewArch enabled
|
|
139
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
repositories {
|
|
147
|
+
mavenCentral()
|
|
148
|
+
google()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// This can be moved to gradle.properties (minus the quotes) with no code changes
|
|
152
|
+
// here since `version` is a default project property.
|
|
153
|
+
version = "4.7.4"
|
|
154
|
+
|
|
155
|
+
dependencies {
|
|
156
|
+
// For < 0.71, this will be from the local maven repo
|
|
157
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
158
|
+
//noinspection GradleDynamicVersion
|
|
159
|
+
implementation "com.facebook.react:react-native:+"
|
|
160
|
+
implementation "live.ditto:ditto:${project.version}"
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (isNewArchitectureEnabled()) {
|
|
164
|
+
react {
|
|
165
|
+
jsRootDir = file("../src/")
|
|
166
|
+
libraryName = "DittoRNSDK"
|
|
167
|
+
codegenJavaPackageName = "com.dittolive.rnsdk"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
task downloadBinaries {
|
|
172
|
+
doLast {
|
|
173
|
+
def defaultArchitectures = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64']
|
|
174
|
+
|
|
175
|
+
defaultArchitectures.each { arch ->
|
|
176
|
+
def fileUrl = "https://software.ditto.live/react-native/ditto/${project.version}/android/${arch}/libdittoffi.a"
|
|
177
|
+
|
|
178
|
+
new File("${project.projectDir}/../dittoffi/android/${arch}").mkdirs()
|
|
179
|
+
def localFilePath = "${project.projectDir}/../dittoffi/android/${arch}/libdittoffi.a"
|
|
180
|
+
|
|
181
|
+
if (!new File(localFilePath).exists()) {
|
|
182
|
+
println "Downloading file for $arch: $fileUrl"
|
|
183
|
+
ant.get(src: fileUrl, dest: localFilePath, verbose: true)
|
|
184
|
+
} else {
|
|
185
|
+
println "File for $arch already exists, skipping download: $localFilePath"
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
preBuild.dependsOn downloadBinaries
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#include <jni.h>
|
|
2
|
+
#include <sys/types.h>
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <pthread.h>
|
|
5
|
+
|
|
6
|
+
#include "main.h"
|
|
7
|
+
#include "TypedArray.hpp"
|
|
8
|
+
#include "dittoffi.h"
|
|
9
|
+
#include <sstream>
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <vector>
|
|
12
|
+
#include <android/log.h>
|
|
13
|
+
|
|
14
|
+
using namespace facebook::jsi;
|
|
15
|
+
|
|
16
|
+
JavaVM *java_vm;
|
|
17
|
+
jclass java_class;
|
|
18
|
+
jobject java_object;
|
|
19
|
+
jobject java_context;
|
|
20
|
+
|
|
21
|
+
void DeferThreadDetach(JNIEnv *env)
|
|
22
|
+
{
|
|
23
|
+
static pthread_key_t thread_key;
|
|
24
|
+
|
|
25
|
+
static auto run_once = []
|
|
26
|
+
{
|
|
27
|
+
const auto err = pthread_key_create(&thread_key, [](void *ts_env)
|
|
28
|
+
{
|
|
29
|
+
if (ts_env) {
|
|
30
|
+
java_vm->DetachCurrentThread();
|
|
31
|
+
} });
|
|
32
|
+
if (err)
|
|
33
|
+
{
|
|
34
|
+
// Failed to create TSD key. Throw an exception if you want to.
|
|
35
|
+
}
|
|
36
|
+
return 0;
|
|
37
|
+
}();
|
|
38
|
+
|
|
39
|
+
const auto ts_env = pthread_getspecific(thread_key);
|
|
40
|
+
if (!ts_env)
|
|
41
|
+
{
|
|
42
|
+
if (pthread_setspecific(thread_key, env))
|
|
43
|
+
{
|
|
44
|
+
// Failed to set thread-specific value for key. Throw an exception if you want to.
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
JNIEnv *GetJniEnv()
|
|
50
|
+
{
|
|
51
|
+
JNIEnv *env = nullptr;
|
|
52
|
+
|
|
53
|
+
auto get_env_result = java_vm->GetEnv((void **)&env, JNI_VERSION_1_6);
|
|
54
|
+
if (get_env_result == JNI_EDETACHED)
|
|
55
|
+
{
|
|
56
|
+
if (java_vm->AttachCurrentThread(&env, NULL) == JNI_OK)
|
|
57
|
+
{
|
|
58
|
+
DeferThreadDetach(env);
|
|
59
|
+
}
|
|
60
|
+
else
|
|
61
|
+
{
|
|
62
|
+
// Failed to attach thread. Throw an exception if you want to.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (get_env_result == JNI_EVERSION)
|
|
66
|
+
{
|
|
67
|
+
// Unsupported JNI version. Throw an exception if you want to.
|
|
68
|
+
}
|
|
69
|
+
return env;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static jstring string2jstring(JNIEnv *env, const std::string &str)
|
|
73
|
+
{
|
|
74
|
+
return (*env).NewStringUTF(str.c_str());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
void install(Runtime &jsiRuntime)
|
|
78
|
+
{
|
|
79
|
+
auto defaultDeviceName = Function::createFromHostFunction(jsiRuntime,
|
|
80
|
+
PropNameID::forAscii(jsiRuntime,
|
|
81
|
+
"defaultDeviceName"),
|
|
82
|
+
0,
|
|
83
|
+
[](Runtime &runtime,
|
|
84
|
+
const Value &thisValue,
|
|
85
|
+
const Value *arguments,
|
|
86
|
+
size_t count) -> Value
|
|
87
|
+
{
|
|
88
|
+
JNIEnv *jniEnv = GetJniEnv();
|
|
89
|
+
|
|
90
|
+
java_class = jniEnv->GetObjectClass(
|
|
91
|
+
java_object);
|
|
92
|
+
jmethodID defaultDeviceName = jniEnv->GetMethodID(
|
|
93
|
+
java_class, "defaultDeviceName",
|
|
94
|
+
"()Ljava/lang/String;");
|
|
95
|
+
jobject result = jniEnv->CallObjectMethod(
|
|
96
|
+
java_object, defaultDeviceName);
|
|
97
|
+
const char *str = jniEnv->GetStringUTFChars(
|
|
98
|
+
(jstring)result, NULL);
|
|
99
|
+
|
|
100
|
+
return Value(runtime,
|
|
101
|
+
String::createFromUtf8(
|
|
102
|
+
runtime, str));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
jsiRuntime.global().setProperty(jsiRuntime, "defaultDeviceName", std::move(defaultDeviceName));
|
|
106
|
+
|
|
107
|
+
auto createDirectory = Function::createFromHostFunction(jsiRuntime,
|
|
108
|
+
PropNameID::forAscii(jsiRuntime,
|
|
109
|
+
"createDirectory"),
|
|
110
|
+
0,
|
|
111
|
+
[](Runtime &runtime,
|
|
112
|
+
const Value &thisValue,
|
|
113
|
+
const Value *arguments,
|
|
114
|
+
size_t count) -> Value
|
|
115
|
+
{
|
|
116
|
+
std::string path = arguments[0].getString(runtime).utf8(runtime);
|
|
117
|
+
JNIEnv *jniEnv = GetJniEnv();
|
|
118
|
+
|
|
119
|
+
jclass localJavaClass = jniEnv->GetObjectClass(java_object);
|
|
120
|
+
jmethodID createDirectory = jniEnv->GetMethodID(localJavaClass, "createDirectory", "(Ljava/lang/String;)Ljava/lang/String;");
|
|
121
|
+
jstring jPath = string2jstring(jniEnv, path);
|
|
122
|
+
jobject result = jniEnv->CallObjectMethod(java_object, createDirectory, jPath);
|
|
123
|
+
|
|
124
|
+
const char *str = jniEnv->GetStringUTFChars((jstring)result, NULL);
|
|
125
|
+
|
|
126
|
+
jniEnv->ReleaseStringUTFChars((jstring)result, str);
|
|
127
|
+
jniEnv->DeleteLocalRef(jPath);
|
|
128
|
+
jniEnv->DeleteLocalRef(localJavaClass);
|
|
129
|
+
jniEnv->DeleteLocalRef(result);
|
|
130
|
+
|
|
131
|
+
return Value(runtime, String::createFromUtf8(runtime, str));
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
jsiRuntime.global().setProperty(jsiRuntime, "createDirectory", std::move(createDirectory));
|
|
135
|
+
|
|
136
|
+
auto copyFile = Function::createFromHostFunction(jsiRuntime,
|
|
137
|
+
PropNameID::forAscii(jsiRuntime, "copyFile"),
|
|
138
|
+
3,
|
|
139
|
+
[](Runtime &runtime,
|
|
140
|
+
const Value &thisValue,
|
|
141
|
+
const Value *arguments,
|
|
142
|
+
size_t count) -> Value {
|
|
143
|
+
std::string sourcePath = arguments[0].getString(runtime).utf8(runtime);
|
|
144
|
+
std::string destinationPath = arguments[1].getString(runtime).utf8(runtime);
|
|
145
|
+
std::string defaultFolder = arguments[2].getString(runtime).utf8(runtime);
|
|
146
|
+
|
|
147
|
+
JNIEnv *jniEnv = GetJniEnv();
|
|
148
|
+
|
|
149
|
+
jclass fileManagerClass = jniEnv->GetObjectClass(java_object);
|
|
150
|
+
jmethodID copyFileMethod = jniEnv->GetMethodID(fileManagerClass, "copyFile", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
|
151
|
+
|
|
152
|
+
jstring jSourcePath = jniEnv->NewStringUTF(sourcePath.c_str());
|
|
153
|
+
jstring jDestinationPath = jniEnv->NewStringUTF(destinationPath.c_str());
|
|
154
|
+
jstring jDefaultFolder = jniEnv->NewStringUTF(defaultFolder.c_str());
|
|
155
|
+
|
|
156
|
+
jniEnv->CallVoidMethod(java_object, copyFileMethod, jSourcePath, jDestinationPath, jDefaultFolder);
|
|
157
|
+
|
|
158
|
+
jniEnv->DeleteLocalRef(jSourcePath);
|
|
159
|
+
jniEnv->DeleteLocalRef(jDestinationPath);
|
|
160
|
+
jniEnv->DeleteLocalRef(jDefaultFolder);
|
|
161
|
+
jniEnv->DeleteLocalRef(fileManagerClass);
|
|
162
|
+
|
|
163
|
+
return Value();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
jsiRuntime.global().setProperty(jsiRuntime, "copyFile", std::move(copyFile));
|
|
167
|
+
|
|
168
|
+
auto getRandomValues = Function::createFromHostFunction(jsiRuntime,
|
|
169
|
+
PropNameID::forUtf8(jsiRuntime, "getRandomValues"),
|
|
170
|
+
1,
|
|
171
|
+
[](Runtime &runtime,
|
|
172
|
+
const Value &thisArg,
|
|
173
|
+
const Value *args,
|
|
174
|
+
size_t count) -> Value
|
|
175
|
+
{
|
|
176
|
+
TypedArrayBase typedArrayBase(runtime, args[0].asObject(runtime));
|
|
177
|
+
auto byteLength = typedArrayBase.byteLength(runtime);
|
|
178
|
+
|
|
179
|
+
JNIEnv *jniEnv = GetJniEnv();
|
|
180
|
+
jclass clazz = jniEnv->GetObjectClass(java_object);
|
|
181
|
+
jmethodID getRandomValues = jniEnv->GetMethodID(clazz, "getRandomValues", "(I)[B");
|
|
182
|
+
auto b = (jbyteArray)jniEnv->CallObjectMethod(java_object,
|
|
183
|
+
getRandomValues,
|
|
184
|
+
byteLength);
|
|
185
|
+
jboolean isCopy = true;
|
|
186
|
+
jbyte *values = jniEnv->GetByteArrayElements(b, &isCopy);
|
|
187
|
+
jniEnv->DeleteLocalRef(b);
|
|
188
|
+
|
|
189
|
+
auto randomValues = reinterpret_cast<std::byte *>(values);
|
|
190
|
+
|
|
191
|
+
auto typedArray = TypedArray<TypedArrayKind::Uint8Array>(runtime, byteLength);
|
|
192
|
+
auto arrayBuffer = typedArray.getBuffer(runtime);
|
|
193
|
+
memcpy(arrayBuffer.data(runtime), reinterpret_cast<std::byte *>(randomValues), byteLength);
|
|
194
|
+
return typedArray;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
jsiRuntime.global().setProperty(jsiRuntime, "getRandomValues", std::move(getRandomValues));
|
|
198
|
+
|
|
199
|
+
auto ditto_sdk_transports_set_android_context = Function::createFromHostFunction(jsiRuntime,
|
|
200
|
+
PropNameID::forUtf8(
|
|
201
|
+
jsiRuntime,
|
|
202
|
+
"ditto_sdk_transports_set_android_context"),
|
|
203
|
+
1,
|
|
204
|
+
[](Runtime &runtime,
|
|
205
|
+
const Value &thisArg,
|
|
206
|
+
const Value *args,
|
|
207
|
+
size_t count) -> Value {
|
|
208
|
+
|
|
209
|
+
return ::ditto_sdk_transports_set_android_context(
|
|
210
|
+
GetJniEnv(),
|
|
211
|
+
java_context);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
jsiRuntime.global().setProperty(jsiRuntime, "ditto_sdk_transports_set_android_context",
|
|
215
|
+
std::move(ditto_sdk_transports_set_android_context));
|
|
216
|
+
|
|
217
|
+
auto ditto_sdk_transports_android_missing_permissions = Function::createFromHostFunction(
|
|
218
|
+
jsiRuntime,
|
|
219
|
+
PropNameID::forUtf8(jsiRuntime, "ditto_sdk_transports_android_missing_permissions"),
|
|
220
|
+
1,
|
|
221
|
+
[](Runtime &runtime,
|
|
222
|
+
const Value &thisArg,
|
|
223
|
+
const Value *args,
|
|
224
|
+
size_t count) -> Value {
|
|
225
|
+
char *result = ::ditto_sdk_transports_android_missing_permissions();
|
|
226
|
+
std::vector<std::string> lines;
|
|
227
|
+
std::stringstream ss(result);
|
|
228
|
+
std::string line;
|
|
229
|
+
while (std::getline(ss, line, '\n')) {
|
|
230
|
+
lines.push_back(line);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
Array jsiArray(runtime, lines.size());
|
|
234
|
+
for (size_t i = 0; i < lines.size(); ++i) {
|
|
235
|
+
jsiArray.setValueAtIndex(runtime, i, String::createFromUtf8(runtime, lines[i]));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return jsiArray;
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
jsiRuntime.global().setProperty(jsiRuntime, "ditto_sdk_transports_android_missing_permissions",
|
|
242
|
+
std::move(ditto_sdk_transports_android_missing_permissions));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
extern "C" JNIEXPORT void JNICALL
|
|
246
|
+
Java_com_dittolive_rnsdk_DittoRNSDKModule_nativeInstall(JNIEnv *env, jobject thiz, jobject context,
|
|
247
|
+
jlong jsiPtr) {
|
|
248
|
+
// Save context, module, java_vm objects globally (thread-safe, as opposed to JNIEnv)
|
|
249
|
+
java_context = env->NewGlobalRef(context);
|
|
250
|
+
java_object = env->NewGlobalRef(thiz);
|
|
251
|
+
env->GetJavaVM(&java_vm);
|
|
252
|
+
|
|
253
|
+
// Install JSI
|
|
254
|
+
Runtime *runtime = reinterpret_cast<Runtime *>(jsiPtr);
|
|
255
|
+
if (runtime) {
|
|
256
|
+
sharedjsi::install(*runtime);
|
|
257
|
+
install(*runtime);
|
|
258
|
+
}
|
|
259
|
+
}
|