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,134 @@
|
|
|
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
|
|
7
|
+
|
|
8
|
+
import android.content.Context
|
|
9
|
+
import android.view.View
|
|
10
|
+
import android.webkit.WebView
|
|
11
|
+
import com.tiktok.sparkling.method.registry.core.BridgePlatformType
|
|
12
|
+
import com.tiktok.sparkling.method.registry.api.SparklingBridge
|
|
13
|
+
import com.lynx.tasm.LynxBackgroundRuntime
|
|
14
|
+
import com.lynx.tasm.LynxBackgroundRuntimeOptions
|
|
15
|
+
import com.lynx.tasm.LynxView
|
|
16
|
+
import com.lynx.tasm.LynxViewBuilder
|
|
17
|
+
import com.tiktok.sparkling.method.protocol.handler.BridgeDispatcher
|
|
18
|
+
import com.tiktok.sparkling.method.protocol.impl.lynx.LynxBridgeProtocol
|
|
19
|
+
import com.tiktok.sparkling.method.protocol.impl.lynx.LynxViewImpl
|
|
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.IBridgeHandler
|
|
23
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeLifeClient
|
|
24
|
+
import org.json.JSONObject
|
|
25
|
+
import java.util.concurrent.atomic.AtomicBoolean
|
|
26
|
+
|
|
27
|
+
internal class InnerBridge {
|
|
28
|
+
private var mBridgeContext = BridgeContext()
|
|
29
|
+
|
|
30
|
+
companion object {
|
|
31
|
+
private val hasInitMonitor: AtomicBoolean = AtomicBoolean(false)
|
|
32
|
+
var globalMonitor : BridgeSDKMonitor? = null
|
|
33
|
+
fun initSDKMonitor(context: Context, appInfo: BridgeSDKMonitor.APPInfo4Monitor) {
|
|
34
|
+
if (hasInitMonitor.compareAndSet(false, true))
|
|
35
|
+
globalMonitor = BridgeSDKMonitor(context, appInfo)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
init {
|
|
40
|
+
mBridgeContext.dispatcher = BridgeDispatcher()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* use this to pass the bridge to mBridgeContext, to and you can use the custom auth ability.
|
|
45
|
+
*/
|
|
46
|
+
fun init(view: View, containerId: String?, jsBridgeProtocols: Int? = null, bridge: SparklingBridge) {
|
|
47
|
+
mBridgeContext.sparklingBridge = bridge
|
|
48
|
+
init(view, containerId, jsBridgeProtocols)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fun init(view: View, containerId: String?, jsBridgeProtocols: Int? = null) {
|
|
52
|
+
if (view is LynxView) {
|
|
53
|
+
mBridgeContext.lynxView = view
|
|
54
|
+
mBridgeContext.platform = BridgePlatformType.LYNX
|
|
55
|
+
mBridgeContext.registerProtocol(LynxBridgeProtocol(mBridgeContext))
|
|
56
|
+
} else if (view is WebView) {
|
|
57
|
+
// TODO
|
|
58
|
+
}
|
|
59
|
+
mBridgeContext.protocols.forEach {
|
|
60
|
+
it.init()
|
|
61
|
+
}
|
|
62
|
+
mBridgeContext.containerId = containerId
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fun initLynxJSRuntime(containerId: String, options: LynxBackgroundRuntimeOptions, context: Context, sparklingBridge: SparklingBridge) {
|
|
66
|
+
mBridgeContext.sparklingBridge = sparklingBridge
|
|
67
|
+
mBridgeContext.platform = BridgePlatformType.LYNX
|
|
68
|
+
mBridgeContext.registerProtocol(LynxBridgeProtocol(mBridgeContext))
|
|
69
|
+
mBridgeContext.protocols.forEach {
|
|
70
|
+
it.init()
|
|
71
|
+
}
|
|
72
|
+
registerLynxJSRuntimeModule(options, containerId)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private fun registerLynxJSRuntimeModule(options: LynxBackgroundRuntimeOptions, containerId: String?) {
|
|
76
|
+
LynxViewImpl(mBridgeContext).initJSRuntime(options)
|
|
77
|
+
mBridgeContext.containerId = containerId
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fun registerIBridgeLifeClient(bridgeLifeClient: IBridgeLifeClient) {
|
|
81
|
+
mBridgeContext.registerIBridgeLifeClient(bridgeLifeClient)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
fun registerLynxModule(builder: LynxViewBuilder, containerId: String?) {
|
|
86
|
+
LynxViewImpl(mBridgeContext).apply {
|
|
87
|
+
init(builder)
|
|
88
|
+
}
|
|
89
|
+
mBridgeContext.containerId = containerId
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
fun registerHandler(handler: IBridgeHandler) {
|
|
93
|
+
mBridgeContext.dispatcher?.registerHandler(handler)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fun getBridgeContext(): BridgeContext {
|
|
97
|
+
return mBridgeContext
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
fun registerMonitor(monitor: IBridgeMonitor) {
|
|
101
|
+
mBridgeContext.monitor.add(monitor)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fun sendEvent(event: String, data: JSONObject?) {
|
|
105
|
+
mBridgeContext.monitor.forEach {
|
|
106
|
+
runCatching {
|
|
107
|
+
it.onBridgeEvent(event, data)
|
|
108
|
+
}.onFailure {
|
|
109
|
+
it.printStackTrace()
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
mBridgeContext.protocols.forEach {
|
|
113
|
+
it.sendEvent(event,data)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fun sendJSRuntimeEvent(event: String, data: JSONObject?) {
|
|
118
|
+
mBridgeContext.monitor.forEach {
|
|
119
|
+
runCatching {
|
|
120
|
+
it.onBridgeEvent(event, data)
|
|
121
|
+
}.onFailure {
|
|
122
|
+
it.printStackTrace()
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
mBridgeContext.protocols.forEach {
|
|
126
|
+
it.sendJSRuntimeEvent(event,data)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fun bindLynxJSRuntime(lynxBackgroundRuntime: LynxBackgroundRuntime) {
|
|
131
|
+
mBridgeContext.lynxBackgroundRuntime = lynxBackgroundRuntime
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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.protocol.entity
|
|
5
|
+
|
|
6
|
+
import com.tiktok.sparkling.method.protocol.BridgeContext
|
|
7
|
+
import com.tiktok.sparkling.method.protocol.impl.monitor.BridgeSDKMonitor
|
|
8
|
+
import com.tiktok.sparkling.method.registry.core.model.context.BridgeCallThreadTypeEnum
|
|
9
|
+
import com.tiktok.sparkling.method.registry.api.BridgeSettings
|
|
10
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
11
|
+
import com.tiktok.sparkling.method.protocol.impl.errors.JSBErrorReportModel
|
|
12
|
+
import com.tiktok.sparkling.method.protocol.impl.lifecycle.fe.FeCallMonitorModel
|
|
13
|
+
import org.json.JSONObject
|
|
14
|
+
|
|
15
|
+
class BridgeCall(val context: BridgeContext) {
|
|
16
|
+
|
|
17
|
+
companion object {
|
|
18
|
+
const val DEFAULT_NAMESPACE = "DEFAULT"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
enum class PlatForm {
|
|
22
|
+
Lynx, Web, Other,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var callbackId = ""
|
|
27
|
+
var bridgeName = ""
|
|
28
|
+
var url = ""
|
|
29
|
+
var msgType = ""
|
|
30
|
+
var params: Any? = null
|
|
31
|
+
var sdkVersion = ""
|
|
32
|
+
var nameSpace = ""
|
|
33
|
+
var frameUrl = ""
|
|
34
|
+
var timestamp: Long = -1
|
|
35
|
+
var rawReq = ""
|
|
36
|
+
var hitBusinessHandler: Boolean = false
|
|
37
|
+
lateinit var platform: PlatForm
|
|
38
|
+
|
|
39
|
+
// when bridgeCallThreadType == null, it means bridgeCallThreadType no one set, so just use the default thread.
|
|
40
|
+
// the default thread in jsbsdk will be same as the main thread
|
|
41
|
+
var bridgeCallThreadType: BridgeCallThreadTypeEnum? = null
|
|
42
|
+
|
|
43
|
+
var cancelCallBack: CancelCallbackType = CancelCallbackType.NONE
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* force on instance sdk error
|
|
47
|
+
*/
|
|
48
|
+
val jsbSDKErrorReportModel: JSBErrorReportModel = JSBErrorReportModel()
|
|
49
|
+
|
|
50
|
+
//for lifeClient
|
|
51
|
+
internal var callBeginTime: Long = 0
|
|
52
|
+
// var protocolVersion: Int = ProtocolVersion.UNKNOWN
|
|
53
|
+
internal var monitorBuilder: BridgeSDKMonitor.MonitorModel.Builder? = null
|
|
54
|
+
internal var invocation: String = "" //same as rawReq
|
|
55
|
+
internal var beginCreateCallBaskMsgTime: Long = 0
|
|
56
|
+
internal var endCreateCallBaskMsgTime: Long = 0
|
|
57
|
+
internal var callbackMsg: String? = null
|
|
58
|
+
internal var lynxCallbackMap: JavaOnlyMap? = null
|
|
59
|
+
internal var isInMainThread: Boolean = true
|
|
60
|
+
internal var feCallMonitorModel = FeCallMonitorModel()
|
|
61
|
+
internal var jsbEngine: String = ""
|
|
62
|
+
|
|
63
|
+
//for call to get invocation's jsonObject
|
|
64
|
+
internal var invocationJson: JSONObject? = null
|
|
65
|
+
|
|
66
|
+
override fun toString(): String {
|
|
67
|
+
if (BridgeSettings.bridgeCallToStringOptimization) {
|
|
68
|
+
return "BridgeCall(callbackId='$callbackId', bridgeName='$bridgeName')"
|
|
69
|
+
} else {
|
|
70
|
+
return "BridgeCall(callbackId='$callbackId', bridgeName='$bridgeName', hitBusinessHandler='$hitBusinessHandler', url='$url', msgType='$msgType', params='$params', sdkVersion=$sdkVersion, nameSpace='$nameSpace', frameUrl='$frameUrl')"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
enum class CancelCallbackType {
|
|
78
|
+
NONE, ALL, ONLY_SUCCESS
|
|
79
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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.entity
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.protocol.utils.BridgeConverter
|
|
9
|
+
import com.tiktok.sparkling.method.registry.core.IDLBridgeMethod
|
|
10
|
+
import com.tiktok.sparkling.method.registry.api.SparklingBridge
|
|
11
|
+
import com.tiktok.sparkling.method.registry.api.Utils
|
|
12
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
13
|
+
import org.json.JSONObject
|
|
14
|
+
|
|
15
|
+
class BridgeResult(val parcel: Any) {
|
|
16
|
+
|
|
17
|
+
override fun toString(): String {
|
|
18
|
+
if (SparklingBridge.isDebugEnv) {
|
|
19
|
+
return toJSONObject().toString()
|
|
20
|
+
} else {
|
|
21
|
+
return ""
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
companion object {
|
|
26
|
+
fun toJsonResult(code: Int, msg: String = "", data: JSONObject? = null): BridgeResult {
|
|
27
|
+
val json = JSONObject()
|
|
28
|
+
json.apply {
|
|
29
|
+
put("code", code)
|
|
30
|
+
put("msg", msg)
|
|
31
|
+
put("data", data)
|
|
32
|
+
}
|
|
33
|
+
return BridgeResult(json)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fun toJSONObject(): JSONObject {
|
|
38
|
+
if (parcel is JSONObject) return parcel
|
|
39
|
+
if (parcel is JavaOnlyMap) {
|
|
40
|
+
return BridgeConverter.revertJavaOnlyMap2JSONObject(parcel)
|
|
41
|
+
}
|
|
42
|
+
if (parcel is Map<*, *>) {
|
|
43
|
+
return Utils.mapToJSON(parcel as Map<String, Any?>)
|
|
44
|
+
}
|
|
45
|
+
return JSONObject()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fun isSuccessResult(): Boolean {
|
|
49
|
+
try {
|
|
50
|
+
if (parcel is JSONObject) return parcel.optInt("code", IDLBridgeMethod.FAIL) == IDLBridgeMethod.SUCCESS
|
|
51
|
+
if (parcel is Map<*, *>) return parcel.get("code") == IDLBridgeMethod.SUCCESS
|
|
52
|
+
if (parcel is JavaOnlyMap) return parcel.getInt("code") == IDLBridgeMethod.SUCCESS
|
|
53
|
+
return false
|
|
54
|
+
} catch (e: Exception) {
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fun toJSONObject(call: BridgeCall?): JSONObject {
|
|
60
|
+
return (if (parcel is JSONObject) {
|
|
61
|
+
parcel
|
|
62
|
+
} else if (parcel is Map<*, *>) {
|
|
63
|
+
Utils.mapToJSON(parcel as Map<String, Any?>)
|
|
64
|
+
} else if (parcel is JavaOnlyMap) {
|
|
65
|
+
BridgeConverter.revertJavaOnlyMap2JSONObject(parcel)
|
|
66
|
+
} else JSONObject())
|
|
67
|
+
}
|
|
68
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcher.kt
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
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.handler
|
|
7
|
+
|
|
8
|
+
import android.os.Handler
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import android.widget.Toast
|
|
11
|
+
import com.tiktok.sparkling.method.protocol.BridgeContext
|
|
12
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
13
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeResult
|
|
14
|
+
import com.tiktok.sparkling.method.protocol.impl.monitor.BridgeSDKMonitor
|
|
15
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeCallback
|
|
16
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeHandler
|
|
17
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeMethodCallback
|
|
18
|
+
import com.tiktok.sparkling.method.protocol.utils.BridgeConstants
|
|
19
|
+
import com.tiktok.sparkling.method.protocol.utils.LogUtils
|
|
20
|
+
import com.tiktok.sparkling.method.registry.core.IDLBridgeMethod
|
|
21
|
+
import com.tiktok.sparkling.method.registry.api.SparklingBridge
|
|
22
|
+
import com.tiktok.sparkling.method.registry.api.SparklingBridge.Companion.getToastSetting
|
|
23
|
+
import org.json.JSONObject
|
|
24
|
+
|
|
25
|
+
class BridgeDispatcher {
|
|
26
|
+
companion object {
|
|
27
|
+
val TAG = "BridgeDispatcher"
|
|
28
|
+
val handler = Handler(Looper.getMainLooper())
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private var bridgeHandler: IBridgeHandler? = null
|
|
32
|
+
|
|
33
|
+
fun registerHandler(handler: IBridgeHandler) {
|
|
34
|
+
bridgeHandler = handler
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@JvmOverloads
|
|
38
|
+
fun onDispatchBridgeMethod(
|
|
39
|
+
call: BridgeCall,
|
|
40
|
+
callback: IBridgeCallback,
|
|
41
|
+
context: BridgeContext,
|
|
42
|
+
monitorBuilder: BridgeSDKMonitor.MonitorModel.Builder? = null
|
|
43
|
+
) {
|
|
44
|
+
if (context.jsbMockInterceptor != null) {
|
|
45
|
+
if (!shouldInvokeResult(context, call, callback)) {
|
|
46
|
+
val bridgeCall = context.jsbMockInterceptor!!.interceptBridgeCall(call)
|
|
47
|
+
realDispatchBridgeMethod(bridgeCall, callback, context, monitorBuilder)
|
|
48
|
+
}
|
|
49
|
+
} else realDispatchBridgeMethod(call, callback, context, monitorBuilder)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private fun shouldInvokeResult(
|
|
53
|
+
context: BridgeContext,
|
|
54
|
+
call: BridgeCall,
|
|
55
|
+
callback: IBridgeCallback
|
|
56
|
+
): Boolean {
|
|
57
|
+
val result = context.jsbMockInterceptor!!.invokeBridgeResult(call)
|
|
58
|
+
result?.let {
|
|
59
|
+
callback.onBridgeResult(it, call, null)
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private fun realDispatchBridgeMethod(
|
|
66
|
+
call: BridgeCall,
|
|
67
|
+
callback: IBridgeCallback,
|
|
68
|
+
context: BridgeContext,
|
|
69
|
+
monitorBuilder: BridgeSDKMonitor.MonitorModel.Builder?
|
|
70
|
+
) {
|
|
71
|
+
LogUtils.d(TAG, "realDispatchBridgeMethod: ${Thread.currentThread()} and call is \n$call")
|
|
72
|
+
|
|
73
|
+
SparklingBridge.bridgeFactoryManager?.checkAndInitBridge(context, call)
|
|
74
|
+
|
|
75
|
+
val client = context.bridgeClient
|
|
76
|
+
client.onBridgeDispatched(call)
|
|
77
|
+
val result = client.shouldInterceptRequest(call)
|
|
78
|
+
|
|
79
|
+
if (result != null && (
|
|
80
|
+
result.toJSONObject()
|
|
81
|
+
.optInt("code") == BridgeConstants.ERROR_BRIDGE_NO_AUTHORITY)
|
|
82
|
+
) {
|
|
83
|
+
client.onBridgeCallback()
|
|
84
|
+
callback.onBridgeResult(
|
|
85
|
+
context.jsbMockInterceptor?.interceptBridgeResult(call, result) ?: result,
|
|
86
|
+
call,
|
|
87
|
+
monitorBuilder
|
|
88
|
+
)
|
|
89
|
+
if (getToastSetting()) toastJsbError(call, result.toJSONObject(), context)
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
val shouldHandleBridgeCallResultModel =
|
|
94
|
+
context.bridgeLifeClientImp.shouldHandleBridgeCall(call, context)
|
|
95
|
+
if (!shouldHandleBridgeCallResultModel.shouldHandleBridgeCall) {
|
|
96
|
+
callback.onBridgeResult(
|
|
97
|
+
BridgeResult.toJsonResult(
|
|
98
|
+
IDLBridgeMethod.BRIDGE_CALL_BE_INTERCEPTED,
|
|
99
|
+
IDLBridgeMethod.BRIDGE_CALL_BE_INTERCEPTED_MSG + ", reason: " + shouldHandleBridgeCallResultModel.reason,
|
|
100
|
+
null
|
|
101
|
+
),
|
|
102
|
+
call,
|
|
103
|
+
monitorBuilder
|
|
104
|
+
)
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
val callbackHandler = object : IBridgeMethodCallback {
|
|
109
|
+
override fun onBridgeResult(parcel: Any) {
|
|
110
|
+
client.onBridgeCallback()
|
|
111
|
+
val result =
|
|
112
|
+
context.jsbMockInterceptor?.interceptBridgeResult(call, BridgeResult(parcel))
|
|
113
|
+
?: BridgeResult(parcel)
|
|
114
|
+
callback.onBridgeResult(result, call, monitorBuilder)
|
|
115
|
+
if (getToastSetting()) toastJsbError(call, result.toJSONObject(), context)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (context.shouldHandleWithBusinessHandler(call)) {
|
|
120
|
+
call.hitBusinessHandler = true
|
|
121
|
+
context.businessCallHandler!!.handle(context, call, callbackHandler)
|
|
122
|
+
LogUtils.d(
|
|
123
|
+
TAG,
|
|
124
|
+
"[JSBHit] Business JSB Handler(${context.businessCallHandler?.nameSpace}), $call"
|
|
125
|
+
)
|
|
126
|
+
} else {
|
|
127
|
+
call.hitBusinessHandler = false
|
|
128
|
+
bridgeHandler!!.handle(context, call, callbackHandler)
|
|
129
|
+
LogUtils.d(TAG, "[JSBHit] Default JSB Handler, $call")
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fun handleRawJSBCall(call: BridgeCall, context: BridgeContext, callback: IBridgeCallback) {
|
|
134
|
+
runCatching {
|
|
135
|
+
bridgeHandler?.handle(context, call, object : IBridgeMethodCallback {
|
|
136
|
+
override fun onBridgeResult(parcel: Any) {
|
|
137
|
+
callback.onBridgeResult(BridgeResult(parcel), call, null)
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
}.onFailure {
|
|
141
|
+
it.printStackTrace()
|
|
142
|
+
LogUtils.i(TAG, "handleRawJSBCall ${call.bridgeName} fail, msg: ${it.message}")
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private fun toastJsbError(call: BridgeCall, json: JSONObject, context: BridgeContext) {
|
|
147
|
+
val appContext = context.lynxView?.context
|
|
148
|
+
appContext?.let {
|
|
149
|
+
handler.post {
|
|
150
|
+
if (json.length() == 0) {
|
|
151
|
+
Toast.makeText(
|
|
152
|
+
it,
|
|
153
|
+
"bridgeName: ${call.bridgeName}, callback info is null, check it!",
|
|
154
|
+
Toast.LENGTH_SHORT
|
|
155
|
+
).show()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
val code = json.optInt("code", -2345)
|
|
159
|
+
if (code != -1234 && code != BridgeConstants.BRIDGE_CALL_SUCCESS) {
|
|
160
|
+
when (code) {
|
|
161
|
+
BridgeConstants.BRIDGE_CALL_FAIL ->
|
|
162
|
+
Toast.makeText(
|
|
163
|
+
it,
|
|
164
|
+
"${call.bridgeName}, code=$code, bridge call fail",
|
|
165
|
+
Toast.LENGTH_SHORT
|
|
166
|
+
).show()
|
|
167
|
+
|
|
168
|
+
BridgeConstants.ERROR_BRIDGE_NO_AUTHORITY ->
|
|
169
|
+
Toast.makeText(
|
|
170
|
+
it,
|
|
171
|
+
"${call.bridgeName}, code=$code, no authority",
|
|
172
|
+
Toast.LENGTH_SHORT
|
|
173
|
+
).show()
|
|
174
|
+
|
|
175
|
+
BridgeConstants.BRIDGE_NOT_FOUND ->
|
|
176
|
+
Toast.makeText(
|
|
177
|
+
it,
|
|
178
|
+
"${call.bridgeName}, code=$code, bridge not found",
|
|
179
|
+
Toast.LENGTH_SHORT
|
|
180
|
+
).show()
|
|
181
|
+
|
|
182
|
+
else -> Toast.makeText(
|
|
183
|
+
it,
|
|
184
|
+
"${call.bridgeName}, code=$code, may not success, check it.",
|
|
185
|
+
Toast.LENGTH_SHORT
|
|
186
|
+
).show()
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (code == -2345)
|
|
190
|
+
Toast.makeText(
|
|
191
|
+
it,
|
|
192
|
+
"${call.bridgeName}, seems no code callback",
|
|
193
|
+
Toast.LENGTH_SHORT
|
|
194
|
+
).show()
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManager.kt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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.protocol.handler
|
|
5
|
+
|
|
6
|
+
import com.tiktok.sparkling.method.protocol.BridgeContext
|
|
7
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @Author: linshuhao
|
|
11
|
+
* @Time: 2022/5/12 15:31
|
|
12
|
+
* @Description:
|
|
13
|
+
*/
|
|
14
|
+
open class BridgeFactoryManager {
|
|
15
|
+
open fun checkAndInitBridge(bridgeContext: BridgeContext, call: BridgeCall){}
|
|
16
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcher.kt
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
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.handler
|
|
7
|
+
|
|
8
|
+
import android.os.Handler
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import com.tiktok.sparkling.method.protocol.entity.BridgeCall
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* if you want to dispatch jsb to other thread, you need to implement SparklingBridge.bridgeThreadDispatcher
|
|
14
|
+
* you can just implement one method when you just want to dispatch noe engine's jsb thread.
|
|
15
|
+
*/
|
|
16
|
+
open class BridgeThreadDispatcher(private val handler: Handler? = null) {
|
|
17
|
+
// Lazy initialize the Handler to avoid issues in unit tests
|
|
18
|
+
private val mHandler: Handler? by lazy {
|
|
19
|
+
handler ?: try {
|
|
20
|
+
Handler(Looper.getMainLooper())
|
|
21
|
+
} catch (e: RuntimeException) {
|
|
22
|
+
// In unit tests, return null handler and execute synchronously
|
|
23
|
+
null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* if you want to dispatch lynx's jsb, you can use this method
|
|
29
|
+
*/
|
|
30
|
+
open fun dispatchLynxBridgeThread(call: BridgeCall, jsbRealCallBlock: (isRunInMainThread: Boolean) -> Unit?) {
|
|
31
|
+
val handler = mHandler
|
|
32
|
+
if (handler != null) {
|
|
33
|
+
handler.post {
|
|
34
|
+
jsbRealCallBlock(true)
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
// Execute synchronously in unit tests
|
|
38
|
+
jsbRealCallBlock(true)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* if you want to dispatch web's jsb, you can use this method
|
|
44
|
+
*/
|
|
45
|
+
open fun dispatchWebBridgeThread(call: BridgeCall, jsbRealCallBlock: (isRunInMainThread: Boolean) -> Unit?) {
|
|
46
|
+
val handler = mHandler
|
|
47
|
+
if (handler != null) {
|
|
48
|
+
handler.post {
|
|
49
|
+
jsbRealCallBlock(true)
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
// Execute synchronously in unit tests
|
|
53
|
+
jsbRealCallBlock(true)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
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.impl.errors
|
|
7
|
+
|
|
8
|
+
import android.view.View
|
|
9
|
+
import com.tiktok.sparkling.method.protocol.utils.MonitorUtils
|
|
10
|
+
import com.tiktok.sparkling.method.registry.core.IDLBridgeMethod
|
|
11
|
+
import com.tiktok.sparkling.method.registry.api.SparklingBridge
|
|
12
|
+
import org.json.JSONObject
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*/
|
|
16
|
+
class JSBErrorReportModel {
|
|
17
|
+
companion object {
|
|
18
|
+
const val DEFAULT_JSB_ERROR_BID = "jsb_sdk_error_bid"
|
|
19
|
+
const val DEFAULT_JSB_ERROR_EVENT = "jsb_sdk_error_event"
|
|
20
|
+
|
|
21
|
+
//global messages
|
|
22
|
+
private val globalExtension: HashMap<String, Any> = HashMap<String, Any>()
|
|
23
|
+
|
|
24
|
+
fun putGlobalExtension(key: String, value: Any?) {
|
|
25
|
+
value?.let {
|
|
26
|
+
globalExtension[key] = it
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun putGlobalExtension(map: Map<String, Any>) {
|
|
31
|
+
globalExtension.putAll(map)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//instance messages
|
|
36
|
+
private var jsbMethodName: String? = null
|
|
37
|
+
private var jsbUrl: String? = null
|
|
38
|
+
private var jsbErrorCode: Int? = null
|
|
39
|
+
private var jsbBridgeSdk: String? = null
|
|
40
|
+
private var view: View? = null
|
|
41
|
+
private var containerID: String? = null
|
|
42
|
+
private var jsbEngine: String? = null
|
|
43
|
+
|
|
44
|
+
//only put new value
|
|
45
|
+
private val jsbExtension: HashMap<String, Any> = HashMap<String, Any>()
|
|
46
|
+
|
|
47
|
+
internal fun setJsbMethodName(jsbMethodName: String?) {
|
|
48
|
+
this.jsbMethodName = jsbMethodName
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
internal fun setJsbEngine(jsbEngine: String) {
|
|
52
|
+
this.jsbEngine = jsbEngine
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
internal fun setJsbUrl(jsbUrl: String?) {
|
|
56
|
+
this.jsbUrl = jsbUrl
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
internal fun setJsbErrorCode(jsbErrorCode: Int?) {
|
|
60
|
+
this.jsbErrorCode = jsbErrorCode
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
internal fun setJsbBridgeSdk(jsbBridgeSdk: String?) {
|
|
64
|
+
this.jsbBridgeSdk = jsbBridgeSdk
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
internal fun setView(view: View?) {
|
|
68
|
+
this.view = view
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
internal fun setContainerID(containerID: String?) {
|
|
72
|
+
this.containerID = containerID
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fun putJsbExtension(key: String, value: Any?) {
|
|
76
|
+
value?.let { jsbExtension.put(key, it) }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fun putJsbExtension(map: Map<String, Any>) {
|
|
80
|
+
jsbExtension.putAll(map)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
internal fun reportJSBErrorModel(contextErrorModel: JSBErrorReportModel?) {
|
|
85
|
+
if (!checkJSBErrorCodeIsRight()) {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
if (SparklingBridge.jsbErrorReportBlockList.contains(jsbMethodName)) {
|
|
89
|
+
//report be block.
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
realReportSDKErrorModel(contextErrorModel, DEFAULT_JSB_ERROR_EVENT, 0)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private fun realReportSDKErrorModel(
|
|
96
|
+
contextErrorModel: JSBErrorReportModel?,
|
|
97
|
+
eventName: String,
|
|
98
|
+
simple: Int
|
|
99
|
+
) {
|
|
100
|
+
MonitorUtils.customReport(
|
|
101
|
+
eventName,
|
|
102
|
+
JSONObject().apply {
|
|
103
|
+
put("jsb_method_name", jsbMethodName)
|
|
104
|
+
put("jsb_url", jsbUrl)
|
|
105
|
+
put("jsb_error_code", jsbErrorCode)
|
|
106
|
+
put("jsb_bridge_sdk", jsbBridgeSdk)
|
|
107
|
+
put("jsb_engine", jsbEngine)
|
|
108
|
+
for ((key, value) in jsbExtension) {
|
|
109
|
+
put(key, value.toString())
|
|
110
|
+
}
|
|
111
|
+
if (jsbErrorCode == IDLBridgeMethod.UNREGISTERED) {
|
|
112
|
+
for ((key, value) in globalExtension) {
|
|
113
|
+
put(key, value.toString())
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//add context message
|
|
117
|
+
contextErrorModel?.jsbExtension?.let {
|
|
118
|
+
for ((key, value) in it) {
|
|
119
|
+
put(key, value.toString())
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private val allJSBSDKErrorCode = arrayOf(
|
|
126
|
+
IDLBridgeMethod.UNREGISTERED, // UnregisteredMethod, the called method isn't registered, due to legacy error, sdk use BridgeConstants's BRIDGE_NOT_FOUND
|
|
127
|
+
IDLBridgeMethod.INVALID_PARAM, // InvalidParameter, the parameter passed by FE is invalid
|
|
128
|
+
IDLBridgeMethod.INVALID_RESULT, // InvalidResult, the result passed by the method implementor is invalid
|
|
129
|
+
|
|
130
|
+
IDLBridgeMethod.UNKNOWN_ERROR,
|
|
131
|
+
IDLBridgeMethod.PERMISSION_NO_EXIST, // internal code, due to legacy error, sdk use BridgeConstants's PERMISSION_NO_EXIST
|
|
132
|
+
IDLBridgeMethod.ANNOTATION_ERROR, // when annotation can't get
|
|
133
|
+
IDLBridgeMethod.ILLEGAL_OPERATION_ERROR, // when call a illegal method of proxy
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
IDLBridgeMethod.BRIDGE_CALL_BE_INTERCEPTED, // bridge call be intercepted
|
|
137
|
+
IDLBridgeMethod.BRIDGE_HAS_BEEN_RELEASED,
|
|
138
|
+
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
private fun checkJSBErrorCodeIsRight(): Boolean {
|
|
142
|
+
return allJSBSDKErrorCode.contains(jsbErrorCode)
|
|
143
|
+
}
|
|
144
|
+
}
|