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
package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeCallback.kt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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.protocol.interfaces
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
9
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeResult
|
|
10
|
+
import com.tiktok.sparkling.method.protocol.impl.monitor.BridgeSDKMonitor
|
|
11
|
+
|
|
12
|
+
interface IBridgeCallback {
|
|
13
|
+
fun onBridgeResult(result: BridgeResult, call: BridgeCall?, monitorBuilder: BridgeSDKMonitor.MonitorModel.Builder?)
|
|
14
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeClient.kt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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.protocol.interfaces
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
9
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeResult
|
|
10
|
+
import org.json.JSONObject
|
|
11
|
+
|
|
12
|
+
interface IBridgeClient {
|
|
13
|
+
fun shouldInterceptRequest(call: BridgeCall): BridgeResult?
|
|
14
|
+
fun onBridgeInvoked(protocol: IBridgeProtocol, detail: JSONObject)
|
|
15
|
+
fun onBridgeDispatched(call:BridgeCall)
|
|
16
|
+
fun onBridgeResultReceived(name: String, handler: IBridgeHandler, detail: JSONObject)
|
|
17
|
+
fun onBridgeCallback()
|
|
18
|
+
fun onBridgeRejected()
|
|
19
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeHandler.kt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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.protocol.interfaces
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.protocol.BridgeContext
|
|
9
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
10
|
+
|
|
11
|
+
interface IBridgeHandler {
|
|
12
|
+
fun handle(
|
|
13
|
+
bridgeContext: BridgeContext,
|
|
14
|
+
call: BridgeCall,
|
|
15
|
+
callback: IBridgeMethodCallback
|
|
16
|
+
)
|
|
17
|
+
fun onRelease()
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* for check release status
|
|
21
|
+
*/
|
|
22
|
+
fun isReleased(): Boolean
|
|
23
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeLifeClient.kt
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) 2023 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.protocol.interfaces
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.protocol.BridgeContext
|
|
9
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
10
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeResult
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* when shouldHandleBridgeCall is false, you should give a reason to explain it
|
|
16
|
+
*/
|
|
17
|
+
class ShouldHandleBridgeCallResultModel(val shouldHandleBridgeCall: Boolean, val reason: String?){}
|
|
18
|
+
abstract class IBridgeLifeClient {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* if return false, the jsb call will be intercepted, and will callback to FE
|
|
22
|
+
* with error code : -10 BRIDGE_CALL_BE_INTERCEPTED and message : "intercepted by lifeClient"
|
|
23
|
+
*/
|
|
24
|
+
open fun shouldHandleBridgeCall(call: BridgeCall, bridgeContext: BridgeContext) : ShouldHandleBridgeCallResultModel {
|
|
25
|
+
return ShouldHandleBridgeCallResultModel(true, null)
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* you can register jsb in there
|
|
29
|
+
*/
|
|
30
|
+
open fun onBridgeCalledStart(call: BridgeCall, bridgeContext: BridgeContext) {}
|
|
31
|
+
open fun onBridgeImplHandleStart(call: BridgeCall?, bridgeContext: BridgeContext) {}
|
|
32
|
+
open fun onBridgeImplHandleEnd(call: BridgeCall?, bridgeContext: BridgeContext) {}
|
|
33
|
+
open fun onBridgeCallbackCallStart(result: BridgeResult, call: BridgeCall, mContext: BridgeContext) {}
|
|
34
|
+
open fun onBridgeCallbackInvokeStart(result: BridgeResult, call: BridgeCall){}
|
|
35
|
+
open fun onBridgeCalledEnd(call: BridgeCall, bridgeContext: BridgeContext) {}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* data is any.
|
|
39
|
+
* when it is webview, data will be a JSONObject
|
|
40
|
+
* when it is lynxview, data will be JavaOnlyArray
|
|
41
|
+
* you can change data in onBridgeEventBegin.
|
|
42
|
+
*/
|
|
43
|
+
open fun onBridgeEventStart(eventName: String, data: Any?) {}
|
|
44
|
+
open fun onBridgeEventEnd(eventName: String, data: Any?) {}
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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.protocol.interfaces
|
|
7
|
+
|
|
8
|
+
interface IBridgeMethodCallback {
|
|
9
|
+
fun onBridgeResult(parcel: Any)
|
|
10
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeProtocol.kt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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.protocol.interfaces
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.protocol.BridgeContext
|
|
9
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
10
|
+
|
|
11
|
+
abstract class IBridgeProtocol(context: BridgeContext) {
|
|
12
|
+
val mContext = context
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* params: JSONObject or JavaOnlyArray
|
|
16
|
+
*/
|
|
17
|
+
abstract fun sendEvent(name: String, params: Any?)
|
|
18
|
+
abstract fun init()
|
|
19
|
+
abstract fun createBridgeCall(msg:String): BridgeCall
|
|
20
|
+
|
|
21
|
+
open fun sendJSRuntimeEvent(name: String, params: Any?) {}
|
|
22
|
+
}
|
|
@@ -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.protocol.utils
|
|
7
|
+
|
|
8
|
+
internal object BridgeConstants {
|
|
9
|
+
const val BRIDGE_CALL_SUCCESS = 1
|
|
10
|
+
const val BRIDGE_CALL_FAIL = 0
|
|
11
|
+
const val ERROR_BRIDGE_NO_AUTHORITY = -1
|
|
12
|
+
const val BRIDGE_NOT_FOUND = -2
|
|
13
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
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.protocol.utils
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.registry.api.stringify
|
|
9
|
+
import com.lynx.react.bridge.JavaOnlyArray
|
|
10
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
11
|
+
import com.lynx.react.bridge.PiperData
|
|
12
|
+
import com.lynx.react.bridge.ReadableType
|
|
13
|
+
import org.json.JSONArray
|
|
14
|
+
import org.json.JSONObject
|
|
15
|
+
|
|
16
|
+
object BridgeConverter {
|
|
17
|
+
private const val TAG = "BridgeConverter"
|
|
18
|
+
|
|
19
|
+
fun revertJavaOnlyMap2JSONObject(map: JavaOnlyMap?): JSONObject {
|
|
20
|
+
val obj = JSONObject()
|
|
21
|
+
if (map.isNullOrEmpty()) {
|
|
22
|
+
return obj
|
|
23
|
+
}
|
|
24
|
+
val keys = map.keySetIterator()
|
|
25
|
+
while (keys.hasNextKey()) {
|
|
26
|
+
val nextKey = keys.nextKey()
|
|
27
|
+
val nextValue = map[nextKey]
|
|
28
|
+
try {
|
|
29
|
+
when (map.getType(nextKey)) {
|
|
30
|
+
ReadableType.Array -> {
|
|
31
|
+
obj.putOpt(nextKey, revertJavaOnlyArray2JSONArray(nextValue as JavaOnlyArray))
|
|
32
|
+
}
|
|
33
|
+
ReadableType.Map -> {
|
|
34
|
+
obj.putOpt(nextKey, revertJavaOnlyMap2JSONObject(nextValue as JavaOnlyMap))
|
|
35
|
+
}
|
|
36
|
+
ReadableType.Number -> {
|
|
37
|
+
val num = nextValue as Number
|
|
38
|
+
obj.put(nextKey, getNumber(num))
|
|
39
|
+
}
|
|
40
|
+
ReadableType.PiperData -> {
|
|
41
|
+
val jsonObject = (nextValue as PiperData).stringify()
|
|
42
|
+
obj.put(nextKey, jsonObject)
|
|
43
|
+
}
|
|
44
|
+
else -> {
|
|
45
|
+
obj.putOpt(nextKey, nextValue)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch (ex: Throwable) {
|
|
49
|
+
LogUtils.e(TAG, "revertJavaOnlyMap2JSONObject $ex")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
return obj
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private fun revertJavaOnlyArray2JSONArray(array: JavaOnlyArray): JSONArray {
|
|
57
|
+
val result = JSONArray()
|
|
58
|
+
for (i in 0 until array.size) {
|
|
59
|
+
val value = array[i]
|
|
60
|
+
try {
|
|
61
|
+
when (array.getType(i)) {
|
|
62
|
+
ReadableType.Map -> {
|
|
63
|
+
result.put(revertJavaOnlyMap2JSONObject(value as JavaOnlyMap))
|
|
64
|
+
}
|
|
65
|
+
ReadableType.Array -> {
|
|
66
|
+
result.put(revertJavaOnlyArray2JSONArray(value as JavaOnlyArray))
|
|
67
|
+
}
|
|
68
|
+
ReadableType.Number -> {
|
|
69
|
+
val num = value as Number
|
|
70
|
+
result.put(getNumber(num))
|
|
71
|
+
}
|
|
72
|
+
ReadableType.PiperData -> {
|
|
73
|
+
val jsonObject = (value as PiperData).stringify()
|
|
74
|
+
result.put(jsonObject)
|
|
75
|
+
}
|
|
76
|
+
else -> {
|
|
77
|
+
result.put(value)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch (ex: Throwable) {
|
|
81
|
+
LogUtils.e(TAG, "revertJavaOnlyArray2JSONArray $ex")
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private fun getNumber(rawNumber: Number): Number {
|
|
88
|
+
val intValue: Int = runCatching { rawNumber.toInt() }.getOrNull() ?: 0
|
|
89
|
+
val doubleValue: Double = runCatching { rawNumber.toDouble() }.getOrNull() ?: 0.0
|
|
90
|
+
if (intValue.compareTo(doubleValue) == 0) {
|
|
91
|
+
return intValue
|
|
92
|
+
} else {
|
|
93
|
+
val longValue: Long = doubleValue.toLong()
|
|
94
|
+
if (doubleValue.compareTo(longValue) == 0) {
|
|
95
|
+
return longValue
|
|
96
|
+
} else {
|
|
97
|
+
return doubleValue
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fun convertJSONObject2JavaOnlyMap(obj: JSONObject): JavaOnlyMap {
|
|
103
|
+
val keys = obj.keys()
|
|
104
|
+
val result = JavaOnlyMap()
|
|
105
|
+
while (keys.hasNext()) {
|
|
106
|
+
val key = keys.next()
|
|
107
|
+
when (val sonValue = obj.opt(key)) {
|
|
108
|
+
is JSONObject -> {
|
|
109
|
+
result[key] = convertJSONObject2JavaOnlyMap(sonValue)
|
|
110
|
+
}
|
|
111
|
+
is JSONArray -> {
|
|
112
|
+
result[key] = convertJSONArray2JavaOnlyArray(sonValue)
|
|
113
|
+
}
|
|
114
|
+
else -> {
|
|
115
|
+
if(sonValue == JSONObject.NULL) {
|
|
116
|
+
result[key] = null
|
|
117
|
+
}else {
|
|
118
|
+
result[key] = sonValue
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return result
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
private fun convertJSONArray2JavaOnlyArray(arrays: JSONArray): JavaOnlyArray {
|
|
130
|
+
val result = JavaOnlyArray()
|
|
131
|
+
for (i in 0 until arrays.length()) {
|
|
132
|
+
when (val sonValue = arrays.opt(i)) {
|
|
133
|
+
is JSONArray -> {
|
|
134
|
+
result.add(convertJSONArray2JavaOnlyArray(sonValue))
|
|
135
|
+
}
|
|
136
|
+
is JSONObject -> {
|
|
137
|
+
result.add(convertJSONObject2JavaOnlyMap(sonValue))
|
|
138
|
+
}
|
|
139
|
+
else -> {
|
|
140
|
+
result.add(sonValue)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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.protocol.utils
|
|
7
|
+
|
|
8
|
+
import android.util.Log
|
|
9
|
+
import com.tiktok.sparkling.method.registry.api.SparklingBridge
|
|
10
|
+
|
|
11
|
+
object LogUtils {
|
|
12
|
+
fun e(tag:String,msg:String){
|
|
13
|
+
if (SparklingBridge.isDebugEnv) {
|
|
14
|
+
Log.e(tag, msg)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
fun d(tag:String,msg:String){
|
|
18
|
+
if (SparklingBridge.isDebugEnv) {
|
|
19
|
+
Log.d(tag, msg)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
fun w(tag:String,msg:String){
|
|
23
|
+
if (SparklingBridge.isDebugEnv) {
|
|
24
|
+
Log.w(tag, msg)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
fun i(tag:String,msg:String){
|
|
28
|
+
if (SparklingBridge.isDebugEnv) {
|
|
29
|
+
Log.i(tag, msg)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
fun v(tag:String,msg:String){
|
|
33
|
+
if (SparklingBridge.isDebugEnv) {
|
|
34
|
+
Log.v(tag, msg)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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.protocol.utils
|
|
7
|
+
|
|
8
|
+
import org.json.JSONObject
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
class MonitorUtils {
|
|
14
|
+
companion object {
|
|
15
|
+
fun customReport(eventName: String, eventInfo: JSONObject?) {
|
|
16
|
+
customReport(eventName, null, eventInfo)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fun customReport(eventName: String, category: JSONObject?, metrics: JSONObject?) {
|
|
20
|
+
customReport(eventName, category, metrics, null)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fun customReport(
|
|
24
|
+
eventName: String,
|
|
25
|
+
category: JSONObject?,
|
|
26
|
+
metrics: JSONObject?,
|
|
27
|
+
extraInfo: String?
|
|
28
|
+
) {
|
|
29
|
+
// TODO: implement by injection
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fun lifecycleReportPV(params: HashMap<String, Any>) {
|
|
33
|
+
// TODO: implement by injection
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fun lifecycleReportPerf(params: HashMap<String, Any>) {
|
|
37
|
+
// TODO: implement by injection
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import com.tiktok.sparkling.method.registry.core.IBridgeContext
|
|
10
|
+
import com.tiktok.sparkling.method.registry.core.IDLBridgeMethod
|
|
11
|
+
import com.tiktok.sparkling.method.registry.core.LocalBridge
|
|
12
|
+
import com.tiktok.sparkling.method.registry.core.SparklingBridgeManager
|
|
13
|
+
import com.tiktok.sparkling.method.registry.core.BridgePlatformType
|
|
14
|
+
import com.tiktok.sparkling.method.registry.core.interfaces.IReleasable
|
|
15
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
16
|
+
|
|
17
|
+
class BridgeLocalPool : IReleasable {
|
|
18
|
+
private var context: IBridgeContext? = null
|
|
19
|
+
private val map: ConcurrentHashMap<BridgePlatformType, ConcurrentHashMap<String, IDLBridgeMethod>> = ConcurrentHashMap()
|
|
20
|
+
|
|
21
|
+
private val localBridge: LocalBridge by lazy {
|
|
22
|
+
LocalBridge().apply { setIsLocalBridge(true) }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fun setBridgeContext(context: IBridgeContext?) {
|
|
26
|
+
this.context = context
|
|
27
|
+
localBridge.setContext(context)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun registerLocalIDLMethod(
|
|
31
|
+
clazz: Class<out IDLBridgeMethod>?,
|
|
32
|
+
scope: BridgePlatformType = BridgePlatformType.ALL
|
|
33
|
+
) {
|
|
34
|
+
localBridge.registerIDLMethod(clazz, scope)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fun getBridge(bridgeName: String, platformType: BridgePlatformType): IDLBridgeMethod? {
|
|
38
|
+
val method = map[platformType]?.get(bridgeName) ?: map[BridgePlatformType.ALL]?.get(bridgeName)
|
|
39
|
+
if (method != null) {
|
|
40
|
+
return method
|
|
41
|
+
} else {
|
|
42
|
+
val clazz =
|
|
43
|
+
localBridge.findIDLMethodClass(platformType, bridgeName) ?:
|
|
44
|
+
SparklingBridgeManager.findIDLMethodClass(platformType, bridgeName) ?:
|
|
45
|
+
return null
|
|
46
|
+
val newInstance = clazz.newInstance()
|
|
47
|
+
getPlatformTypeCache(platformType)[bridgeName] = newInstance
|
|
48
|
+
return newInstance
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private fun getPlatformTypeCache(platformType: BridgePlatformType): ConcurrentHashMap<String, IDLBridgeMethod> {
|
|
53
|
+
val concurrentHashMap = map[platformType]
|
|
54
|
+
return if (concurrentHashMap == null) {
|
|
55
|
+
map[platformType] = ConcurrentHashMap()
|
|
56
|
+
map[platformType]!!
|
|
57
|
+
} else {
|
|
58
|
+
concurrentHashMap
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override fun release() {
|
|
63
|
+
map.forEach { entry ->
|
|
64
|
+
entry.value.forEach{
|
|
65
|
+
it.value.release()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
map.clear()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) 2023 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
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* when your value is just for the experiment, you can add it here.
|
|
10
|
+
* and after your data has been recycled, you must delete it.
|
|
11
|
+
*/
|
|
12
|
+
object BridgeSettings {
|
|
13
|
+
|
|
14
|
+
var bridgeRegistryOptimize: Boolean = false
|
|
15
|
+
var bridgeDisableLongToDouble: Boolean = false
|
|
16
|
+
var bridgeNewInputNumberTypeChange : Boolean = false
|
|
17
|
+
var bridgeCallToStringOptimization: Boolean = false
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -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.api
|
|
7
|
+
|
|
8
|
+
import com.lynx.react.bridge.ReadableMap
|
|
9
|
+
import com.tiktok.sparkling.method.protocol.BridgeContext
|
|
10
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
11
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeHandler
|
|
12
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeMethodCallback
|
|
13
|
+
import com.tiktok.sparkling.method.registry.core.IBridgeContext
|
|
14
|
+
import com.tiktok.sparkling.method.registry.core.IDLBridgeMethod
|
|
15
|
+
import com.tiktok.sparkling.method.registry.core.IDLMethodRegistry
|
|
16
|
+
import com.tiktok.sparkling.method.registry.core.BridgePlatformType
|
|
17
|
+
import com.tiktok.sparkling.method.registry.api.util.BridgeMethodCallbackHelper
|
|
18
|
+
import org.json.JSONObject
|
|
19
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*/
|
|
23
|
+
class BusinessCallHandler(val nameSpace: String): IBridgeHandler {
|
|
24
|
+
private var context : IBridgeContext? = null
|
|
25
|
+
private var registry = IDLMethodRegistry().apply { namespace = nameSpace }
|
|
26
|
+
private var pool: ConcurrentHashMap<BridgePlatformType, ConcurrentHashMap<String, IDLBridgeMethod>> = ConcurrentHashMap()
|
|
27
|
+
private var isRelease = false
|
|
28
|
+
override fun handle(
|
|
29
|
+
bridgeContext: BridgeContext,
|
|
30
|
+
call: BridgeCall,
|
|
31
|
+
callback: IBridgeMethodCallback
|
|
32
|
+
) {
|
|
33
|
+
val bridge = getBridge(bridgeContext, call.bridgeName) ?: return BridgeMethodCallbackHelper.bridgeNotFound(callback)
|
|
34
|
+
|
|
35
|
+
context?.let {
|
|
36
|
+
bridge.setBridgeContext(it)
|
|
37
|
+
}
|
|
38
|
+
val params = call.params
|
|
39
|
+
when (params) {
|
|
40
|
+
is JSONObject -> {
|
|
41
|
+
JsonProcessor(bridge, params, call.platform)
|
|
42
|
+
}
|
|
43
|
+
is ReadableMap -> {
|
|
44
|
+
ReadableMapProcessor(bridge, unWrapperParams(params) ?: params)
|
|
45
|
+
}
|
|
46
|
+
else -> {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
}.handle(callback)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun registerMethod(
|
|
53
|
+
clazz: Class<out IDLBridgeMethod>,
|
|
54
|
+
scope: BridgePlatformType = BridgePlatformType.ALL
|
|
55
|
+
) {
|
|
56
|
+
registry.registerMethod(clazz, scope)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fun getBridge(bridgeContext: BridgeContext, bridgeName: String) : IDLBridgeMethod? {
|
|
60
|
+
val platformType = BridgeContext.getPlatformByBridgeContext(bridgeContext)
|
|
61
|
+
val clazz = registry.findMethodClass(platformType, bridgeName) ?: return null
|
|
62
|
+
val newInstance = clazz.newInstance()
|
|
63
|
+
getPlatformTypeCache(platformType)[bridgeName] = newInstance
|
|
64
|
+
return newInstance
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fun isMethodExists(
|
|
68
|
+
name: String,
|
|
69
|
+
platformType: BridgePlatformType = BridgePlatformType.ALL
|
|
70
|
+
): Boolean {
|
|
71
|
+
return registry.isMethodExists(name, platformType)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
fun setBridgeContext(bridgeContext: IBridgeContext) {
|
|
75
|
+
context = bridgeContext
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private fun getPlatformTypeCache(platformType: BridgePlatformType): ConcurrentHashMap<String, IDLBridgeMethod> {
|
|
79
|
+
val concurrentHashMap = pool[platformType]
|
|
80
|
+
return if (concurrentHashMap == null) {
|
|
81
|
+
pool[platformType] = ConcurrentHashMap()
|
|
82
|
+
pool[platformType]!!
|
|
83
|
+
} else {
|
|
84
|
+
concurrentHashMap
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private fun unWrapperParams(params: ReadableMap?) : ReadableMap? {
|
|
89
|
+
return params?.getMap("data") ?: params
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
override fun onRelease() {
|
|
93
|
+
pool.clear()
|
|
94
|
+
isRelease = true
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
override fun isReleased(): Boolean {
|
|
98
|
+
return isRelease
|
|
99
|
+
}
|
|
100
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/registry/api/CancelCallbackConfig.kt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) 2024 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
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
*/
|
|
10
|
+
class CancelCallbackConfig {
|
|
11
|
+
var enable: Boolean = false
|
|
12
|
+
var cancelCallbackUrlList: ArrayList<String>? = null
|
|
13
|
+
}
|