| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System;
- using System.Threading.Tasks;
- namespace TapSDK.Core
- {
- public class EngineBridge
- {
- private static volatile EngineBridge _sInstance;
- private readonly IBridge _bridge;
- private static readonly object Locker = new object();
- public static EngineBridge GetInstance()
- {
- lock (Locker)
- {
- if (_sInstance == null)
- {
- _sInstance = new EngineBridge();
- }
- }
- return _sInstance;
- }
- private EngineBridge()
- {
- if (Platform.IsAndroid())
- {
- _bridge = BridgeAndroid.GetInstance();
- }
- else if (Platform.IsIOS())
- {
- _bridge = BridgeIOS.GetInstance();
- }
- }
- public void Register(string serviceClzName, string serviceImplName)
- {
- _bridge?.Register(serviceClzName, serviceImplName);
- }
- public void CallHandler(Command command)
- {
- _bridge?.Call(command);
- }
- public string CallWithReturnValue(Command command, Action<Result> action = null)
- {
- return _bridge?.CallWithReturnValue(command, action);
- }
- public void CallHandler(Command command, Action<Result> action)
- {
- _bridge?.Call(command, action);
- }
- public Task<Result> Emit(Command command)
- {
- var tcs = new TaskCompletionSource<Result>();
- CallHandler(command, result =>
- {
- tcs.TrySetResult(result);
- });
- return tcs.Task;
- }
- public static bool CheckResult(Result result)
- {
- if (result == null)
- {
- return false;
- }
- if (result.code != Result.RESULT_SUCCESS)
- {
- return false;
- }
- return !string.IsNullOrEmpty(result.content);
- }
- }
- }
|