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,106 @@
|
|
|
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.BridgePlatformType
|
|
16
|
+
import com.tiktok.sparkling.method.registry.api.util.BridgeMethodCallbackHelper
|
|
17
|
+
import org.json.JSONObject
|
|
18
|
+
|
|
19
|
+
class DefaultCallHandler : IBridgeHandler {
|
|
20
|
+
private var context: IBridgeContext? = null
|
|
21
|
+
private var pool: BridgeLocalPool = BridgeLocalPool()
|
|
22
|
+
private var isReleased = false
|
|
23
|
+
|
|
24
|
+
override fun handle(
|
|
25
|
+
bridgeContext: BridgeContext,
|
|
26
|
+
call: BridgeCall,
|
|
27
|
+
callback: IBridgeMethodCallback
|
|
28
|
+
) {
|
|
29
|
+
val platform = BridgeContext.getPlatformByBridgeContext(bridgeContext)
|
|
30
|
+
val bridge = pool.getBridge(call.bridgeName, platform)
|
|
31
|
+
?: return BridgeMethodCallbackHelper.bridgeNotFound(callback)
|
|
32
|
+
|
|
33
|
+
val params = call.params
|
|
34
|
+
|
|
35
|
+
context?.let {
|
|
36
|
+
bridge.setBridgeContext(it)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!bridge.compatibility.value) {
|
|
40
|
+
when (params) {
|
|
41
|
+
is JSONObject -> {
|
|
42
|
+
JsonProcessor(bridge, params, call.platform).apply { this@apply.context = this@DefaultCallHandler.context }
|
|
43
|
+
}
|
|
44
|
+
is ReadableMap -> {
|
|
45
|
+
ReadableMapProcessor(bridge, unWrapperParams(params) ?: params).apply { this@apply.context = this@DefaultCallHandler.context }
|
|
46
|
+
}
|
|
47
|
+
else -> {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
}.handle(callback)
|
|
51
|
+
} else { // compatible bridge
|
|
52
|
+
val idlCallback = object : IDLBridgeMethod.Callback {
|
|
53
|
+
override fun invoke(data: Map<String, Any?>) {
|
|
54
|
+
callback.onBridgeResult(data)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
when (params) {
|
|
58
|
+
is JSONObject -> {
|
|
59
|
+
bridge.realHandle(Utils.jsonToMap(params), idlCallback, BridgePlatformType.ALL)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
is ReadableMap -> {
|
|
63
|
+
bridge.realHandle(
|
|
64
|
+
(unWrapperParams(params) ?: params).toHashMap(),
|
|
65
|
+
idlCallback,
|
|
66
|
+
BridgePlatformType.ALL
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
else -> {
|
|
71
|
+
bridge.realHandle(emptyMap(), idlCallback, BridgePlatformType.ALL)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fun registerLocalIDLMethod(
|
|
78
|
+
clazz: Class<out IDLBridgeMethod>?,
|
|
79
|
+
scope: BridgePlatformType = BridgePlatformType.ALL
|
|
80
|
+
) {
|
|
81
|
+
pool.registerLocalIDLMethod(clazz, scope)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fun setBridgeContext(context: IBridgeContext) {
|
|
85
|
+
this.context = context
|
|
86
|
+
this.pool.setBridgeContext(context)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fun getBridge(bridgeContext: BridgeContext, bridgeName: String) : IDLBridgeMethod? {
|
|
90
|
+
val platform = BridgeContext.getPlatformByBridgeContext(bridgeContext)
|
|
91
|
+
return pool.getBridge(bridgeName, platform)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
override fun onRelease() {
|
|
95
|
+
pool.release()
|
|
96
|
+
isReleased = true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
override fun isReleased(): Boolean {
|
|
100
|
+
return isReleased
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private fun unWrapperParams(params: ReadableMap?) : ReadableMap? {
|
|
104
|
+
return params?.getMap("data") ?: params
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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.JavaOnlyMap
|
|
9
|
+
import com.lynx.react.bridge.ReadableMap
|
|
10
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
11
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeMethodCallback
|
|
12
|
+
import com.tiktok.sparkling.method.registry.core.IBridgeContext
|
|
13
|
+
import com.tiktok.sparkling.method.registry.core.IDLBridgeMethod
|
|
14
|
+
import com.tiktok.sparkling.method.registry.core.BridgePlatformType
|
|
15
|
+
import com.tiktok.sparkling.method.registry.core.interfaces.IPlatformDataProcessor
|
|
16
|
+
import com.tiktok.sparkling.method.registry.core.exception.IllegalInputParamException
|
|
17
|
+
import com.tiktok.sparkling.method.registry.core.exception.IllegalOperationException
|
|
18
|
+
import com.tiktok.sparkling.method.registry.core.exception.IllegalOutputParamException
|
|
19
|
+
import com.tiktok.sparkling.method.registry.api.processor.LynxPlatformDataProcessor
|
|
20
|
+
import com.tiktok.sparkling.method.registry.api.processor.WebPlatformDataProcessor
|
|
21
|
+
import com.tiktok.sparkling.method.registry.api.util.printStackString
|
|
22
|
+
import org.json.JSONObject
|
|
23
|
+
|
|
24
|
+
class JsonProcessor @JvmOverloads constructor(
|
|
25
|
+
bridge: IDLBridgeMethod,
|
|
26
|
+
data: JSONObject,
|
|
27
|
+
val platForm: BridgeCall.PlatForm = BridgeCall.PlatForm.Web
|
|
28
|
+
) : BaseProcessor<JSONObject>(bridge, data) {
|
|
29
|
+
var context: IBridgeContext? = null
|
|
30
|
+
override fun getPlatformType() =
|
|
31
|
+
BridgePlatformType.WEB
|
|
32
|
+
|
|
33
|
+
override val processor = WebPlatformDataProcessor().apply {
|
|
34
|
+
this@apply.context = this@JsonProcessor.context
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override fun onError(code: Int, message: String): JSONObject {
|
|
38
|
+
return JSONObject().apply {
|
|
39
|
+
put("code", code)
|
|
40
|
+
put("msg", message)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class ReadableMapProcessor(bridge: IDLBridgeMethod, data: ReadableMap) :
|
|
46
|
+
BaseProcessor<ReadableMap>(bridge, data) {
|
|
47
|
+
var context: IBridgeContext? = null
|
|
48
|
+
override fun getPlatformType() = BridgePlatformType.LYNX
|
|
49
|
+
override val processor = LynxPlatformDataProcessor().apply {
|
|
50
|
+
this@apply.context = this@ReadableMapProcessor.context
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override fun onError(code: Int, message: String): ReadableMap {
|
|
54
|
+
return JavaOnlyMap.from(hashMapOf<String, Any>().apply {
|
|
55
|
+
put("code", code)
|
|
56
|
+
put("msg", message)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
abstract class BaseProcessor<Input>(val bridge: IDLBridgeMethod, val data: Input) {
|
|
63
|
+
|
|
64
|
+
abstract fun getPlatformType(): BridgePlatformType
|
|
65
|
+
abstract val processor: IPlatformDataProcessor<Input>
|
|
66
|
+
fun handle(callback: IBridgeMethodCallback) {
|
|
67
|
+
try {
|
|
68
|
+
val map = processor.transformPlatformDataToMap(data, bridge::class.java)
|
|
69
|
+
if (map == null) {
|
|
70
|
+
callback.onBridgeResult(
|
|
71
|
+
onError(
|
|
72
|
+
IDLBridgeMethod.ANNOTATION_ERROR,
|
|
73
|
+
"processor.transformPlatformDataToMap failed"
|
|
74
|
+
)!!
|
|
75
|
+
)
|
|
76
|
+
} else {
|
|
77
|
+
bridge.realHandle(map, object : IDLBridgeMethod.Callback {
|
|
78
|
+
override fun invoke(data: Map<String, Any?>) {
|
|
79
|
+
val code =
|
|
80
|
+
(data[IDLBridgeMethod.PARAM_CODE] as? Int) ?: IDLBridgeMethod.SUCCESS
|
|
81
|
+
if (code != IDLBridgeMethod.SUCCESS) {
|
|
82
|
+
callback.onBridgeResult(
|
|
83
|
+
processor.transformMapToPlatformData(
|
|
84
|
+
data,
|
|
85
|
+
bridge::class.java
|
|
86
|
+
)!!
|
|
87
|
+
)
|
|
88
|
+
} else {
|
|
89
|
+
callback.onBridgeResult(
|
|
90
|
+
processor.transformMapToPlatformData(
|
|
91
|
+
data,
|
|
92
|
+
bridge::class.java
|
|
93
|
+
)!!
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, getPlatformType())
|
|
98
|
+
}
|
|
99
|
+
} catch (e: IllegalInputParamException) {
|
|
100
|
+
callback.onBridgeResult(onError(IDLBridgeMethod.INVALID_PARAM, e.toString())!!)
|
|
101
|
+
} catch (e: IllegalOutputParamException) {
|
|
102
|
+
callback.onBridgeResult(onError(IDLBridgeMethod.INVALID_RESULT, e.toString())!!)
|
|
103
|
+
} catch (e: IllegalOperationException) {
|
|
104
|
+
callback.onBridgeResult(
|
|
105
|
+
onError(
|
|
106
|
+
IDLBridgeMethod.ILLEGAL_OPERATION_ERROR,
|
|
107
|
+
e.toString()
|
|
108
|
+
)!!
|
|
109
|
+
)
|
|
110
|
+
} catch (e: Throwable) {
|
|
111
|
+
callback.onBridgeResult(onError(IDLBridgeMethod.UNKNOWN_ERROR, e.printStackString())!!)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
abstract fun onError(code: Int, message: String): Input
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
|
5
|
+
|
|
6
|
+
import com.lynx.react.bridge.PiperData
|
|
7
|
+
import org.json.JSONObject
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
internal fun PiperData.toJSONObject(): JSONObject {
|
|
13
|
+
return try {
|
|
14
|
+
when (this.dataType) {
|
|
15
|
+
PiperData.DataType.String.ordinal -> {
|
|
16
|
+
val rawData = this.rawData
|
|
17
|
+
if (rawData is String) {
|
|
18
|
+
JSONObject(rawData)
|
|
19
|
+
} else {
|
|
20
|
+
JSONObject()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
PiperData.DataType.Map.ordinal -> {
|
|
25
|
+
val rawData = this.rawData
|
|
26
|
+
if (rawData is Map<*, *>) {
|
|
27
|
+
JSONObject(rawData)
|
|
28
|
+
} else {
|
|
29
|
+
JSONObject()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
else -> {
|
|
34
|
+
JSONObject()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch (e: Exception) {
|
|
38
|
+
JSONObject()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
internal fun PiperData.stringify(): String {
|
|
43
|
+
return when (this.dataType) {
|
|
44
|
+
PiperData.DataType.String.ordinal -> {
|
|
45
|
+
this.rawData as? String
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
PiperData.DataType.Map.ordinal -> {
|
|
49
|
+
val rawData = this.rawData
|
|
50
|
+
if (rawData is Map<*, *>) {
|
|
51
|
+
JSONObject(rawData).toString()
|
|
52
|
+
} else {
|
|
53
|
+
null
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
else -> null
|
|
58
|
+
} ?: ""
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
internal fun Map<*, *>.containsPiperData(): Boolean {
|
|
62
|
+
this.forEach { (_, v) ->
|
|
63
|
+
if (v is PiperData) {
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
if (v is Map<*, *> && v.containsPiperData()) {
|
|
67
|
+
return true
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
@@ -0,0 +1,374 @@
|
|
|
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
|
+
package com.tiktok.sparkling.method.registry.api
|
|
6
|
+
|
|
7
|
+
import android.content.Context
|
|
8
|
+
import android.view.View
|
|
9
|
+
import com.lynx.tasm.LynxBackgroundRuntime
|
|
10
|
+
import com.lynx.tasm.LynxBackgroundRuntimeOptions
|
|
11
|
+
import com.lynx.tasm.LynxViewBuilder
|
|
12
|
+
import com.tiktok.sparkling.method.protocol.BridgeContext
|
|
13
|
+
import com.tiktok.sparkling.method.protocol.InnerBridge
|
|
14
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
15
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeResult
|
|
16
|
+
import com.tiktok.sparkling.method.protocol.handler.BridgeFactoryManager
|
|
17
|
+
import com.tiktok.sparkling.method.protocol.handler.BridgeThreadDispatcher
|
|
18
|
+
import com.tiktok.sparkling.method.protocol.impl.errors.JSBErrorReportModel
|
|
19
|
+
import com.tiktok.sparkling.method.protocol.impl.interceptor.BridgeMockInterceptor
|
|
20
|
+
import com.tiktok.sparkling.method.protocol.impl.monitor.BridgeSDKMonitor
|
|
21
|
+
import com.tiktok.sparkling.method.protocol.impl.monitor.IBridgeMonitor
|
|
22
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeCallback
|
|
23
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeLifeClient
|
|
24
|
+
import com.tiktok.sparkling.method.protocol.utils.LogUtils
|
|
25
|
+
import com.tiktok.sparkling.method.registry.core.BridgeContextWrapper
|
|
26
|
+
import com.tiktok.sparkling.method.registry.core.IBridgeContext
|
|
27
|
+
import com.tiktok.sparkling.method.registry.core.IDLBridgeMethod
|
|
28
|
+
import com.tiktok.sparkling.method.registry.core.IDLMethodRegistryCacheManager
|
|
29
|
+
import com.tiktok.sparkling.method.registry.core.JSEventDelegate
|
|
30
|
+
import com.tiktok.sparkling.method.registry.core.SparklingBridgeManager
|
|
31
|
+
import com.tiktok.sparkling.method.registry.core.SparklingBridgeManager.DEFAULT_NAMESPACE
|
|
32
|
+
import com.tiktok.sparkling.method.registry.core.BridgePlatformType
|
|
33
|
+
import com.tiktok.sparkling.method.registry.core.interfaces.IContainerIDProvider
|
|
34
|
+
import com.tiktok.sparkling.method.registry.core.interfaces.IReleasable
|
|
35
|
+
import com.tiktok.sparkling.method.registry.api.util.BridgeProtocolConstants
|
|
36
|
+
import com.tiktok.sparkling.method.registry.api.util.log
|
|
37
|
+
import org.json.JSONObject
|
|
38
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
39
|
+
import java.util.concurrent.CopyOnWriteArrayList
|
|
40
|
+
|
|
41
|
+
class SparklingBridge : IReleasable {
|
|
42
|
+
|
|
43
|
+
internal val innerBridge: InnerBridge = InnerBridge()
|
|
44
|
+
private val closedSubscribers = mutableListOf<Pair<String, JSONObject?>>()
|
|
45
|
+
private val TAG = "SparklingBridge"
|
|
46
|
+
private val bridgeSdkContext = BridgeContextWrapper()
|
|
47
|
+
|
|
48
|
+
companion object {
|
|
49
|
+
|
|
50
|
+
var bridgeFactoryManager: BridgeFactoryManager? = null
|
|
51
|
+
|
|
52
|
+
private var _bridgeThreadDispatcher: BridgeThreadDispatcher? = null
|
|
53
|
+
var bridgeThreadDispatcher: BridgeThreadDispatcher
|
|
54
|
+
get() = _bridgeThreadDispatcher ?: BridgeThreadDispatcher().also { _bridgeThreadDispatcher = it }
|
|
55
|
+
set(value) { _bridgeThreadDispatcher = value }
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Whether the host is a debug environment
|
|
59
|
+
*/
|
|
60
|
+
var isDebugEnv = false
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* JSB SDK Error report block jsb list.
|
|
64
|
+
* if you set jsb name here, it's jsb error message will not reported.
|
|
65
|
+
*/
|
|
66
|
+
val jsbErrorReportBlockList = ArrayList<String>()
|
|
67
|
+
|
|
68
|
+
val cancelCallbackConfig: CancelCallbackConfig =
|
|
69
|
+
CancelCallbackConfig().apply { enable = false }
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* switch enableToast to true will invoke a toast when jsb callback with an error code
|
|
74
|
+
*/
|
|
75
|
+
private var enableToast = false
|
|
76
|
+
fun enableToast(isEnable: Boolean) {
|
|
77
|
+
enableToast = isEnable
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fun getToastSetting(): Boolean {
|
|
81
|
+
return enableToast
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fun attachInitListener(listener: BridgeInitListener) {
|
|
85
|
+
BridgeManager.attachInitListener(listener)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
fun getErrorReportModel(): JSBErrorReportModel {
|
|
92
|
+
return innerBridge.getBridgeContext().errorReportModel
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* prepareLynxJSRuntime
|
|
97
|
+
* because of there is no lynxjsruntime yet, so we need a new way to bind lynxjsruntime
|
|
98
|
+
*/
|
|
99
|
+
fun prepareLynxJSRuntime(
|
|
100
|
+
containerId: String,
|
|
101
|
+
options: LynxBackgroundRuntimeOptions,
|
|
102
|
+
context: Context
|
|
103
|
+
) {
|
|
104
|
+
BridgeManager.insert(containerId, this)
|
|
105
|
+
innerBridge.initLynxJSRuntime(containerId, options, context, this)
|
|
106
|
+
bridgeSdkContext.registerWeakObject(
|
|
107
|
+
BridgeContext::class.java,
|
|
108
|
+
innerBridge.getBridgeContext()
|
|
109
|
+
)
|
|
110
|
+
bridgeSdkContext.setContainerID(containerId)
|
|
111
|
+
// bridgeSdkContext.setView(view)
|
|
112
|
+
bridgeSdkContext.setBridge(this)
|
|
113
|
+
bridgeSdkContext.setJSEventDelegate(object : JSEventDelegate {
|
|
114
|
+
override fun sendJSEvent(eventName: String, params: JSONObject?) {
|
|
115
|
+
sendJSRuntimeEvent(eventName, params)
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
bridgeSdkContext.registerObject(
|
|
119
|
+
IDLBridgeMethod.JSEventDelegate::class.java,
|
|
120
|
+
object : IDLBridgeMethod.JSEventDelegate {
|
|
121
|
+
override fun sendJSEvent(eventName: String, params: Map<String, Any?>?) {
|
|
122
|
+
sendJSRuntimeEvent(
|
|
123
|
+
eventName,
|
|
124
|
+
params?.let { Utils.mapToJSON(params) } ?: JSONObject())
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
bridgeSdkContext.registerObject(
|
|
129
|
+
IContainerIDProvider::class.java,
|
|
130
|
+
object : IContainerIDProvider {
|
|
131
|
+
override fun provideContainerID(): String? {
|
|
132
|
+
return containerId
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
val handler = getBridgeContext().defaultCallHandler
|
|
136
|
+
handler.setBridgeContext(bridgeSdkContext)
|
|
137
|
+
innerBridge.registerHandler(handler)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* bind lynxjsruntime
|
|
142
|
+
*/
|
|
143
|
+
fun bindLynxJSRuntime(lynxBackgroundRuntime: LynxBackgroundRuntime) {
|
|
144
|
+
innerBridge.bindLynxJSRuntime(lynxBackgroundRuntime)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
fun sendJSRuntimeEvent(eventName: String, jsonObject: JSONObject?) {
|
|
148
|
+
innerBridge.sendJSRuntimeEvent(eventName, jsonObject)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The first step of protocol layer initialization
|
|
154
|
+
* @jsBridgeProtocols bridge protocol for control injection
|
|
155
|
+
* @see BridgeProtocolConstants specific protocol constant reference
|
|
156
|
+
*/
|
|
157
|
+
fun init(view: View, containerId: String?, jsBridgeProtocols: Int) {
|
|
158
|
+
BridgeManager.insert(view, this)
|
|
159
|
+
innerBridge.init(view, containerId, jsBridgeProtocols, this)
|
|
160
|
+
bridgeSdkContext.registerWeakObject(
|
|
161
|
+
BridgeContext::class.java,
|
|
162
|
+
innerBridge.getBridgeContext()
|
|
163
|
+
)
|
|
164
|
+
bridgeSdkContext.setContainerID(containerId)
|
|
165
|
+
bridgeSdkContext.setView(view)
|
|
166
|
+
bridgeSdkContext.setBridge(this)
|
|
167
|
+
bridgeSdkContext.setJSEventDelegate(object : JSEventDelegate {
|
|
168
|
+
override fun sendJSEvent(eventName: String, params: JSONObject?) {
|
|
169
|
+
sendEvent(eventName, params)
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
bridgeSdkContext.registerObject(
|
|
173
|
+
IDLBridgeMethod.JSEventDelegate::class.java,
|
|
174
|
+
object : IDLBridgeMethod.JSEventDelegate {
|
|
175
|
+
override fun sendJSEvent(eventName: String, params: Map<String, Any?>?) {
|
|
176
|
+
sendEvent(eventName, params?.let { Utils.mapToJSON(params) } ?: JSONObject())
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
bridgeSdkContext.registerObject(
|
|
181
|
+
IContainerIDProvider::class.java,
|
|
182
|
+
object : IContainerIDProvider {
|
|
183
|
+
override fun provideContainerID(): String? {
|
|
184
|
+
return containerId
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
val handler = getBridgeContext().defaultCallHandler
|
|
188
|
+
handler.setBridgeContext(bridgeSdkContext)
|
|
189
|
+
innerBridge.registerHandler(handler)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
fun bindWithBusinessNamespace(namespace: String) {
|
|
194
|
+
getBridgeContext().businessCallHandler = BusinessCallHandler(namespace).apply {
|
|
195
|
+
setBridgeContext(bridgeSdkContext)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* only for who has call bindWithBusinessNamespace to register it's unique IDLMethod
|
|
201
|
+
*/
|
|
202
|
+
fun registerBusinessIDLMethod(
|
|
203
|
+
clazz: Class<out IDLBridgeMethod>,
|
|
204
|
+
scope: BridgePlatformType = BridgePlatformType.ALL
|
|
205
|
+
) {
|
|
206
|
+
getBridgeContext().getNamespace()?.let {
|
|
207
|
+
getBridgeContext().businessCallHandler?.registerMethod(clazz, scope)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
fun registerIDLMethod(
|
|
212
|
+
clazz: Class<out IDLBridgeMethod>?, scope: BridgePlatformType = BridgePlatformType.ALL,
|
|
213
|
+
namespace:String = DEFAULT_NAMESPACE
|
|
214
|
+
) {
|
|
215
|
+
SparklingBridgeManager.registerIDLMethod(clazz, scope, namespace)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
fun isBusinessIDLMethodExists(
|
|
219
|
+
name: String,
|
|
220
|
+
platformType: BridgePlatformType = BridgePlatformType.ALL
|
|
221
|
+
): Boolean {
|
|
222
|
+
if (getBridgeContext().getNamespace().isNullOrEmpty()) {
|
|
223
|
+
return false
|
|
224
|
+
}
|
|
225
|
+
val businessHandler = getBridgeContext().businessCallHandler ?: return false
|
|
226
|
+
return businessHandler.isMethodExists(name, platformType)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
fun registerLocalIDLMethod(
|
|
230
|
+
clazz: Class<out IDLBridgeMethod>?,
|
|
231
|
+
scope: BridgePlatformType = BridgePlatformType.ALL
|
|
232
|
+
) {
|
|
233
|
+
innerBridge.getBridgeContext().defaultCallHandler.registerLocalIDLMethod(clazz, scope)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
fun getBridgeSDKContext(): IBridgeContext {
|
|
237
|
+
return bridgeSdkContext
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// @Deprecated("don't use this method")
|
|
241
|
+
fun getBridgeContext(): BridgeContext {
|
|
242
|
+
return innerBridge.getBridgeContext()
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
fun registerMonitor(monitor: IBridgeMonitor) {
|
|
246
|
+
innerBridge.registerMonitor(monitor)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
fun registerJSBMockInterceptor(interceptor: BridgeMockInterceptor) {
|
|
250
|
+
innerBridge.getBridgeContext().jsbMockInterceptor = interceptor
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
fun initSDKMonitor(context: Context, appInfo: BridgeSDKMonitor.APPInfo4Monitor) {
|
|
254
|
+
InnerBridge.initSDKMonitor(context, appInfo)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
fun registerLynxModule(builder: LynxViewBuilder, containerId: String?) {
|
|
258
|
+
innerBridge.registerLynxModule(builder, containerId)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
fun registerIBridgeLifeClient(bridgeLifeClient: IBridgeLifeClient) {
|
|
262
|
+
innerBridge.registerIBridgeLifeClient(bridgeLifeClient)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
fun sendEvent(event: String, data: JSONObject?) {
|
|
266
|
+
innerBridge.sendEvent(event, data)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
fun addClosedEventObserver(bridgeNames: List<String>, params: List<JSONObject?>) {
|
|
270
|
+
bridgeNames.forEachIndexed { index, s ->
|
|
271
|
+
this.closedSubscribers.add(Pair(bridgeNames[index], params[index]))
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
override fun release() {
|
|
276
|
+
dealWithCloseEvent()
|
|
277
|
+
innerBridge.getBridgeContext().defaultCallHandler.onRelease()
|
|
278
|
+
innerBridge.getBridgeContext().businessCallHandler?.onRelease()
|
|
279
|
+
innerBridge.getBridgeContext().errorReportModel.putJsbExtension("release", "true")
|
|
280
|
+
BridgeManager.remove(this)
|
|
281
|
+
bridgeSdkContext.containerID?.let {
|
|
282
|
+
IDLMethodRegistryCacheManager.unregisterIDLMethodRegistryCache(
|
|
283
|
+
it
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private fun dealWithCloseEvent() {
|
|
289
|
+
closedSubscribers.forEach { pair ->
|
|
290
|
+
val curPlatform = when (getBridgeContext().platform) {
|
|
291
|
+
BridgePlatformType.LYNX -> {
|
|
292
|
+
BridgeCall.PlatForm.Lynx
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
BridgePlatformType.WEB -> {
|
|
296
|
+
BridgeCall.PlatForm.Web
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
else -> {
|
|
300
|
+
BridgeCall.PlatForm.Other
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
getBridgeContext()?.dispatcher?.onDispatchBridgeMethod(
|
|
305
|
+
BridgeCall(getBridgeContext()).apply {
|
|
306
|
+
bridgeName = pair.first
|
|
307
|
+
params = pair.second
|
|
308
|
+
nameSpace = "DEFAULT"
|
|
309
|
+
platform = curPlatform
|
|
310
|
+
url = ""
|
|
311
|
+
},
|
|
312
|
+
object : IBridgeCallback {
|
|
313
|
+
override fun onBridgeResult(
|
|
314
|
+
result: BridgeResult, call: BridgeCall?,
|
|
315
|
+
monitorBuilder: BridgeSDKMonitor.MonitorModel.Builder?
|
|
316
|
+
) {
|
|
317
|
+
LogUtils.d(
|
|
318
|
+
TAG,
|
|
319
|
+
"dealWithCloseEvent, bridgeName: ${pair.first}}, result: ${result.toString()}"
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
getBridgeContext()!!,
|
|
324
|
+
null
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
internal object BridgeManager {
|
|
331
|
+
private val map: ConcurrentHashMap<Int, SparklingBridge> = ConcurrentHashMap()
|
|
332
|
+
|
|
333
|
+
// private val containerIdMap : WeakValueConcurrentHashMap<String, SparklingBridge> = WeakValueConcurrentHashMap()
|
|
334
|
+
private val listeners = CopyOnWriteArrayList<BridgeInitListener>()
|
|
335
|
+
|
|
336
|
+
fun attachInitListener(listener: BridgeInitListener) = listeners.add(listener)
|
|
337
|
+
|
|
338
|
+
fun insert(webView: View, sparklingBridge: SparklingBridge) {
|
|
339
|
+
map[webView.hashCode()] = sparklingBridge
|
|
340
|
+
map.values.log()
|
|
341
|
+
listeners.forEach {
|
|
342
|
+
it.onInit(webView, sparklingBridge)
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
fun getSparklingBridge(view: View): SparklingBridge? {
|
|
347
|
+
return map[view.hashCode()]
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
fun remove(bridge: SparklingBridge) {
|
|
351
|
+
val find = map.toList().find { it.second == bridge }
|
|
352
|
+
if (find != null) {
|
|
353
|
+
map.remove(find.first)
|
|
354
|
+
}
|
|
355
|
+
map.values.log()
|
|
356
|
+
// containerIdMap.remove(bridge.getBridgeSDKContext().containerID)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* create this function for lynx runtime JSB
|
|
361
|
+
* wait hdt to support this feature
|
|
362
|
+
* @param containerId
|
|
363
|
+
* @return
|
|
364
|
+
*/
|
|
365
|
+
fun insert(containerId: String, sparklingBridge: SparklingBridge) {
|
|
366
|
+
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
interface BridgeInitListener {
|
|
372
|
+
fun onInit(view: View, sparklingBridge: SparklingBridge)
|
|
373
|
+
fun onInit(containerID: String, sparklingBridge: SparklingBridge) {}
|
|
374
|
+
}
|