sparkling-method 2.0.0-rc.0 → 2.0.0-rc.1
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/README.md +39 -0
- package/android/build.gradle.kts +153 -0
- package/android/gradle.properties +1 -0
- package/android/proguard-rules.pro +21 -0
- package/android/src/androidTest/java/com/tiktok/sparkling/sparkling/methods/ExampleInstrumentedTest.kt +27 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/BridgeContext.kt +74 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/DefaultBridgeClientImp.kt +47 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/DefaultBridgeLifeClientImp.kt +233 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/InnerBridge.kt +134 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/entity/BridgeCall.kt +79 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/entity/BridgeResult.kt +68 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcher.kt +198 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManager.kt +16 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcher.kt +56 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/errors/JSBErrorReportModel.kt +144 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/interceptor/BridgeMockInterceptor.kt +30 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lifecycle/fe/FeCallMonitorModel.kt +66 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeDelegateModule.kt +31 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeProtol.kt +69 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxRuntimeBridgeDelegateModule.kt +31 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxViewImpl.kt +29 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/RealLynxBridgeDelegate.kt +147 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/BridgeSDKMonitor.kt +239 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/IBridgeMonitor.kt +17 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/MonitorEntity.kt +22 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeCallback.kt +14 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeClient.kt +19 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeHandler.kt +23 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeLifeClient.kt +45 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeMethodCallback.kt +10 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeProtocol.kt +22 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/BridgeConstants.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/BridgeConverter.kt +147 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/LogUtils.kt +37 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/MonitorUtils.kt +41 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BridgeLocalPool.kt +70 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BridgeSettings.kt +19 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BusinessCallHandler.kt +100 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/CancelCallbackConfig.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/DefaultCallHandler.kt +106 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/IBridgeMethod.kt +118 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/PiperDataExt.kt +71 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/SparklingBridge.kt +374 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/Utils.kt +89 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/interfaces/IBridgeNotFound.kt +11 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/LynxDataProcessorForMap.kt +204 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/LynxPlatformDataProcessor.kt +239 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/WebPlatformDataProcessor.kt +307 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/WebProcessorForMap.kt +227 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/BridgeMethodCallbackHelper.kt +29 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/BridgeProtocolConstants.kt +12 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/DataConvertUtils.kt +684 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/IConvertUtils.kt +44 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/LogHelper.kt +30 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/ThreadPool.kt +73 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/BridgeCollections.kt +194 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/BridgePlatformType.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IBridgeContext.kt +137 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLBridgeMethod.kt +100 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodProvider.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistry.kt +132 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryCache.kt +150 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryCacheManager.kt +34 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLProxyClient.kt +28 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IRegister.kt +21 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/LocalBridge.kt +70 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/ReadableMapImpl.kt +227 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/RegistryCache.kt +77 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/SparklingBridgeManager.kt +50 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodIntEnum.kt +15 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodName.kt +17 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodParamField.kt +42 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodParamModel.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodResultModel.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodStringEnum.kt +15 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/base/AbsSparklingIDLMethod.kt +276 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IDLMethodException.kt +10 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalInputParamException.kt +12 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalOperationException.kt +12 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalOutputParamException.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IContainerIDProvider.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/INameSpaceProvider.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IPlatformDataProcessor.kt +19 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IReleasable.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/context/BridgeCallThreadTypeConfig.kt +44 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/context/ContextProviderFactory.kt +133 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/CompletionBlock.kt +26 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLDynamic.kt +97 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseModel.kt +37 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseParamModel.kt +62 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseResultModel.kt +18 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/BridgeKTX.kt +37 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IAssignDir.kt +25 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodHelper.kt +44 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodResultModelArguments.kt +264 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodResultModelHelper.kt +194 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/JsonUtils.kt +200 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/BridgeBaseRuntime.kt +11 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/CommonDependsProvider.kt +14 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostNetworkDepend.kt +19 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostPermissionDepend.kt +34 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostThreadPoolExecutorDepend.kt +12 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/AbsStreamConnection.kt +36 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/AbsStringConnection.kt +30 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/HttpRequest.kt +134 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/NetworkRequestImpl.kt +28 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/RequestJsonFormatOptionConstants.kt +10 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/utils/BridgeAPIRequestUtils.kt +365 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/utils/HttpUrlBuilder.kt +97 -0
- package/android/src/main/res/drawable/ic_launcher_background.xml +170 -0
- package/android/src/main/res/drawable/ic_launcher_foreground.xml +30 -0
- package/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
- package/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/values/colors.xml +10 -0
- package/android/src/main/res/values/strings.xml +3 -0
- package/android/src/test/java/com/tiktok/sparkling/method/TestApplication.kt +19 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/BridgeContextTest.kt +89 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/DefaultBridgeClientImpTest.kt +78 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/DefaultBridgeLifeClientImpTest.kt +97 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/InnerBridgeTest.kt +105 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/entity/BridgeCallTest.kt +61 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/entity/BridgeResultTest.kt +74 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcherTest.kt +96 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManagerTest.kt +21 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcherTest.kt +34 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/errors/JSBErrorReportModelTest.kt +60 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/interceptor/BridgeMockInterceptorTest.kt +51 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lifecycle/fe/FeCallMonitorModelTest.kt +65 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeDelegateModuleTest.kt +57 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeProtocolTest.kt +10 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxRuntimeBridgeDelegateModuleTest.kt +37 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/RealLynxBridgeDelegateTest.kt +10 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/monitor/BridgeSDKMonitorTest.kt +10 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/monitor/MonitorEntityTest.kt +43 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/api/SparklingBridgeTest.kt +444 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/api/util/DataConvertUtilsTest.kt +236 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryTest.kt +331 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/LocalBridgeTest.kt +299 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/SparklingBridgeManagerTest.kt +213 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/base/AbsSparklingIDLMethodTest.kt +307 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/exception/IDLMethodExceptionTest.kt +311 -0
- package/android/src/test/java/com/tiktok/sparkling/method/runtime/depend/BridgeBaseRuntimeTest.kt +54 -0
- package/android/src/test/resources/robolectric.properties +5 -0
- package/dist/index.d.ts +55 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +181 -52
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/typing.d.ts +44 -0
- package/ios/Sources/Core/DI/DIContainerProtocol.swift +27 -0
- package/ios/Sources/Core/DI/DIContainerProvider.swift +10 -0
- package/ios/Sources/Core/DI/DIProviderRegistry.swift +21 -0
- package/ios/Sources/Core/Definitions/CommonDefines.swift +17 -0
- package/ios/Sources/Core/Examples/SampleMethod+impl.swift +24 -0
- package/ios/Sources/Core/Examples/SampleMethod.swift +58 -0
- package/ios/Sources/Core/Models/MethodContext.swift +53 -0
- package/ios/Sources/Core/Models/MethodStatus.swift +146 -0
- package/ios/Sources/Core/Models/SPKAutoRegisteringMethod.swift +7 -0
- package/ios/Sources/Core/Pipe/MethodPipe+Internal.swift +90 -0
- package/ios/Sources/Core/Pipe/MethodPipe.swift +45 -0
- package/ios/Sources/Core/Pipe/MethodRegistry.swift +97 -0
- package/ios/Sources/Core/Protocols/DictionaryCodable.swift +10 -0
- package/ios/Sources/Core/Protocols/MethodModel.swift +143 -0
- package/ios/Sources/Core/Protocols/MethodPipeFacade.swift +16 -0
- package/ios/Sources/Core/Protocols/PipeContainer.swift +21 -0
- package/ios/Sources/Core/Protocols/PipeEngine.swift +10 -0
- package/ios/Sources/Core/Protocols/PipeMethod.swift +83 -0
- package/ios/Sources/Core/Protocols/PipeRuntime.swift +9 -0
- package/ios/Sources/Core/Utils/AnyCodableValue.swift +128 -0
- package/ios/Sources/Core/Utils/CoreUtils.swift +17 -0
- package/ios/Sources/Core/Utils/NSString+SPKBridgeAdditions.swift +35 -0
- package/ios/Sources/Core/Utils/ReadWriteLock.swift +33 -0
- package/ios/Sources/Core/Utils/SPKHttpResponseChromium.swift +24 -0
- package/ios/Sources/Core/Utils/SPKNetworkManager.swift +200 -0
- package/ios/Sources/Core/Utils/SPKReachability.swift +46 -0
- package/ios/Sources/DIProvider/DIContainer.swift +80 -0
- package/ios/Sources/DIProvider/DefaultDIContainerProvider.swift +21 -0
- package/ios/Sources/Debug/MethodPipe+Debug.swift +36 -0
- package/ios/Sources/Lynx/Definitions/LynxConstants.swift +19 -0
- package/ios/Sources/Lynx/Definitions/LynxPipeStatusCode.swift +26 -0
- package/ios/Sources/Lynx/Definitions/LynxTypealiases.swift +7 -0
- package/ios/Sources/Lynx/Engine/LynxConfig+SPKPipe.swift +31 -0
- package/ios/Sources/Lynx/Engine/LynxContext+SPKPipe.swift +21 -0
- package/ios/Sources/Lynx/Engine/LynxPipeEngine.swift +52 -0
- package/ios/Sources/Lynx/Engine/LynxPipeEnginePool.swift +41 -0
- package/ios/Sources/Lynx/Engine/LynxView+SPKPipe.swift +64 -0
- package/ios/Sources/Lynx/Engine/SPKLynxModuleService.swift +23 -0
- package/ios/Sources/Lynx/Models/LynxRecvMessage.swift +31 -0
- package/ios/Sources/Lynx/Models/LynxSendMessage.swift +55 -0
- package/ios/Sources/Lynx/Module/SPKLynxNativeModule.swift +41 -0
- package/ios/Sources/Lynx/Pipe/MethodPipe+Lynx.swift +53 -0
- package/ios/SparklingMethod.podspec +65 -0
- package/package.json +11 -29
- package/src/index.ts +240 -0
- package/src/types.ts +44 -0
- package/src/typing.d.ts +44 -0
- package/tsconfig.json +15 -0
- package/dist/codegen/definition-parser.d.ts +0 -5
- package/dist/codegen/definition-parser.d.ts.map +0 -1
- package/dist/codegen/definition-parser.js +0 -376
- package/dist/codegen/definition-parser.js.map +0 -1
- package/dist/codegen/index.d.ts +0 -3
- package/dist/codegen/index.d.ts.map +0 -1
- package/dist/codegen/index.js +0 -99
- package/dist/codegen/index.js.map +0 -1
- package/dist/codegen/kotlin.d.ts +0 -4
- package/dist/codegen/kotlin.d.ts.map +0 -1
- package/dist/codegen/kotlin.js +0 -273
- package/dist/codegen/kotlin.js.map +0 -1
- package/dist/codegen/metadata.d.ts +0 -4
- package/dist/codegen/metadata.d.ts.map +0 -1
- package/dist/codegen/metadata.js +0 -78
- package/dist/codegen/metadata.js.map +0 -1
- package/dist/codegen/swift.d.ts +0 -4
- package/dist/codegen/swift.d.ts.map +0 -1
- package/dist/codegen/swift.js +0 -145
- package/dist/codegen/swift.js.map +0 -1
- package/dist/codegen/template/android/kotlin-idl-template +0 -119
- package/dist/codegen/template/android/kotlin-impl-template +0 -0
- package/dist/codegen/template/ios/oc-idl-template +0 -0
- package/dist/codegen/template/ios/oc-impl-template +0 -0
- package/dist/codegen/template/ios/swift-idl-template +0 -83
- package/dist/codegen/template/ios/swift-impl-template +0 -0
- package/dist/codegen/template/ts/call-template +0 -0
- package/dist/codegen/template/ts/ts-idl-template +0 -66
- package/dist/codegen/template/ts/ts-impl-template +0 -78
- package/dist/codegen/template/ts/ts-index-template +0 -13
- package/dist/codegen/types.d.ts +0 -157
- package/dist/codegen/types.d.ts.map +0 -1
- package/dist/codegen/types.js +0 -3
- package/dist/codegen/types.js.map +0 -1
- package/dist/codegen/typescript.d.ts +0 -8
- package/dist/codegen/typescript.d.ts.map +0 -1
- package/dist/codegen/typescript.js +0 -232
- package/dist/codegen/typescript.js.map +0 -1
- package/dist/codegen/utils.d.ts +0 -10
- package/dist/codegen/utils.d.ts.map +0 -1
- package/dist/codegen/utils.js +0 -83
- package/dist/codegen/utils.js.map +0 -1
- package/dist/create/index.d.ts +0 -3
- package/dist/create/index.d.ts.map +0 -1
- package/dist/create/index.js +0 -44
- package/dist/create/index.js.map +0 -1
- package/dist/create/prompts.d.ts +0 -7
- package/dist/create/prompts.d.ts.map +0 -1
- package/dist/create/prompts.js +0 -61
- package/dist/create/prompts.js.map +0 -1
- package/dist/create/scaffold.d.ts +0 -9
- package/dist/create/scaffold.d.ts.map +0 -1
- package/dist/create/scaffold.js +0 -131
- package/dist/create/scaffold.js.map +0 -1
- package/dist/create/template/README.md +0 -17
- package/dist/create/template/android/.gitkeep +0 -1
- package/dist/create/template/ios/.gitkeep +0 -1
- package/dist/create/template/src/method.d.ts +0 -17
- package/dist/create/templates.d.ts +0 -5
- package/dist/create/templates.d.ts.map +0 -1
- package/dist/create/templates.js +0 -75
- package/dist/create/templates.js.map +0 -1
- package/dist/create/types.d.ts +0 -12
- package/dist/create/types.d.ts.map +0 -1
- package/dist/create/types.js +0 -3
- package/dist/create/types.js.map +0 -1
- package/dist/create/utils.d.ts +0 -3
- package/dist/create/utils.d.ts.map +0 -1
- package/dist/create/utils.js +0 -19
- package/dist/create/utils.js.map +0 -1
- package/dist/ui.d.ts +0 -13
- package/dist/ui.d.ts.map +0 -1
- package/dist/ui.js +0 -82
- package/dist/ui.js.map +0 -1
- package/dist/verbose.d.ts +0 -4
- package/dist/verbose.d.ts.map +0 -1
- package/dist/verbose.js +0 -25
- package/dist/verbose.js.map +0 -1
- package/templates/sparkling-app-template-android-groovy/android/sparkling-method-media/build.gradle +0 -44
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
package com.tiktok.sparkling.method.registry.api.util
|
|
5
|
+
|
|
6
|
+
import com.lynx.react.bridge.WritableArray
|
|
7
|
+
import com.lynx.react.bridge.WritableMap
|
|
8
|
+
import com.tiktok.sparkling.method.registry.core.XReadableArray
|
|
9
|
+
import com.tiktok.sparkling.method.registry.core.XReadableMap
|
|
10
|
+
import org.json.JSONArray
|
|
11
|
+
import org.json.JSONObject
|
|
12
|
+
|
|
13
|
+
interface IConvertUtils {
|
|
14
|
+
|
|
15
|
+
fun toStringOrJson(data: Any?): String
|
|
16
|
+
|
|
17
|
+
fun mapToJSON(map: Map<String, Any?>): JSONObject
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
fun mapSupportPiperdataToJSON(map: Map<String, Any?>): JSONObject
|
|
21
|
+
|
|
22
|
+
fun listSupportPiperdataToJSON(list: List<Any>): JSONArray
|
|
23
|
+
|
|
24
|
+
fun listToJSON(list: List<Any>): JSONArray
|
|
25
|
+
|
|
26
|
+
fun jsonToMap(json: JSONObject): Map<String, Any?>
|
|
27
|
+
|
|
28
|
+
fun jsonToList(json: JSONArray): List<Any?>
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
fun convertJsonToMap(jsonObject: JSONObject): WritableMap
|
|
32
|
+
|
|
33
|
+
fun convertJsonToArray(jsonArray: JSONArray): WritableArray
|
|
34
|
+
|
|
35
|
+
fun convertMapToReadableMap(source: Map<String, Any?>): WritableMap
|
|
36
|
+
|
|
37
|
+
fun convertArrayToWritableArray(sourceArray: List<Any>): WritableArray
|
|
38
|
+
|
|
39
|
+
fun convertXReadableMapToReadableMap(source: XReadableMap): WritableMap
|
|
40
|
+
|
|
41
|
+
fun convertXReadableArrayToReadableArray(source: XReadableArray): WritableArray
|
|
42
|
+
|
|
43
|
+
fun getValue(value: Any?): Any?
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.api.util
|
|
7
|
+
|
|
8
|
+
import android.util.Log
|
|
9
|
+
import java.io.PrintWriter
|
|
10
|
+
import java.io.StringWriter
|
|
11
|
+
|
|
12
|
+
const val TAG = "SparklingBridge"
|
|
13
|
+
internal fun Any?.log() {
|
|
14
|
+
when (this) {
|
|
15
|
+
is Map<*,*> -> {
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
else -> {
|
|
19
|
+
Log.d(TAG, this.toString())
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
internal fun Throwable.printStackString(): String {
|
|
25
|
+
val sw = StringWriter()
|
|
26
|
+
val pw = PrintWriter(sw)
|
|
27
|
+
this.printStackTrace(pw)
|
|
28
|
+
pw.flush()
|
|
29
|
+
return sw.toString()
|
|
30
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.api.util
|
|
7
|
+
|
|
8
|
+
import android.os.Handler
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import android.util.Log
|
|
11
|
+
import com.tiktok.sparkling.method.runtime.depend.CommonDependsProvider
|
|
12
|
+
import com.tiktok.sparkling.method.registry.api.util.ThreadPool.runInBackGround
|
|
13
|
+
import java.util.concurrent.ExecutorService
|
|
14
|
+
import java.util.concurrent.Executors
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
object ThreadPool {
|
|
18
|
+
|
|
19
|
+
private const val TAG = "ThreadPool"
|
|
20
|
+
|
|
21
|
+
private var executor: ExecutorService? = null
|
|
22
|
+
|
|
23
|
+
private val mainHandler: Handler by lazy {
|
|
24
|
+
Handler(Looper.getMainLooper())
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* run task on main thread
|
|
29
|
+
*/
|
|
30
|
+
fun runInMain(runnable: Runnable) {
|
|
31
|
+
mainHandler.post(runnable)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* run task on background thread
|
|
36
|
+
*/
|
|
37
|
+
fun runInBackGround(runnable: Runnable) {
|
|
38
|
+
ensureExecutorNotNull()
|
|
39
|
+
executor!!.submit(runnable)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* config custom executor by user
|
|
44
|
+
* used by runInBackGround
|
|
45
|
+
* @see runInBackGround
|
|
46
|
+
*/
|
|
47
|
+
fun configExecutorService(outerExecutors: ExecutorService) {
|
|
48
|
+
executor = outerExecutors
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fun getExecutorService(): ExecutorService {
|
|
52
|
+
ensureExecutorNotNull()
|
|
53
|
+
return executor!!
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private fun ensureExecutorNotNull() {
|
|
57
|
+
if (executor == null) {
|
|
58
|
+
executor = CommonDependsProvider.hostThreadPoolExecutorDepend?.getNormalThreadExecutor()
|
|
59
|
+
?: createDefault()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private fun createDefault(): ExecutorService {
|
|
64
|
+
val cupNumber = Runtime.getRuntime().availableProcessors()
|
|
65
|
+
var threadPoolSize = cupNumber / 2
|
|
66
|
+
if (threadPoolSize == 0) {
|
|
67
|
+
threadPoolSize = 1
|
|
68
|
+
}
|
|
69
|
+
Log.d(TAG, "jsb thread pool size: $threadPoolSize")
|
|
70
|
+
return Executors.newFixedThreadPool(threadPoolSize)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.core
|
|
7
|
+
|
|
8
|
+
interface XReadableMap {
|
|
9
|
+
fun hasKey(name: String): Boolean
|
|
10
|
+
fun isNull(name: String): Boolean
|
|
11
|
+
fun getBoolean(name: String): Boolean
|
|
12
|
+
fun getDouble(name: String): Double
|
|
13
|
+
fun getInt(name: String): Int
|
|
14
|
+
fun getString(name: String): String
|
|
15
|
+
fun getArray(name: String): XReadableArray?
|
|
16
|
+
fun getMap(name: String): XReadableMap?
|
|
17
|
+
fun get(name: String): XDynamic
|
|
18
|
+
fun getType(name: String): XReadableType
|
|
19
|
+
fun keyIterator(): XKeyIterator
|
|
20
|
+
fun toMap(): Map<String, Any?>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fun XReadableMap.optString(name: String, defaultValue: String = ""): String {
|
|
24
|
+
if (!hasKey(name)) {
|
|
25
|
+
return defaultValue
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
val value = get(name)
|
|
29
|
+
return if (value.getType() == XReadableType.String) {
|
|
30
|
+
value.asString()
|
|
31
|
+
} else {
|
|
32
|
+
defaultValue
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fun XReadableMap.optBoolean(name: String, defaultValue: Boolean = false): Boolean {
|
|
37
|
+
if (!hasKey(name)) {
|
|
38
|
+
return defaultValue
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
val value = get(name)
|
|
42
|
+
return if (value.getType() == XReadableType.Boolean) {
|
|
43
|
+
value.asBoolean()
|
|
44
|
+
} else {
|
|
45
|
+
defaultValue
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fun XReadableMap.optInt(name: String, defaultValue: Int = 0): Int {
|
|
50
|
+
if (!hasKey(name)) {
|
|
51
|
+
return defaultValue
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
val value = get(name)
|
|
55
|
+
return if (value.getType() == XReadableType.Int) {
|
|
56
|
+
value.asInt()
|
|
57
|
+
} else {
|
|
58
|
+
defaultValue
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fun XReadableMap.optDouble(name: String, defaultValue: Double = 0.0): Double {
|
|
63
|
+
if (!hasKey(name)) {
|
|
64
|
+
return defaultValue
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
val value = get(name)
|
|
68
|
+
return if (value.getType() == XReadableType.Number) {
|
|
69
|
+
value.asDouble()
|
|
70
|
+
} else {
|
|
71
|
+
defaultValue
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fun XReadableMap.optMap(name: String, defaultValue: XReadableMap? = null): XReadableMap? {
|
|
76
|
+
if (!hasKey(name)) {
|
|
77
|
+
return defaultValue
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
val value = get(name)
|
|
81
|
+
return if (value.getType() == XReadableType.Map) {
|
|
82
|
+
value.asMap()
|
|
83
|
+
} else {
|
|
84
|
+
defaultValue
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fun XReadableMap.optArray(name: String, defaultValue: XReadableArray? = null): XReadableArray? {
|
|
89
|
+
if (!hasKey(name)) {
|
|
90
|
+
return defaultValue
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
val value = get(name)
|
|
94
|
+
return if (value.getType() == XReadableType.Array) {
|
|
95
|
+
value.asArray()
|
|
96
|
+
} else {
|
|
97
|
+
defaultValue
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface XReadableArray {
|
|
102
|
+
fun size(): Int
|
|
103
|
+
fun isNull(index: Int): Boolean
|
|
104
|
+
fun getBoolean(index: Int): Boolean
|
|
105
|
+
fun getDouble(index: Int): Double
|
|
106
|
+
fun getInt(index: Int): Int
|
|
107
|
+
fun getString(index: Int): String
|
|
108
|
+
fun getArray(index: Int): XReadableArray?
|
|
109
|
+
fun getMap(index: Int): XReadableMap?
|
|
110
|
+
fun get(index: Int): XDynamic
|
|
111
|
+
fun getType(index: Int): XReadableType
|
|
112
|
+
fun toList(): List<Any?>
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fun XReadableArray.toObjectList(): List<Any> {
|
|
116
|
+
val data = mutableListOf<Any>()
|
|
117
|
+
for (idx in 0 until size()) {
|
|
118
|
+
when (getType(idx)) {
|
|
119
|
+
XReadableType.String -> data.add(getString(idx))
|
|
120
|
+
XReadableType.Number -> data.add(getDouble(idx))
|
|
121
|
+
XReadableType.Boolean -> data.add(getBoolean(idx))
|
|
122
|
+
XReadableType.Int -> data.add(getInt(idx))
|
|
123
|
+
XReadableType.Map -> {
|
|
124
|
+
getMap(idx)?.let {
|
|
125
|
+
data.add(it.toObjectMap())
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
XReadableType.Array -> {
|
|
129
|
+
getArray(idx)?.let {
|
|
130
|
+
data.add(it.toObjectList())
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else -> {
|
|
134
|
+
//ignore
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return data
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fun XReadableMap.toObjectMap(): Map<String, Any> {
|
|
142
|
+
val data = mutableMapOf<String, Any>()
|
|
143
|
+
val iterator = keyIterator()
|
|
144
|
+
while (iterator.hasNextKey()) {
|
|
145
|
+
val key = iterator.nextKey()
|
|
146
|
+
when (getType(key)) {
|
|
147
|
+
XReadableType.String -> data[key] = getString(key)
|
|
148
|
+
XReadableType.Number -> data[key] = getDouble(key)
|
|
149
|
+
XReadableType.Boolean -> data[key] = getBoolean(key)
|
|
150
|
+
XReadableType.Int -> data[key] = getInt(key)
|
|
151
|
+
XReadableType.Map -> {
|
|
152
|
+
getMap(key)?.let {
|
|
153
|
+
data[key] = it.toObjectMap()
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
XReadableType.Array -> {
|
|
157
|
+
getArray(key)?.let {
|
|
158
|
+
data[key] = it.toObjectList()
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else -> {
|
|
162
|
+
//ignore
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return data
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface XDynamic {
|
|
170
|
+
fun isNull(): Boolean
|
|
171
|
+
fun getType(): XReadableType
|
|
172
|
+
fun asBoolean(): Boolean
|
|
173
|
+
fun asDouble(): Double
|
|
174
|
+
fun asInt(): Int
|
|
175
|
+
fun asString(): String
|
|
176
|
+
fun asArray(): XReadableArray?
|
|
177
|
+
fun asMap(): XReadableMap?
|
|
178
|
+
fun recycle()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface XKeyIterator {
|
|
182
|
+
fun hasNextKey(): Boolean
|
|
183
|
+
fun nextKey(): String
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
enum class XReadableType {
|
|
187
|
+
Null,
|
|
188
|
+
Boolean,
|
|
189
|
+
Number,
|
|
190
|
+
Int,
|
|
191
|
+
String,
|
|
192
|
+
Map,
|
|
193
|
+
Array
|
|
194
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.core
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Desc:
|
|
10
|
+
*/
|
|
11
|
+
enum class BridgePlatformType {
|
|
12
|
+
WEB, LYNX, NONE, ALL
|
|
13
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.core
|
|
7
|
+
|
|
8
|
+
import android.app.Activity
|
|
9
|
+
import android.content.Context
|
|
10
|
+
import android.view.View
|
|
11
|
+
import com.tiktok.sparkling.method.registry.api.SparklingBridge
|
|
12
|
+
import com.tiktok.sparkling.method.registry.core.model.context.IContextProvider
|
|
13
|
+
import com.tiktok.sparkling.method.registry.core.model.context.ContextHolder
|
|
14
|
+
import com.tiktok.sparkling.method.registry.core.model.context.WeakContextHolder
|
|
15
|
+
import com.tiktok.sparkling.method.registry.core.utils.IDLMethodHelper
|
|
16
|
+
import org.json.JSONObject
|
|
17
|
+
import java.lang.ref.WeakReference
|
|
18
|
+
|
|
19
|
+
interface IBridgeContext {
|
|
20
|
+
val bridge: SparklingBridge?
|
|
21
|
+
val view: View?
|
|
22
|
+
val ownerActivity: Activity?
|
|
23
|
+
val containerID: String?
|
|
24
|
+
val context: Context?
|
|
25
|
+
fun sendEvent(name: String, obj: JSONObject)
|
|
26
|
+
fun <T> getObject(clazz: Class<T>): T?
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface JSEventDelegate {
|
|
30
|
+
fun sendJSEvent(eventName: String, params: JSONObject?)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class BridgeContextWrapper : IBridgeContext {
|
|
34
|
+
private val providers: MutableMap<Class<*>, IContextProvider<*>> = mutableMapOf()
|
|
35
|
+
private var _view: WeakReference<View?>? = null
|
|
36
|
+
private var _activity: WeakReference<Activity?>? = null
|
|
37
|
+
private var _containerID: String? = null
|
|
38
|
+
private var _jsEvent: JSEventDelegate? = null
|
|
39
|
+
private var __bridge: WeakReference<SparklingBridge>? = null
|
|
40
|
+
/**
|
|
41
|
+
* register object to JSBSDKContext, you can use getSDKContext().getObject(clazz) in JSB method to get it.
|
|
42
|
+
* there is two-ways to register object to JSBSDKContext: registerObject & registerWeakObject
|
|
43
|
+
* 1. registerObject register an object to JSBSDKContext. It uses strong references to ensure that objects exist when used.
|
|
44
|
+
* 2. registerWeakObject register a weakObject to JSBSDKContext.
|
|
45
|
+
* It uses weak references to store the object, so when the object is released, maybe you will get a null when you use it.
|
|
46
|
+
* 3. registerWeakObject has higher priority than registerObject,
|
|
47
|
+
* so if you register the same class with object and weakObject, you only can get the weakObject.
|
|
48
|
+
*/
|
|
49
|
+
fun <T> registerWeakObject(clazz: Class<T>, t: T?) {
|
|
50
|
+
providers[clazz] = WeakContextHolder(t)
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* register object to JSBSDKContext, you can use getSDKContext().getObject(clazz) in JSB method to get it.
|
|
54
|
+
* there is two-ways to register object to JSBSDKContext: registerObject & registerWeakObject
|
|
55
|
+
* 1. registerObject register an object to JSBSDKContext. It uses strong references to ensure that objects exist when used.
|
|
56
|
+
* 2. registerWeakObject register a weakObject to JSBSDKContext.
|
|
57
|
+
* It uses weak references to store the object, so when the object is released, maybe you will get a null when you use it.
|
|
58
|
+
* 3. registerWeakObject has higher priority than registerObject,
|
|
59
|
+
* so if you register the same class with object and weakObject, you only can get the weakObject.
|
|
60
|
+
*/
|
|
61
|
+
fun <T> registerObject(clazz: Class<T>, t: T?) {
|
|
62
|
+
providers[clazz] = ContextHolder(t)
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* register object to JSBSDKContext, you can use getSDKContext().getObject(clazz) in JSB method to get it.
|
|
66
|
+
* there is two-ways to register object to JSBSDKContext: registerObject & registerWeakObject
|
|
67
|
+
* 1. registerObject register an object to JSBSDKContext. It uses strong references to ensure that objects exist when used.
|
|
68
|
+
* 2. registerWeakObject register a weakObject to JSBSDKContext.
|
|
69
|
+
* It uses weak references to store the object, so when the object is released, maybe you will get a null when you use it.
|
|
70
|
+
* 3. registerWeakObject has higher priority than registerObject,
|
|
71
|
+
* so if you register the same class with object and weakObject, you only can get the weakObject.
|
|
72
|
+
*/
|
|
73
|
+
fun registerWeakObjects(map: Map<Class<*>, WeakContextHolder<*>>) {
|
|
74
|
+
providers.putAll(map)
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* register object to JSBSDKContext, you can use getSDKContext().getObject(clazz) in JSB method to get it.
|
|
78
|
+
* there is two-ways to register object to JSBSDKContext: registerObject & registerWeakObject
|
|
79
|
+
* 1. registerObject register an object to JSBSDKContext. It uses strong references to ensure that objects exist when used.
|
|
80
|
+
* 2. registerWeakObject register a weakObject to JSBSDKContext.
|
|
81
|
+
* It uses weak references to store the object, so when the object is released, maybe you will get a null when you use it.
|
|
82
|
+
* 3. registerWeakObject has higher priority than registerObject,
|
|
83
|
+
* so if you register the same class with object and weakObject, you only can get the weakObject.
|
|
84
|
+
*/
|
|
85
|
+
fun registerObjects(map: Map<Class<*>, ContextHolder<*>>) {
|
|
86
|
+
providers.putAll(map)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fun setJSEventDelegate(delegate: JSEventDelegate) {
|
|
90
|
+
if (_jsEvent == null) {
|
|
91
|
+
_jsEvent = delegate
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fun setView(view: View?) {
|
|
96
|
+
if (_view == null) {
|
|
97
|
+
_view = WeakReference(view)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fun setContainerID(containerID: String?) {
|
|
102
|
+
_containerID = containerID
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fun setOwnerActivity(activity: Activity?) {
|
|
106
|
+
if (_activity?.get() == null) {
|
|
107
|
+
_activity = WeakReference(activity)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fun setBridge(bridge:SparklingBridge) {
|
|
112
|
+
if (__bridge?.get() == null) {
|
|
113
|
+
__bridge = WeakReference(bridge)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
override val bridge: SparklingBridge?
|
|
118
|
+
get() = __bridge?.get()
|
|
119
|
+
|
|
120
|
+
override val view: View?
|
|
121
|
+
get() = _view?.get() ?: getObject(View::class.java)
|
|
122
|
+
override val ownerActivity: Activity?
|
|
123
|
+
get() = WeakReference(IDLMethodHelper.getActivity(context)).get()
|
|
124
|
+
override val context: Context?
|
|
125
|
+
get() = _view?.get()?.context ?: getObject(Context::class.java)
|
|
126
|
+
|
|
127
|
+
override fun sendEvent(name: String, obj: JSONObject) {
|
|
128
|
+
_jsEvent?.sendJSEvent(name, obj)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
override val containerID: String?
|
|
132
|
+
get() = _containerID
|
|
133
|
+
|
|
134
|
+
override fun <T> getObject(clazz: Class<T>): T? {
|
|
135
|
+
return providers[clazz]?.provideInstance() as T?
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.core
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.registry.core.model.context.ContextProviderFactory
|
|
9
|
+
import com.tiktok.sparkling.method.registry.core.model.idl.IDLMethodBaseParamModel
|
|
10
|
+
import com.tiktok.sparkling.method.registry.core.model.idl.IDLMethodBaseResultModel
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Desc:
|
|
14
|
+
*/
|
|
15
|
+
interface IDLBridgeMethod {
|
|
16
|
+
|
|
17
|
+
companion object {
|
|
18
|
+
const val KEY_NOT_FOUND = 2
|
|
19
|
+
const val SUCCESS = 1
|
|
20
|
+
const val FAIL = 0 //error code for JSB method
|
|
21
|
+
|
|
22
|
+
//error code for sdk
|
|
23
|
+
const val UNREGISTERED = -2 // UnregisteredMethod, the called method isn't registered, due to legacy error, sdk use BridgeConstants's BRIDGE_NOT_FOUND
|
|
24
|
+
const val INVALID_PARAM = -3 // InvalidParameter, the parameter passed by FE is invalid
|
|
25
|
+
const val INVALID_RESULT = -5 // InvalidResult, the result passed by the method implementor is invalid
|
|
26
|
+
const val BRIDGE_CALL_BE_INTERCEPTED = -10 // bridge call be intercepted
|
|
27
|
+
const val BRIDGE_CALL_BE_INTERCEPTED_MSG = "intercepted by lifeClient"
|
|
28
|
+
const val BRIDGE_HAS_BEEN_RELEASED = -13 //bridge has been released
|
|
29
|
+
|
|
30
|
+
const val UNKNOWN_ERROR = -1000
|
|
31
|
+
const val PERMISSION_NO_EXIST = -1128 // internal code, due to legacy error, sdk use BridgeConstants's PERMISSION_NO_EXIST
|
|
32
|
+
const val ANNOTATION_ERROR = -2000 // when annotation can't get
|
|
33
|
+
const val ILLEGAL_OPERATION_ERROR = -2001 // when call a illegal method of proxy
|
|
34
|
+
|
|
35
|
+
//other error codes
|
|
36
|
+
const val UNAUTHORIZED_ACCESS = -6 // UnauthorizedAccess, unauthorized to access some resources, like camera, microphone
|
|
37
|
+
const val CANCELLED = -7 // OperationCancelled, user cancelled certain operation
|
|
38
|
+
const val OPERATION_TIMEOUT = -8 // OperationTimeout
|
|
39
|
+
const val NOT_FOUND = -9 // NOT_FOUND
|
|
40
|
+
|
|
41
|
+
const val NETWORK_UNREACHABLE = -1001
|
|
42
|
+
const val NETWORK_TIMEOUT = -1002
|
|
43
|
+
const val MALFORMEDRESPONSE_ERROR = -1003
|
|
44
|
+
|
|
45
|
+
const val PARAM_CODE = "code"
|
|
46
|
+
const val PARAM_MSG = "msg"
|
|
47
|
+
const val PARAM_DATA = "data"
|
|
48
|
+
const val ORIGINAL_RESULT = "originalResult"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
enum class Compatibility(val value: Boolean) {
|
|
53
|
+
Compatible(true),
|
|
54
|
+
InCompatible(false)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface Callback {
|
|
58
|
+
// why do we need hashmap here
|
|
59
|
+
fun invoke(data: Map<String, Any?>)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface JSEventDelegate {
|
|
63
|
+
fun sendJSEvent(eventName: String, params: Map<String, Any?>?)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fun provideParamModel(): Class<out IDLMethodBaseParamModel>? {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fun provideResultModel(): Class<out IDLMethodBaseResultModel>? {
|
|
71
|
+
return null
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* this just for old jsb change to idl with difference format result.
|
|
76
|
+
* if you set useOriginalResult is true,
|
|
77
|
+
* you can add your result as a Map<String, any> to the resultModel with key: IDLBridgeMethod.ORIGINAL_RESULT,
|
|
78
|
+
* we will get it by the key : IDLBridgeMethod.ORIGINAL_RESULT,
|
|
79
|
+
* or you can also pass the original map<String, any> to callbak, we will pass it to fe directly.
|
|
80
|
+
*/
|
|
81
|
+
val useOriginalResult: Boolean
|
|
82
|
+
get() = false
|
|
83
|
+
|
|
84
|
+
fun shouldUseOriginalData(bridgeContext: IBridgeContext?): Boolean {
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
val compatibility: Compatibility
|
|
89
|
+
get() = Compatibility.InCompatible
|
|
90
|
+
|
|
91
|
+
val name: String
|
|
92
|
+
|
|
93
|
+
fun realHandle(params: Map<String, Any?>, callback: Callback, type: BridgePlatformType)
|
|
94
|
+
|
|
95
|
+
fun setProviderFactory(contextProviderFactory: ContextProviderFactory?)
|
|
96
|
+
|
|
97
|
+
fun setBridgeContext(bridgeContext: IBridgeContext)
|
|
98
|
+
|
|
99
|
+
fun release() {}
|
|
100
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.core
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Desc:
|
|
10
|
+
*/
|
|
11
|
+
interface IDLMethodProvider {
|
|
12
|
+
fun provideMethod(): IDLBridgeMethod
|
|
13
|
+
}
|