@dittolive/ditto 4.4.4 → 4.5.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/DittoReactNative.podspec +27 -0
- package/README.md +68 -51
- package/node/ditto.cjs.js +1639 -851
- 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-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 +34 -38
- package/react-native/android/CMakeLists.txt +37 -0
- package/react-native/android/build.gradle +203 -0
- package/react-native/android/cpp-adapter.cpp +254 -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 +85 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
- package/react-native/boost/boost/assert.hpp +85 -0
- package/react-native/boost/boost/config/abi/borland_prefix.hpp +27 -0
- package/react-native/boost/boost/config/abi/borland_suffix.hpp +12 -0
- package/react-native/boost/boost/config/abi/msvc_prefix.hpp +22 -0
- package/react-native/boost/boost/config/abi/msvc_suffix.hpp +8 -0
- package/react-native/boost/boost/config/abi_prefix.hpp +25 -0
- package/react-native/boost/boost/config/abi_suffix.hpp +25 -0
- package/react-native/boost/boost/config/assert_cxx03.hpp +211 -0
- package/react-native/boost/boost/config/assert_cxx11.hpp +209 -0
- package/react-native/boost/boost/config/assert_cxx14.hpp +47 -0
- package/react-native/boost/boost/config/assert_cxx17.hpp +62 -0
- package/react-native/boost/boost/config/assert_cxx20.hpp +59 -0
- package/react-native/boost/boost/config/assert_cxx98.hpp +23 -0
- package/react-native/boost/boost/config/auto_link.hpp +525 -0
- package/react-native/boost/boost/config/compiler/borland.hpp +339 -0
- package/react-native/boost/boost/config/compiler/clang.hpp +366 -0
- package/react-native/boost/boost/config/compiler/clang_version.hpp +83 -0
- package/react-native/boost/boost/config/compiler/codegear.hpp +385 -0
- package/react-native/boost/boost/config/compiler/comeau.hpp +59 -0
- package/react-native/boost/boost/config/compiler/common_edg.hpp +183 -0
- package/react-native/boost/boost/config/compiler/compaq_cxx.hpp +19 -0
- package/react-native/boost/boost/config/compiler/cray.hpp +446 -0
- package/react-native/boost/boost/config/compiler/diab.hpp +26 -0
- package/react-native/boost/boost/config/compiler/digitalmars.hpp +143 -0
- package/react-native/boost/boost/config/compiler/gcc.hpp +383 -0
- package/react-native/boost/boost/config/compiler/gcc_xml.hpp +114 -0
- package/react-native/boost/boost/config/compiler/greenhills.hpp +28 -0
- package/react-native/boost/boost/config/compiler/hp_acc.hpp +149 -0
- package/react-native/boost/boost/config/compiler/intel.hpp +577 -0
- package/react-native/boost/boost/config/compiler/kai.hpp +33 -0
- package/react-native/boost/boost/config/compiler/metrowerks.hpp +198 -0
- package/react-native/boost/boost/config/compiler/mpw.hpp +140 -0
- package/react-native/boost/boost/config/compiler/nvcc.hpp +61 -0
- package/react-native/boost/boost/config/compiler/pathscale.hpp +138 -0
- package/react-native/boost/boost/config/compiler/pgi.hpp +23 -0
- package/react-native/boost/boost/config/compiler/sgi_mipspro.hpp +29 -0
- package/react-native/boost/boost/config/compiler/sunpro_cc.hpp +222 -0
- package/react-native/boost/boost/config/compiler/vacpp.hpp +186 -0
- package/react-native/boost/boost/config/compiler/visualc.hpp +391 -0
- package/react-native/boost/boost/config/compiler/xlcpp.hpp +299 -0
- package/react-native/boost/boost/config/compiler/xlcpp_zos.hpp +173 -0
- package/react-native/boost/boost/config/detail/cxx_composite.hpp +203 -0
- package/react-native/boost/boost/config/detail/posix_features.hpp +95 -0
- package/react-native/boost/boost/config/detail/select_compiler_config.hpp +157 -0
- package/react-native/boost/boost/config/detail/select_platform_config.hpp +147 -0
- package/react-native/boost/boost/config/detail/select_stdlib_config.hpp +121 -0
- package/react-native/boost/boost/config/detail/suffix.hpp +1294 -0
- package/react-native/boost/boost/config/header_deprecated.hpp +26 -0
- package/react-native/boost/boost/config/helper_macros.hpp +37 -0
- package/react-native/boost/boost/config/no_tr1/cmath.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/complex.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/functional.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/memory.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/utility.hpp +28 -0
- package/react-native/boost/boost/config/platform/aix.hpp +33 -0
- package/react-native/boost/boost/config/platform/amigaos.hpp +15 -0
- package/react-native/boost/boost/config/platform/beos.hpp +26 -0
- package/react-native/boost/boost/config/platform/bsd.hpp +83 -0
- package/react-native/boost/boost/config/platform/cloudabi.hpp +18 -0
- package/react-native/boost/boost/config/platform/cray.hpp +18 -0
- package/react-native/boost/boost/config/platform/cygwin.hpp +71 -0
- package/react-native/boost/boost/config/platform/haiku.hpp +31 -0
- package/react-native/boost/boost/config/platform/hpux.hpp +87 -0
- package/react-native/boost/boost/config/platform/irix.hpp +31 -0
- package/react-native/boost/boost/config/platform/linux.hpp +106 -0
- package/react-native/boost/boost/config/platform/macos.hpp +87 -0
- package/react-native/boost/boost/config/platform/qnxnto.hpp +31 -0
- package/react-native/boost/boost/config/platform/solaris.hpp +31 -0
- package/react-native/boost/boost/config/platform/symbian.hpp +97 -0
- package/react-native/boost/boost/config/platform/vms.hpp +25 -0
- package/react-native/boost/boost/config/platform/vxworks.hpp +422 -0
- package/react-native/boost/boost/config/platform/wasm.hpp +23 -0
- package/react-native/boost/boost/config/platform/win32.hpp +90 -0
- package/react-native/boost/boost/config/platform/zos.hpp +32 -0
- package/react-native/boost/boost/config/pragma_message.hpp +31 -0
- package/react-native/boost/boost/config/requires_threads.hpp +92 -0
- package/react-native/boost/boost/config/stdlib/dinkumware.hpp +324 -0
- package/react-native/boost/boost/config/stdlib/libcomo.hpp +93 -0
- package/react-native/boost/boost/config/stdlib/libcpp.hpp +180 -0
- package/react-native/boost/boost/config/stdlib/libstdcpp3.hpp +482 -0
- package/react-native/boost/boost/config/stdlib/modena.hpp +79 -0
- package/react-native/boost/boost/config/stdlib/msl.hpp +98 -0
- package/react-native/boost/boost/config/stdlib/roguewave.hpp +208 -0
- package/react-native/boost/boost/config/stdlib/sgi.hpp +168 -0
- package/react-native/boost/boost/config/stdlib/stlport.hpp +258 -0
- package/react-native/boost/boost/config/stdlib/vacpp.hpp +74 -0
- package/react-native/boost/boost/config/stdlib/xlcpp_zos.hpp +61 -0
- package/react-native/boost/boost/config/user.hpp +133 -0
- package/react-native/boost/boost/config/warning_disable.hpp +47 -0
- package/react-native/boost/boost/config/workaround.hpp +305 -0
- package/react-native/boost/boost/config.hpp +67 -0
- package/react-native/boost/boost/cstdint.hpp +556 -0
- package/react-native/boost/boost/intrusive_ptr.hpp +18 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count.hpp +103 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc.hpp +79 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc_atomic.hpp +63 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc_x86.hpp +88 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_nt.hpp +66 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_pt.hpp +104 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_spin.hpp +69 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_std_atomic.hpp +67 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_sync.hpp +72 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_win32.hpp +70 -0
- package/react-native/boost/boost/smart_ptr/detail/local_counted_base.hpp +148 -0
- package/react-native/boost/boost/smart_ptr/detail/local_sp_deleter.hpp +91 -0
- package/react-native/boost/boost/smart_ptr/detail/operator_bool.hpp +64 -0
- package/react-native/boost/boost/smart_ptr/detail/requires_cxx11.hpp +23 -0
- package/react-native/boost/boost/smart_ptr/detail/shared_count.hpp +707 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_convertible.hpp +92 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base.hpp +92 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp +163 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_aix.hpp +152 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_cw_ppc.hpp +185 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp +148 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_ia64.hpp +170 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_mips.hpp +200 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_ppc.hpp +194 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_sparc.hpp +179 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp +186 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_nt.hpp +119 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_pt.hpp +147 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp +174 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_spin.hpp +141 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_std_atomic.hpp +147 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_sync.hpp +165 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp +163 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_w32.hpp +140 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_impl.hpp +309 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_disable_deprecated.hpp +40 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_forward.hpp +52 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_has_gcc_intrinsics.hpp +27 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_has_sync_intrinsics.hpp +69 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_interlocked.hpp +173 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_noexcept.hpp +48 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_nullptr_t.hpp +45 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_obsolete.hpp +32 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_pause.hpp +51 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_sleep.hpp +104 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_yield.hpp +100 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_typeinfo_.hpp +58 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_win32_sleep.hpp +49 -0
- package/react-native/boost/boost/smart_ptr/intrusive_ptr.hpp +409 -0
- package/react-native/boost/boost/smart_ptr/intrusive_ref_counter.hpp +188 -0
- package/react-native/cpp/include/Attachment.h +16 -0
- package/react-native/cpp/include/Authentication.h +23 -0
- package/react-native/cpp/include/Collection.h +13 -0
- package/react-native/cpp/include/DQL.h +21 -0
- package/react-native/cpp/include/Document.h +17 -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 +26 -0
- package/react-native/cpp/include/Presence.h +14 -0
- package/react-native/cpp/include/RetainableState.h +24 -0
- package/react-native/cpp/include/SmallPeerInfo.h +17 -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 +61 -0
- package/react-native/cpp/include/main.h +10 -0
- package/react-native/cpp/src/Attachment.cpp +86 -0
- package/react-native/cpp/src/Authentication.cpp +224 -0
- package/react-native/cpp/src/Collection.cpp +54 -0
- package/react-native/cpp/src/DQL.cpp +254 -0
- package/react-native/cpp/src/Document.cpp +146 -0
- package/react-native/cpp/src/Identity.cpp +123 -0
- package/react-native/cpp/src/Lifecycle.cpp +75 -0
- package/react-native/cpp/src/LiveQuery.cpp +64 -0
- package/react-native/cpp/src/Logger.cpp +200 -0
- package/react-native/cpp/src/Misc.cpp +271 -0
- package/react-native/cpp/src/Presence.cpp +77 -0
- package/react-native/cpp/src/RetainableState.cpp +15 -0
- package/react-native/cpp/src/SmallPeerInfo.cpp +108 -0
- package/react-native/cpp/src/Transports.cpp +270 -0
- package/react-native/cpp/src/TypedArray.cpp +303 -0
- package/react-native/cpp/src/Utils.cpp +138 -0
- package/react-native/cpp/src/main.cpp +149 -0
- package/react-native/dittoffi/dittoffi.h +4698 -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 +107 -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 +14 -0
- package/react-native/lib/commonjs/index.js.map +1 -0
- package/react-native/lib/module/ditto.rn.js +83 -0
- package/react-native/lib/module/ditto.rn.js.map +1 -0
- package/react-native/lib/module/index.js +13 -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/scripts/ruby/include_local_boost.rb +78 -0
- package/react-native/src/ditto.rn.ts +91 -0
- package/react-native/src/environment/environment.fallback.ts +4 -0
- package/react-native/src/index.ts +26 -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 +2 -0
- package/react-native/src/sources/attachment-fetch-event.ts +54 -0
- package/react-native/src/sources/attachment-fetcher-manager.ts +129 -0
- package/react-native/src/sources/attachment-fetcher.ts +124 -0
- package/react-native/src/sources/attachment-token.ts +48 -0
- package/react-native/src/sources/attachment.ts +59 -0
- package/react-native/src/sources/augment.ts +89 -0
- package/react-native/src/sources/authenticator.ts +314 -0
- package/react-native/src/sources/base-pending-cursor-operation.ts +237 -0
- package/react-native/src/sources/base-pending-id-specific-operation.ts +109 -0
- package/react-native/src/sources/bridge.ts +549 -0
- package/react-native/src/sources/build-time-constants.ts +4 -0
- package/react-native/src/sources/cbor.ts +35 -0
- package/react-native/src/sources/collection-interface.ts +67 -0
- package/react-native/src/sources/collection.ts +212 -0
- package/react-native/src/sources/collections-event.ts +99 -0
- package/react-native/src/sources/counter.ts +77 -0
- package/react-native/src/sources/ditto.ts +945 -0
- package/react-native/src/sources/document-id.ts +159 -0
- package/react-native/src/sources/document-path.ts +303 -0
- package/react-native/src/sources/document.ts +192 -0
- package/react-native/src/sources/epilogue.ts +24 -0
- package/react-native/src/sources/error-codes.ts +52 -0
- package/react-native/src/sources/error.ts +203 -0
- package/react-native/src/sources/essentials.ts +53 -0
- package/react-native/src/sources/ffi-error.ts +117 -0
- package/react-native/src/sources/ffi.ts +1972 -0
- package/react-native/src/sources/identity.ts +163 -0
- package/react-native/src/sources/init.ts +70 -0
- package/react-native/src/sources/internal.ts +113 -0
- package/react-native/src/sources/keep-alive.ts +69 -0
- package/react-native/src/sources/key-path.ts +195 -0
- package/react-native/src/sources/live-query-event.ts +208 -0
- package/react-native/src/sources/live-query-manager.ts +101 -0
- package/react-native/src/sources/live-query.ts +164 -0
- package/react-native/src/sources/logger.ts +196 -0
- package/react-native/src/sources/observer-manager.ts +175 -0
- package/react-native/src/sources/observer.ts +77 -0
- package/react-native/src/sources/pending-collections-operation.ts +232 -0
- package/react-native/src/sources/pending-cursor-operation.ts +218 -0
- package/react-native/src/sources/pending-id-specific-operation.ts +216 -0
- package/react-native/src/sources/presence-manager.ts +160 -0
- package/react-native/src/sources/presence.ts +238 -0
- package/react-native/src/sources/query-result-item.ts +116 -0
- package/react-native/src/sources/query-result.ts +55 -0
- package/react-native/src/sources/register.ts +92 -0
- package/react-native/src/sources/small-peer-info.ts +176 -0
- package/react-native/src/sources/static-tcp-client.ts +6 -0
- package/react-native/src/sources/store-observer.ts +176 -0
- package/react-native/src/sources/store.ts +365 -0
- package/react-native/src/sources/subscription-manager.ts +98 -0
- package/react-native/src/sources/subscription.ts +88 -0
- package/react-native/src/sources/sync-subscription.ts +90 -0
- package/react-native/src/sources/sync.ts +495 -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 +428 -0
- package/react-native/src/sources/update-result.ts +66 -0
- package/react-native/src/sources/update-results-map.ts +57 -0
- package/react-native/src/sources/websocket-client.ts +6 -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 +72 -0
- package/react-native/src/sources/write-transaction.ts +119 -0
- package/react-native.config.js +9 -0
- package/types/ditto.d.ts +1230 -798
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as FFI from './ffi'
|
|
6
|
+
import * as Environment from './@environment'
|
|
7
|
+
|
|
8
|
+
import { Bridge } from './bridge'
|
|
9
|
+
import { CBOR, documentIDReplacer } from './cbor'
|
|
10
|
+
import { defaultDittoCloudURL } from './internal'
|
|
11
|
+
import { SyncSubscription } from './sync-subscription'
|
|
12
|
+
import { TransportConfig } from './transport-config'
|
|
13
|
+
import { DittoError, mapFFIErrors } from './error'
|
|
14
|
+
|
|
15
|
+
import type { Ditto } from './ditto'
|
|
16
|
+
import type { Identity } from './identity'
|
|
17
|
+
import type { DQLQueryArguments } from './essentials'
|
|
18
|
+
|
|
19
|
+
/** @internal */
|
|
20
|
+
export type SyncParameters = {
|
|
21
|
+
readonly isSyncActive: boolean
|
|
22
|
+
readonly isX509Valid: boolean
|
|
23
|
+
readonly isWebValid: boolean
|
|
24
|
+
readonly ditto: Ditto
|
|
25
|
+
readonly identity: Identity
|
|
26
|
+
readonly transportConfig: TransportConfig
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
export type SyncState = {
|
|
31
|
+
readonly underlyingSyncParameters: SyncParameters
|
|
32
|
+
readonly effectiveTransportConfig: TransportConfig
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Provides access to sync related functionality of Ditto.
|
|
37
|
+
*
|
|
38
|
+
* Access this object via {@link Ditto.sync | Ditto.sync} on any Ditto instance.
|
|
39
|
+
*/
|
|
40
|
+
export class Sync {
|
|
41
|
+
/**
|
|
42
|
+
* The {@link Ditto} instance managed by this sync object.
|
|
43
|
+
*/
|
|
44
|
+
readonly ditto: Ditto
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* All currently active sync subscriptions.
|
|
48
|
+
*
|
|
49
|
+
* **Note:** Manage sync subscriptions using
|
|
50
|
+
* {@link registerSubscription | registerSubscription()} to register a new
|
|
51
|
+
* sync subscription and
|
|
52
|
+
* {@link SyncSubscription.cancel | SyncSubscription.cancel()} to remove an
|
|
53
|
+
* existing sync subscription.
|
|
54
|
+
*/
|
|
55
|
+
readonly subscriptions: Readonly<Array<SyncSubscription>> = Object.freeze([])
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Installs and returns a sync subscription for a query, configuring Ditto to
|
|
59
|
+
* receive updates from other peers for documents matching that query. The
|
|
60
|
+
* passed in query must be a `SELECT` query, otherwise an error is thrown.
|
|
61
|
+
*
|
|
62
|
+
* @param query a string containing a valid query expressed in DQL.
|
|
63
|
+
* @param queryArguments an object containing the arguments for the query.
|
|
64
|
+
* Example: `{mileage: 123}` for a query with `:mileage` placeholder.
|
|
65
|
+
* @returns An active `SyncSubscription` for the passed in query and
|
|
66
|
+
* arguments. It will remain active until it is
|
|
67
|
+
* {@link SyncSubscription.cancel | cancelled} or the {@link Ditto} instance
|
|
68
|
+
* managing the sync subscription has been closed.
|
|
69
|
+
* @throws {@link DittoError} `query/invalid`: if `query` argument is not a
|
|
70
|
+
* string or not valid DQL.
|
|
71
|
+
* @throws {@link DittoError} `query/arguments-invalid`: if `queryArguments`
|
|
72
|
+
* argument is invalid (e.g. contains unsupported types).
|
|
73
|
+
* @throws {@link DittoError} `query/unsupported`: if the query is not a
|
|
74
|
+
* `SELECT` query.
|
|
75
|
+
* @throws {@link DittoError} may throw other errors.
|
|
76
|
+
*/
|
|
77
|
+
registerSubscription(query: string, queryArguments?: DQLQueryArguments): SyncSubscription {
|
|
78
|
+
if (typeof query !== 'string') {
|
|
79
|
+
throw new DittoError('query/invalid', `Expected parameter 'query' to be of type 'string', found: ${typeof query}`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let queryArgumentsCBOR: Uint8Array | null = null
|
|
83
|
+
if (queryArguments != null) {
|
|
84
|
+
try {
|
|
85
|
+
queryArgumentsCBOR = CBOR.encode(queryArguments, documentIDReplacer)
|
|
86
|
+
} catch (error: any) {
|
|
87
|
+
throw new DittoError('query/arguments-invalid', `Unable to encode query arguments: ${error.message}`)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const errorContext = { query, queryArguments }
|
|
92
|
+
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
93
|
+
this.ditto.deferClose(() => {
|
|
94
|
+
mapFFIErrors(() => FFI.tryExperimentalAddDQLSubscription(dittoHandle.deref(), query, queryArgumentsCBOR), undefined, errorContext)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const subscription = new SyncSubscription(this.ditto, query, queryArguments || null, queryArgumentsCBOR)
|
|
98
|
+
|
|
99
|
+
// @ts-expect-error modifying readonly property
|
|
100
|
+
this.subscriptions = Object.freeze([...this.subscriptions, subscription])
|
|
101
|
+
|
|
102
|
+
return subscription
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ---------------------------------------------------------- Internal ------
|
|
106
|
+
|
|
107
|
+
/** @internal */
|
|
108
|
+
get parameters(): SyncParameters {
|
|
109
|
+
return this._parameters
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** @internal */
|
|
113
|
+
constructor(ditto: Ditto) {
|
|
114
|
+
const identity = ditto.identity
|
|
115
|
+
const transportConfig = new TransportConfig()
|
|
116
|
+
const parameters = { identity, transportConfig, ditto, isWebValid: false, isX509Valid: false, isSyncActive: false }
|
|
117
|
+
|
|
118
|
+
this.ditto = ditto
|
|
119
|
+
this._parameters = parameters
|
|
120
|
+
this.state = stateFrom(parameters)
|
|
121
|
+
|
|
122
|
+
FFI.transportsInit()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Removes the passed in `syncSubscription`, configuring Ditto to not receive
|
|
127
|
+
* updates for documents matching the corresponding query anymore. No-op if
|
|
128
|
+
* the passed in `syncSubscription` has already been removed.
|
|
129
|
+
*
|
|
130
|
+
* This must only be called by the sync subscription itself.
|
|
131
|
+
*
|
|
132
|
+
* @param syncSubscription the sync subscription to remove
|
|
133
|
+
* @returns `true` if the passed in sync subscription could be found and has
|
|
134
|
+
* been removed, otherwise returns `false`.
|
|
135
|
+
* @throws {@link DittoError} `internal`: if the replication subscription does not
|
|
136
|
+
* belong to this store
|
|
137
|
+
* @throws {@link DittoError} `internal`: if the replication subscription has not
|
|
138
|
+
* been cancelled yet
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
unregisterSubscription(syncSubscription: SyncSubscription): boolean {
|
|
142
|
+
if (syncSubscription.ditto !== this.ditto) {
|
|
143
|
+
throw new DittoError('internal', `Can't remove replication subscription that does not belong to this store`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!syncSubscription.isCancelled) {
|
|
147
|
+
throw new DittoError('internal', "Internal inconsistency, can't remove replication subscription that has not been cancelled")
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const indexToDelete = this.subscriptions.findIndex((s) => s === syncSubscription)
|
|
151
|
+
if (indexToDelete === -1) {
|
|
152
|
+
return false
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const newSyncSubscriptions = [...this.subscriptions]
|
|
156
|
+
newSyncSubscriptions.splice(indexToDelete, 1)
|
|
157
|
+
this.subscriptions = Object.freeze(newSyncSubscriptions)
|
|
158
|
+
|
|
159
|
+
const dittoHandle = Bridge.ditto.handleFor(this.ditto)
|
|
160
|
+
this.ditto.deferClose(() => {
|
|
161
|
+
// prettier-ignor
|
|
162
|
+
mapFFIErrors(
|
|
163
|
+
() => FFI.tryExperimentalRemoveDQLSubscription(dittoHandle.deref(), syncSubscription.queryString, syncSubscription.queryArgumentsCBOR)
|
|
164
|
+
)
|
|
165
|
+
})
|
|
166
|
+
return true
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @internal */
|
|
170
|
+
update(parameters: SyncParameters) {
|
|
171
|
+
this._parameters = { ...parameters }
|
|
172
|
+
|
|
173
|
+
const stateOld = this.state
|
|
174
|
+
const stateNew = stateFrom(this.parameters)
|
|
175
|
+
this.updatePeerToPeerBluetoothLE(stateOld, stateNew)
|
|
176
|
+
this.updatePeerToPeerAWDL(stateOld, stateNew)
|
|
177
|
+
this.updatePeerToPeerLAN(stateOld, stateNew)
|
|
178
|
+
this.updateListenTCP(stateOld, stateNew)
|
|
179
|
+
this.updateListenHTTP(stateOld, stateNew)
|
|
180
|
+
this.updateConnectTCPServers(stateOld, stateNew)
|
|
181
|
+
this.updateConnectWebsocketURLs(stateOld, stateNew)
|
|
182
|
+
this.updateGlobal(stateOld, stateNew)
|
|
183
|
+
this.updateConnectRetryInterval(stateOld, stateNew)
|
|
184
|
+
this.state = stateNew
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** @internal */
|
|
188
|
+
close() {
|
|
189
|
+
if (this.parameters.isSyncActive) {
|
|
190
|
+
throw new Error(`Internal inconsistency, can't close sync object while sync is active, please 'stopSync()' first.`)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
for (const subscription of this.subscriptions) {
|
|
194
|
+
subscription.cancel()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ------------------------------------------------------------ Private ------
|
|
201
|
+
|
|
202
|
+
private state: SyncState
|
|
203
|
+
|
|
204
|
+
private _parameters: SyncParameters
|
|
205
|
+
|
|
206
|
+
private bluetoothLETransportPointer: FFI.Pointer<'DittoTransportsBLE_t'> | null = null
|
|
207
|
+
private awdlTransportPointer: FFI.Pointer<'DittoTransportsAWDL_t'> | null = null
|
|
208
|
+
private lanTransportPointer: FFI.Pointer<'DittoTransportsLAN_t'> | null = null
|
|
209
|
+
private mdnsClientTransportPointer: FFI.Pointer<'DittoTransportsMdnsClient_t'> | null = null
|
|
210
|
+
private mdnsServerAdvertiserPointer: FFI.Pointer<'DittoTransportsMdnsServer_t'> | null = null
|
|
211
|
+
|
|
212
|
+
private updatePeerToPeerBluetoothLE(stateOld: SyncState, stateNew: SyncState) {
|
|
213
|
+
if (!Environment.isNodeBuild && !Environment.isReactNativeBuild) return
|
|
214
|
+
|
|
215
|
+
const ditto = this.ditto
|
|
216
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
217
|
+
ditto.deferClose(() => {
|
|
218
|
+
const bluetoothLEOld = stateOld.effectiveTransportConfig.peerToPeer.bluetoothLE
|
|
219
|
+
const bluetoothLENew = stateNew.effectiveTransportConfig.peerToPeer.bluetoothLE
|
|
220
|
+
|
|
221
|
+
const shouldStart = !bluetoothLEOld.isEnabled && bluetoothLENew.isEnabled
|
|
222
|
+
const shouldStop = bluetoothLEOld.isEnabled && !bluetoothLENew.isEnabled
|
|
223
|
+
|
|
224
|
+
if (shouldStart && this.bluetoothLETransportPointer) throw new Error(`Internal inconsistency, when starting BLE transport, no BLE transport pointer should exist.`)
|
|
225
|
+
if (shouldStop && !this.bluetoothLETransportPointer) throw new Error(`Internal inconsistency, when stopping BLE transport, a BLE transport pointer should exist.`)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
if (process.platform === 'linux' || process.platform === 'win32') {
|
|
229
|
+
if (shouldStart) {
|
|
230
|
+
const clientTransport = FFI.dittoAddInternalBLEClientTransport(dittoHandle.deref())
|
|
231
|
+
const serverTransport = FFI.dittoAddInternalBLEServerTransport(dittoHandle.deref())
|
|
232
|
+
const blePlatform = { clientTransport, serverTransport } as any
|
|
233
|
+
this.bluetoothLETransportPointer = blePlatform
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (shouldStop) {
|
|
237
|
+
const blePlatform = this.bluetoothLETransportPointer as any
|
|
238
|
+
const { clientTransport, serverTransport } = blePlatform
|
|
239
|
+
FFI.bleServerFreeHandle(serverTransport)
|
|
240
|
+
FFI.bleClientFreeHandle(clientTransport)
|
|
241
|
+
this.bluetoothLETransportPointer = null
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (shouldStart) {
|
|
248
|
+
this.bluetoothLETransportPointer = FFI.transportsBLECreate(dittoHandle.deref()) as FFI.Pointer<FFI.TransportBluetooth> | null
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (shouldStop) {
|
|
252
|
+
FFI.transportsBLEDestroy(this.bluetoothLETransportPointer as FFI.Pointer<FFI.TransportBluetooth>)
|
|
253
|
+
this.bluetoothLETransportPointer = null
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private updatePeerToPeerAWDL(stateOld: SyncState, stateNew: SyncState) {
|
|
259
|
+
if (!Environment.isNodeBuild && !Environment.isReactNativeBuild) return
|
|
260
|
+
|
|
261
|
+
const ditto = this.ditto
|
|
262
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
263
|
+
ditto.deferClose(() => {
|
|
264
|
+
const awdlOld = stateOld.effectiveTransportConfig.peerToPeer.awdl
|
|
265
|
+
const awdlNew = stateNew.effectiveTransportConfig.peerToPeer.awdl
|
|
266
|
+
|
|
267
|
+
const shouldStart = !awdlOld.isEnabled && awdlNew.isEnabled
|
|
268
|
+
const shouldStop = awdlOld.isEnabled && !awdlNew.isEnabled
|
|
269
|
+
|
|
270
|
+
if (shouldStart && this.awdlTransportPointer) throw new Error(`Internal inconsistency, when starting AWDL transport, no AWDL transport pointer should exist.`)
|
|
271
|
+
if (shouldStop && !this.awdlTransportPointer) throw new Error(`Internal inconsistency, when stopping AWDL transport, an AWDL transport pointer should exist.`)
|
|
272
|
+
|
|
273
|
+
if (shouldStart) {
|
|
274
|
+
this.awdlTransportPointer = FFI.transportsAWDLCreate(dittoHandle.deref()) as FFI.Pointer<FFI.TransportAWDL> | null
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (shouldStop) {
|
|
278
|
+
FFI.transportsAWDLDestroy(this.awdlTransportPointer as FFI.Pointer<FFI.TransportAWDL>)
|
|
279
|
+
this.awdlTransportPointer = null
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private updatePeerToPeerLAN(stateOld: SyncState, stateNew: SyncState) {
|
|
285
|
+
if (!Environment.isNodeBuild && !Environment.isReactNativeBuild) return
|
|
286
|
+
|
|
287
|
+
const ditto = this.ditto
|
|
288
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
289
|
+
ditto.deferClose(() => {
|
|
290
|
+
const lanOld = stateOld.effectiveTransportConfig.peerToPeer.lan
|
|
291
|
+
const lanNew = stateNew.effectiveTransportConfig.peerToPeer.lan
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
if (process.platform === 'win32' || process.platform === 'linux') {
|
|
295
|
+
if (lanOld.isEnabled) {
|
|
296
|
+
if (lanOld.isMdnsEnabled) {
|
|
297
|
+
if (this.mdnsClientTransportPointer == null) throw new Error(`Internal inconsistency, when stopping LAN transport, a LAN transport pointer should exist.`)
|
|
298
|
+
FFI.mdnsClientFreeHandle(this.mdnsClientTransportPointer)
|
|
299
|
+
this.mdnsClientTransportPointer = null
|
|
300
|
+
|
|
301
|
+
if (this.mdnsServerAdvertiserPointer == null) throw new Error(`Internal inconsistency, when stopping LAN transport, a LAN transport pointer should exist.`)
|
|
302
|
+
FFI.mdnsServerFreeHandle(this.mdnsServerAdvertiserPointer)
|
|
303
|
+
this.mdnsServerAdvertiserPointer = null
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (lanOld.isMulticastEnabled) {
|
|
307
|
+
FFI.dittoRemoveMulticastTransport(dittoHandle.deref())
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (lanNew.isEnabled) {
|
|
312
|
+
if (lanNew.isMdnsEnabled) {
|
|
313
|
+
this.mdnsClientTransportPointer = FFI.dittoAddInternalMdnsTransport(dittoHandle.deref())
|
|
314
|
+
this.mdnsServerAdvertiserPointer = FFI.dittoAddInternalMdnsAdvertiser(dittoHandle.deref())
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (lanNew.isMulticastEnabled) {
|
|
318
|
+
FFI.dittoAddMulticastTransport(dittoHandle.deref())
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
if (lanOld.isEnabled) {
|
|
327
|
+
if (lanOld.isMdnsEnabled) {
|
|
328
|
+
if (this.lanTransportPointer == null) throw new Error(`Internal inconsistency, when stopping LAN transport, a LAN transport pointer should exist.`)
|
|
329
|
+
FFI.transportsLANDestroy(this.lanTransportPointer as FFI.Pointer<FFI.TransportLAN>)
|
|
330
|
+
this.lanTransportPointer = null
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (lanOld.isMulticastEnabled) {
|
|
334
|
+
FFI.dittoRemoveMulticastTransport(dittoHandle.deref())
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (lanNew.isEnabled) {
|
|
339
|
+
if (lanNew.isMdnsEnabled) {
|
|
340
|
+
if (this.lanTransportPointer != null) throw new Error(`Internal inconsistency, when starting LAN transport, no LAN transport pointer should exist.`)
|
|
341
|
+
this.lanTransportPointer = FFI.transportsLANCreate(dittoHandle.deref()) as FFI.Pointer<FFI.TransportLAN>
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (lanNew.isMulticastEnabled) {
|
|
345
|
+
FFI.dittoAddMulticastTransport(dittoHandle.deref())
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
private updateListenTCP(stateOld: SyncState, stateNew: SyncState) {
|
|
352
|
+
const ditto = this.ditto
|
|
353
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
354
|
+
ditto.deferClose(() => {
|
|
355
|
+
const tcpOld = stateOld.effectiveTransportConfig.listen.tcp
|
|
356
|
+
const tcpNew = stateNew.effectiveTransportConfig.listen.tcp
|
|
357
|
+
|
|
358
|
+
if (TransportConfig.areListenTCPsEqual(tcpNew, tcpOld)) return
|
|
359
|
+
|
|
360
|
+
if (tcpOld.isEnabled) FFI.dittoStopTCPServer(dittoHandle.deref())
|
|
361
|
+
if (tcpNew.isEnabled) FFI.dittoStartTCPServer(dittoHandle.deref(), `${tcpNew.interfaceIP}:${tcpNew.port}`)
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
private updateListenHTTP(stateOld: SyncState, stateNew: SyncState) {
|
|
366
|
+
const ditto = this.ditto
|
|
367
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
368
|
+
ditto.deferClose(() => {
|
|
369
|
+
const httpOld = stateOld.effectiveTransportConfig.listen.http
|
|
370
|
+
const httpNew = stateNew.effectiveTransportConfig.listen.http
|
|
371
|
+
|
|
372
|
+
if (TransportConfig.areListenHTTPsEqual(httpOld, httpNew)) return
|
|
373
|
+
if (httpOld.isEnabled) FFI.dittoStopHTTPServer(dittoHandle.deref())
|
|
374
|
+
|
|
375
|
+
/* eslint-disable */
|
|
376
|
+
if (httpNew.isEnabled) {
|
|
377
|
+
FFI.dittoStartHTTPServer(dittoHandle.deref(), `${httpNew.interfaceIP}:${httpNew.port}`, httpNew.staticContentPath || null, httpNew.websocketSync ? 'Enabled' : 'Disabled', httpNew.tlsCertificatePath || null, httpNew.tlsKeyPath || null)
|
|
378
|
+
}
|
|
379
|
+
/* eslint-enable */
|
|
380
|
+
})
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
private updateConnectTCPServers(stateOld: SyncState, stateNew: SyncState) {
|
|
384
|
+
const ditto = this.ditto
|
|
385
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
386
|
+
ditto.deferClose(() => {
|
|
387
|
+
const tcpServers = stateNew.effectiveTransportConfig.connect.tcpServers
|
|
388
|
+
FFI.dittoSetStaticTCPClients(dittoHandle.deref(), tcpServers)
|
|
389
|
+
})
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
private updateConnectWebsocketURLs(stateOld: SyncState, stateNew: SyncState) {
|
|
393
|
+
const ditto = this.ditto
|
|
394
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
395
|
+
ditto.deferClose(() => {
|
|
396
|
+
const websocketURLs = stateNew.effectiveTransportConfig.connect.websocketURLs
|
|
397
|
+
const routingHint = stateNew.effectiveTransportConfig.global.routingHint
|
|
398
|
+
FFI.dittoSetStaticWebsocketClients(dittoHandle.deref(), websocketURLs, routingHint)
|
|
399
|
+
})
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private updateGlobal(stateOld: SyncState, stateNew: SyncState) {
|
|
403
|
+
const ditto = this.ditto
|
|
404
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
405
|
+
ditto.deferClose(() => {
|
|
406
|
+
if (stateOld.effectiveTransportConfig.global.syncGroup !== stateNew.effectiveTransportConfig.global.syncGroup) {
|
|
407
|
+
FFI.dittoSetSyncGroup(dittoHandle.deref(), stateNew.effectiveTransportConfig.global.syncGroup)
|
|
408
|
+
}
|
|
409
|
+
})
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private updateConnectRetryInterval(stateOld: SyncState, stateNew: SyncState) {
|
|
413
|
+
const ditto = this.ditto
|
|
414
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
415
|
+
ditto.deferClose(() => {
|
|
416
|
+
FFI.dittoSetConnectRetryInterval(dittoHandle.deref(), stateNew.effectiveTransportConfig.connect.retryInterval)
|
|
417
|
+
})
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* @private
|
|
423
|
+
*/
|
|
424
|
+
function stateFrom(parameters: SyncParameters): SyncState {
|
|
425
|
+
const ditto = parameters.ditto
|
|
426
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
427
|
+
return ditto.deferClose(() => {
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
const transportConfig = parameters.transportConfig.copy()
|
|
431
|
+
const identity = parameters.identity
|
|
432
|
+
|
|
433
|
+
const isSyncActive = parameters.isSyncActive
|
|
434
|
+
const isX509Valid = parameters.isX509Valid
|
|
435
|
+
const isWebValid = parameters.isWebValid
|
|
436
|
+
|
|
437
|
+
let appID
|
|
438
|
+
let customDittoCloudURL
|
|
439
|
+
let isDittoCloudSyncEnabled = false
|
|
440
|
+
|
|
441
|
+
if (identity.type === 'onlinePlayground' || identity.type === 'onlineWithAuthentication') {
|
|
442
|
+
appID = identity.appID
|
|
443
|
+
customDittoCloudURL = identity.customDittoCloudURL ?? null
|
|
444
|
+
isDittoCloudSyncEnabled = identity.enableDittoCloudSync ?? true
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const unavailableButEnabledP2PTransports = []
|
|
448
|
+
|
|
449
|
+
const isBLEAvailable = FFI.transportsBLEIsAvailable(dittoHandle.deref())
|
|
450
|
+
const isAWDLAvailable = FFI.transportsAWDLIsAvailable(dittoHandle.deref())
|
|
451
|
+
const isLANAvailable = FFI.transportsLANIsAvailable(dittoHandle.deref())
|
|
452
|
+
|
|
453
|
+
if (transportConfig.peerToPeer.bluetoothLE.isEnabled && !isBLEAvailable) {
|
|
454
|
+
unavailableButEnabledP2PTransports.push('BluetoothLE')
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (transportConfig.peerToPeer.awdl.isEnabled && !isAWDLAvailable) {
|
|
458
|
+
unavailableButEnabledP2PTransports.push('AWDL')
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (transportConfig.peerToPeer.lan.isEnabled && !isLANAvailable) {
|
|
462
|
+
unavailableButEnabledP2PTransports.push('LAN')
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (unavailableButEnabledP2PTransports.length > 0) {
|
|
466
|
+
throw new Error(`The following P2P transports are enabled in the transport config but are not supported in the current environment: ${unavailableButEnabledP2PTransports.join(', ')}`)
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (!isSyncActive || !isX509Valid) {
|
|
470
|
+
transportConfig.peerToPeer.bluetoothLE.isEnabled = false
|
|
471
|
+
transportConfig.peerToPeer.awdl.isEnabled = false
|
|
472
|
+
transportConfig.peerToPeer.lan.isEnabled = false
|
|
473
|
+
transportConfig.listen.tcp.isEnabled = false
|
|
474
|
+
transportConfig.connect.tcpServers = []
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (!isSyncActive || !isWebValid) {
|
|
478
|
+
transportConfig.connect.websocketURLs = []
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (!isSyncActive) {
|
|
482
|
+
transportConfig.listen.http.isEnabled = false
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (isSyncActive && isWebValid && isDittoCloudSyncEnabled) {
|
|
486
|
+
const dittoCloudURL = customDittoCloudURL ?? defaultDittoCloudURL(appID)
|
|
487
|
+
transportConfig.connect.websocketURLs.push(dittoCloudURL)
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return {
|
|
491
|
+
underlyingSyncParameters: parameters,
|
|
492
|
+
effectiveTransportConfig: transportConfig.freeze(),
|
|
493
|
+
}
|
|
494
|
+
})
|
|
495
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Bridge } from './bridge'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get a count of bridged objects binned by bridge type.
|
|
5
|
+
*
|
|
6
|
+
* Use this in testing to ensure that all objects are properly garbage collected at the end of tests.
|
|
7
|
+
*
|
|
8
|
+
* @returns an object with a key per bridge type, set to the count of registered
|
|
9
|
+
* objects.
|
|
10
|
+
*/
|
|
11
|
+
export function getBridgeLoad(): { [bridgeName: string]: number } {
|
|
12
|
+
const countsByType: { [bridgeName: string]: number } = {}
|
|
13
|
+
Bridge.all.map((bridgeWeakRef) => {
|
|
14
|
+
const bridge = bridgeWeakRef.deref()
|
|
15
|
+
if (!bridge) {
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
if (bridge.count === 0) {
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
countsByType[bridge.type.name] = bridge.count
|
|
22
|
+
})
|
|
23
|
+
return countsByType
|
|
24
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2021 DittoLive Incorporated. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as FFI from './ffi'
|
|
6
|
+
|
|
7
|
+
import { Bridge } from './bridge'
|
|
8
|
+
import { ObserverManager } from './observer-manager'
|
|
9
|
+
|
|
10
|
+
import type { Ditto, TransportCondition, ConditionSource } from './ditto'
|
|
11
|
+
|
|
12
|
+
/** @internal */
|
|
13
|
+
export class TransportConditionsManager extends ObserverManager {
|
|
14
|
+
readonly ditto: Ditto
|
|
15
|
+
|
|
16
|
+
constructor(ditto: Ditto) {
|
|
17
|
+
const keepAlive = ditto.keepAlive
|
|
18
|
+
super('TransportConditionsObservation', { keepAlive })
|
|
19
|
+
this.ditto = ditto
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected register(callback: (...args: any[]) => void) {
|
|
23
|
+
const ditto = this.ditto
|
|
24
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
25
|
+
return ditto.deferClose(() => {
|
|
26
|
+
return FFI.dittoRegisterTransportConditionChangedCallback(dittoHandle.deref(), callback)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected unregister() {
|
|
31
|
+
const ditto = this.ditto
|
|
32
|
+
const dittoHandle = Bridge.ditto.handleFor(ditto)
|
|
33
|
+
return ditto.deferClose(() => {
|
|
34
|
+
return FFI.dittoRegisterTransportConditionChangedCallback(dittoHandle.deref(), null)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected process(conditionSource: FFI.ConditionSource, transportCondition: FFI.TransportCondition): [TransportCondition, ConditionSource] {
|
|
39
|
+
/* eslint-disable */
|
|
40
|
+
let apiConditionSource: ConditionSource
|
|
41
|
+
switch (conditionSource) {
|
|
42
|
+
case 'Bluetooth':
|
|
43
|
+
apiConditionSource = 'BLE'
|
|
44
|
+
break
|
|
45
|
+
case 'Tcp':
|
|
46
|
+
apiConditionSource = 'TCP'
|
|
47
|
+
break
|
|
48
|
+
case 'Awdl':
|
|
49
|
+
apiConditionSource = 'AWDL'
|
|
50
|
+
break
|
|
51
|
+
case 'Mdns':
|
|
52
|
+
apiConditionSource = 'MDNS'
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
/* eslint-enable */
|
|
56
|
+
|
|
57
|
+
/* eslint-disable */
|
|
58
|
+
let apiTransportCondition: TransportCondition
|
|
59
|
+
switch (transportCondition) {
|
|
60
|
+
case 'Unknown':
|
|
61
|
+
apiTransportCondition = 'Unknown'
|
|
62
|
+
break
|
|
63
|
+
case 'Ok':
|
|
64
|
+
apiTransportCondition = 'OK'
|
|
65
|
+
break
|
|
66
|
+
case 'GenericFailure':
|
|
67
|
+
apiTransportCondition = 'GenericFailure'
|
|
68
|
+
break
|
|
69
|
+
case 'AppInBackground':
|
|
70
|
+
apiTransportCondition = 'AppInBackground'
|
|
71
|
+
break
|
|
72
|
+
case 'MdnsFailure':
|
|
73
|
+
apiTransportCondition = 'MDNSFailure'
|
|
74
|
+
break
|
|
75
|
+
case 'TcpListenFailure':
|
|
76
|
+
apiTransportCondition = 'TCPListenFailure'
|
|
77
|
+
break
|
|
78
|
+
case 'NoBleCentralPermission':
|
|
79
|
+
apiTransportCondition = 'NoBLECentralPermission'
|
|
80
|
+
break
|
|
81
|
+
case 'NoBlePeripheralPermission':
|
|
82
|
+
apiTransportCondition = 'NoBLEPeripheralPermission'
|
|
83
|
+
break
|
|
84
|
+
case 'CannotEstablishConnection':
|
|
85
|
+
apiTransportCondition = 'CannotEstablishConnection'
|
|
86
|
+
break
|
|
87
|
+
case 'BleDisabled':
|
|
88
|
+
apiTransportCondition = 'BLEDisabled'
|
|
89
|
+
break
|
|
90
|
+
case 'NoBleHardware':
|
|
91
|
+
apiTransportCondition = 'NoBLEHardware'
|
|
92
|
+
break
|
|
93
|
+
case 'WifiDisabled':
|
|
94
|
+
apiTransportCondition = 'WiFiDisabled'
|
|
95
|
+
break
|
|
96
|
+
case 'TemporarilyUnavailable':
|
|
97
|
+
apiTransportCondition = 'TemporarilyUnavailable'
|
|
98
|
+
break
|
|
99
|
+
}
|
|
100
|
+
/* eslint-enable */
|
|
101
|
+
|
|
102
|
+
return [apiTransportCondition, apiConditionSource]
|
|
103
|
+
}
|
|
104
|
+
}
|