com.taptap.sdk.core 4.6.2 → 4.7.0-alpha.14
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/Mobile/Editor/NativeDependencies.xml +2 -1
- package/Mobile/Runtime/IOSNativeWrapper.cs +0 -223
- package/Mobile/Runtime/TapEventMobile.cs +5 -0
- package/Resources/TapMessage.prefab +15 -15
- package/Runtime/Internal/Platform/ITapEventPlatform.cs +3 -0
- package/Runtime/Internal/Utils/TapLoom.cs +1 -1
- package/Runtime/Public/TapTapEvent.cs +7 -1
- package/Runtime/Public/TapTapSDK.cs +63 -23
- package/Runtime/Public/TapTapSdkOptions.cs +49 -1
- package/Standalone/Runtime/Internal/PlayRecorder.cs +1 -1
- package/Standalone/Runtime/Internal/TapClientBridge.cs +44 -36
- package/Standalone/Runtime/Internal/TapClientBridgePoll.cs +1 -3
- package/Standalone/Runtime/Internal/UI/TapClientConnectTipController.cs +4 -4
- package/Standalone/Runtime/Internal/User.cs +5 -5
- package/Standalone/Runtime/Public/TapClientStandalone.cs +314 -0
- package/Standalone/Runtime/Public/TapClientStandalone.cs.meta +11 -0
- package/Standalone/Runtime/Public/TapCoreStandalone.cs +26 -371
- package/Standalone/Runtime/Public/TapEventStandalone.cs +62 -31
- package/package.json +1 -1
- package/link.xml +0 -4
- package/link.xml.meta +0 -7
|
@@ -14,29 +14,29 @@ namespace TapSDK.Core.Standalone.Internal
|
|
|
14
14
|
internal enum TapSDKInitResult
|
|
15
15
|
{
|
|
16
16
|
// 初始化成功
|
|
17
|
-
|
|
17
|
+
OK = 0,
|
|
18
18
|
// 其他错误
|
|
19
|
-
|
|
19
|
+
FailedGeneric = 1,
|
|
20
20
|
// 未找到 TapTap,用户可能未安装,请引导用户下载安装 TapTap
|
|
21
|
-
|
|
21
|
+
NoPlatform = 2,
|
|
22
22
|
// 已安装 TapTap,游戏未通过 TapTap 启动
|
|
23
|
-
|
|
23
|
+
NotLaunchedByPlatform = 3,
|
|
24
24
|
|
|
25
25
|
// SDK 本地执行时未知错误
|
|
26
|
-
|
|
26
|
+
Unknown = -1,
|
|
27
27
|
// SDK 本地执行时超时
|
|
28
|
-
|
|
28
|
+
Timeout = -2,
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
internal enum
|
|
31
|
+
internal enum TapEventID
|
|
32
32
|
{
|
|
33
|
-
|
|
33
|
+
Unknown = 0,
|
|
34
34
|
|
|
35
35
|
// [1, 2000), reserved for TapTap platform events
|
|
36
|
-
|
|
36
|
+
SystemStateChanged = 1,
|
|
37
37
|
|
|
38
38
|
// [2001, 4000), reserved for TapTap user events
|
|
39
|
-
|
|
39
|
+
AuthorizeFinished = 2001,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
// 系统事件类型
|
|
@@ -49,9 +49,9 @@ namespace TapSDK.Core.Standalone.Internal
|
|
|
49
49
|
// 是否触发授权的返回结果
|
|
50
50
|
internal enum AuthorizeResult
|
|
51
51
|
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
UNKNOWN = 0, // 未知
|
|
53
|
+
OK = 1, // 成功触发授权
|
|
54
|
+
FAILED = 2, // 授权失败
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
// 完成授权后的返回结果
|
|
@@ -152,39 +152,47 @@ namespace TapSDK.Core.Standalone.Internal
|
|
|
152
152
|
SystemStateResponse response = Marshal.PtrToStructure<SystemStateResponse>(userData);
|
|
153
153
|
}
|
|
154
154
|
*/
|
|
155
|
-
internal static void RegisterCallback(
|
|
155
|
+
internal static void RegisterCallback(TapEventID eventID, CallbackDelegate callback)
|
|
156
156
|
{
|
|
157
157
|
|
|
158
|
-
TapLogger.Debug("start set delegate");
|
|
159
158
|
IntPtr funcPtr = Marshal.GetFunctionPointerForDelegate(callback);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
159
|
+
switch (eventID)
|
|
160
|
+
{
|
|
161
|
+
case TapEventID.AuthorizeFinished:
|
|
162
|
+
if (_userCallbackInstance != null)
|
|
163
|
+
{
|
|
164
|
+
UnRegisterCallback(eventID, _userCallbackInstance);
|
|
165
|
+
}
|
|
166
|
+
_userCallbackInstance = callback;
|
|
167
|
+
break;
|
|
168
|
+
case TapEventID.SystemStateChanged:
|
|
169
|
+
if (_callbackInstance != null)
|
|
170
|
+
{
|
|
171
|
+
UnRegisterCallback(eventID, _callbackInstance);
|
|
172
|
+
}
|
|
173
|
+
_callbackInstance = callback; // 防止被 GC 回收
|
|
174
|
+
break;
|
|
170
175
|
}
|
|
171
|
-
|
|
172
|
-
TapSDK_RegisterCallback(
|
|
173
|
-
TapLogger.Debug("start set delegate ptr finish");
|
|
176
|
+
|
|
177
|
+
TapSDK_RegisterCallback((int)eventID, funcPtr);
|
|
174
178
|
}
|
|
175
179
|
|
|
176
180
|
// 移除回调
|
|
177
|
-
internal static void UnRegisterCallback(CallbackDelegate callback
|
|
181
|
+
internal static void UnRegisterCallback(TapEventID eventID,CallbackDelegate callback)
|
|
178
182
|
{
|
|
179
183
|
|
|
180
184
|
IntPtr funcPtr = Marshal.GetFunctionPointerForDelegate(callback);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
switch (eventID)
|
|
186
|
+
{
|
|
187
|
+
case TapEventID.AuthorizeFinished:
|
|
188
|
+
_userCallbackInstance = null;
|
|
189
|
+
break;
|
|
190
|
+
case TapEventID.SystemStateChanged:
|
|
191
|
+
_callbackInstance = null;
|
|
192
|
+
break;
|
|
185
193
|
}
|
|
186
|
-
|
|
187
|
-
TapSDK_UnregisterCallback(
|
|
194
|
+
TapLogger.Debug("start remove delegate ptr " + funcPtr);
|
|
195
|
+
TapSDK_UnregisterCallback((int) eventID, funcPtr);
|
|
188
196
|
}
|
|
189
197
|
|
|
190
198
|
internal static AuthorizeResult LoginWithScopes(string[] scopeStrings, string responseType, string redirectUri,
|
|
@@ -198,7 +206,7 @@ namespace TapSDK.Core.Standalone.Internal
|
|
|
198
206
|
return (AuthorizeResult)result;
|
|
199
207
|
}catch(Exception ex){
|
|
200
208
|
TapLogger.Debug("login crash = " + ex.StackTrace);
|
|
201
|
-
return AuthorizeResult.
|
|
209
|
+
return AuthorizeResult.UNKNOWN;
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
212
|
|
|
@@ -31,13 +31,13 @@ namespace TapSDK.Core.Standalone.Internal {
|
|
|
31
31
|
|
|
32
32
|
internal void Show(TapSDKInitResult errorType)
|
|
33
33
|
{
|
|
34
|
-
if (errorType == TapSDKInitResult.
|
|
34
|
+
if (errorType == TapSDKInitResult.NoPlatform){
|
|
35
35
|
tipText.text = "获取游戏信息失败,请下载 TapTap 客户端后重新启动游戏";
|
|
36
|
-
}else if (errorType == TapSDKInitResult.
|
|
36
|
+
}else if (errorType == TapSDKInitResult.NotLaunchedByPlatform){
|
|
37
37
|
tipText.text = "获取游戏信息失败,请从 TapTap 客户端重新启动游戏";
|
|
38
|
-
}else if (errorType == TapSDKInitResult.
|
|
38
|
+
}else if (errorType == TapSDKInitResult.Unknown){
|
|
39
39
|
tipText.text = "本地发生未知错误,请从 TapTap 客户端重新启动游戏";
|
|
40
|
-
}else if (errorType == TapSDKInitResult.
|
|
40
|
+
}else if (errorType == TapSDKInitResult.Timeout){
|
|
41
41
|
tipText.text = "获取游戏信息超时,请从 TapTap 客户端重新启动游戏";
|
|
42
42
|
}else {
|
|
43
43
|
tipText.text = "发生未知错误,请从 TapTap 客户端重新启动游戏";
|
|
@@ -16,11 +16,11 @@ namespace TapSDK.Core.Standalone.Internal {
|
|
|
16
16
|
|
|
17
17
|
private readonly PlayRecorder playRecorder;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
internal User() {
|
|
20
20
|
playRecorder = new PlayRecorder();
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
internal void Login(string userId, Dictionary<string, object> props = null) {
|
|
24
24
|
// 先执行旧用户登出逻辑
|
|
25
25
|
Id = TapCoreStandalone.Prefs.Get<string>(USER_ID_KEY);
|
|
26
26
|
if (!string.IsNullOrWhiteSpace(Id)) {
|
|
@@ -31,18 +31,18 @@ namespace TapSDK.Core.Standalone.Internal {
|
|
|
31
31
|
Id = userId;
|
|
32
32
|
|
|
33
33
|
if (TapCoreStandalone.enableAutoEvent) {
|
|
34
|
-
|
|
34
|
+
TapEventStandalone.Tracker?.TrackEvent(Constants.USER_LOGIN, props, true);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
Dictionary<string, object> updateProps = new Dictionary<string, object> {
|
|
38
38
|
{ "has_user", true },
|
|
39
39
|
};
|
|
40
|
-
|
|
40
|
+
TapEventStandalone.Tracker?.TrackDeviceProperties(Constants.PROPERTY_UPDATE_TYPE, updateProps);
|
|
41
41
|
|
|
42
42
|
playRecorder.Start();
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
internal void Logout() {
|
|
46
46
|
playRecorder.Stop();
|
|
47
47
|
|
|
48
48
|
Id = null;
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using System.Threading.Tasks;
|
|
3
|
+
using TapSDK.Core.Internal.Utils;
|
|
4
|
+
using TapSDK.Core.Standalone.Internal;
|
|
5
|
+
using TapSDK.UI;
|
|
6
|
+
using System;
|
|
7
|
+
using System.Runtime.InteropServices;
|
|
8
|
+
using TapSDK.Core.Standalone.Internal.Openlog;
|
|
9
|
+
using System.Threading;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
namespace TapSDK.Core.Standalone
|
|
14
|
+
{
|
|
15
|
+
#if UNITY_STANDALONE_WIN
|
|
16
|
+
public class TapClientStandalone
|
|
17
|
+
{
|
|
18
|
+
|
|
19
|
+
// 是否是渠道服游戏包
|
|
20
|
+
private static bool isChannelPackage = false;
|
|
21
|
+
|
|
22
|
+
// -1 未执行 0 失败 1 成功
|
|
23
|
+
private static int lastIsLaunchedFromTapTapPCResult = -1;
|
|
24
|
+
private static bool isRuningIsLaunchedFromTapTapPC = false;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// 当为渠道游戏包时,与启动器的初始化校验结果
|
|
28
|
+
private static TapInitResult tapInitResult;
|
|
29
|
+
|
|
30
|
+
// <summary>
|
|
31
|
+
// 校验游戏是否通过启动器唤起,建立与启动器通讯
|
|
32
|
+
//</summary>
|
|
33
|
+
public static async Task<bool> IsLaunchedFromTapTapPC()
|
|
34
|
+
{
|
|
35
|
+
// 正在执行中
|
|
36
|
+
if (isRuningIsLaunchedFromTapTapPC)
|
|
37
|
+
{
|
|
38
|
+
UIManager.Instance.OpenToast("IsLaunchedFromTapTapPC 正在执行,请勿重复调用", UIManager.GeneralToastLevel.Error);
|
|
39
|
+
TapLogger.Error("IsLaunchedFromTapTapPC 正在执行,请勿重复调用");
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
// 多次执行时返回上一次结果
|
|
43
|
+
if (lastIsLaunchedFromTapTapPCResult != -1)
|
|
44
|
+
{
|
|
45
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC duplicate invoke return " + lastIsLaunchedFromTapTapPCResult);
|
|
46
|
+
return lastIsLaunchedFromTapTapPCResult > 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
isChannelPackage = true;
|
|
50
|
+
TapTapSdkOptions coreOptions = TapCoreStandalone.coreOptions;
|
|
51
|
+
if (coreOptions == null)
|
|
52
|
+
{
|
|
53
|
+
UIManager.Instance.OpenToast("IsLaunchedFromTapTapPC 调用必须在初始化之后", UIManager.GeneralToastLevel.Error);
|
|
54
|
+
TapLogger.Error("IsLaunchedFromTapTapPC 调用必须在初始化之后");
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
string clientId = coreOptions.clientId;
|
|
58
|
+
string pubKey = coreOptions.clientPublicKey;
|
|
59
|
+
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(pubKey))
|
|
60
|
+
{
|
|
61
|
+
UIManager.Instance.OpenToast("clientId 及 TapPubKey 参数都不能为空, clientId =" + clientId + ", TapPubKey = " + pubKey, UIManager.GeneralToastLevel.Error);
|
|
62
|
+
TapLogger.Error("clientId 或 TapPubKey 无效, clientId = " + clientId + ", TapPubKey = " + pubKey);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
isRuningIsLaunchedFromTapTapPC = true;
|
|
66
|
+
|
|
67
|
+
string sessionId = Guid.NewGuid().ToString();
|
|
68
|
+
TapCoreTracker.Instance.TrackStart(TapCoreTracker.METHOD_LAUNCHER, sessionId);
|
|
69
|
+
try
|
|
70
|
+
{
|
|
71
|
+
TapInitResult result = await RunClientBridgeMethodWithTimeout(clientId, pubKey);
|
|
72
|
+
isRuningIsLaunchedFromTapTapPC = false;
|
|
73
|
+
if (result.needQuitGame)
|
|
74
|
+
{
|
|
75
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
76
|
+
TapCoreTracker.Instance.TrackSuccess(TapCoreTracker.METHOD_LAUNCHER, sessionId, TapCoreTracker.SUCCESS_TYPE_RESTART);
|
|
77
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC Quit game");
|
|
78
|
+
Application.Quit();
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
{
|
|
83
|
+
if (result.result == TapSDKInitResult.OK)
|
|
84
|
+
{
|
|
85
|
+
string currentClientId;
|
|
86
|
+
bool isFetchClientIdSuccess = TapClientBridge.GetClientId(out currentClientId);
|
|
87
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC get clientId = " + currentClientId);
|
|
88
|
+
if (isFetchClientIdSuccess && !string.IsNullOrEmpty(currentClientId) && currentClientId != clientId)
|
|
89
|
+
{
|
|
90
|
+
UIManager.Instance.OpenToast("SDK 中配置的 clientId = " + clientId + "与 Tap 启动器中" + currentClientId + "不一致", UIManager.GeneralToastLevel.Error);
|
|
91
|
+
TapLogger.Error("SDK 中配置的 clientId = " + clientId + "与 Tap 启动器中" + currentClientId + "不一致");
|
|
92
|
+
TapCoreTracker.Instance.TrackFailure(TapCoreTracker.METHOD_LAUNCHER, sessionId, -1, "SDK 中配置的 clientId = " + clientId + "与 Tap 启动器中" + currentClientId + "不一致");
|
|
93
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
string openId;
|
|
97
|
+
bool fetchOpenIdSuccess = TapClientBridge.GetTapUserOpenId(out openId);
|
|
98
|
+
if (fetchOpenIdSuccess)
|
|
99
|
+
{
|
|
100
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC get openId = " + openId);
|
|
101
|
+
EventManager.TriggerEvent(EventManager.IsLaunchedFromTapTapPCFinished, openId);
|
|
102
|
+
}
|
|
103
|
+
else
|
|
104
|
+
{
|
|
105
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC get openId failed");
|
|
106
|
+
}
|
|
107
|
+
lastIsLaunchedFromTapTapPCResult = 1;
|
|
108
|
+
TapClientBridgePoll.StartUp();
|
|
109
|
+
TapCoreTracker.Instance.TrackSuccess(TapCoreTracker.METHOD_LAUNCHER, sessionId, TapCoreTracker.SUCCESS_TYPE_INIT);
|
|
110
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC check success");
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
else
|
|
114
|
+
{
|
|
115
|
+
|
|
116
|
+
TapCoreTracker.Instance.TrackFailure(TapCoreTracker.METHOD_LAUNCHER, sessionId, (int)result.result, result.errorMsg ?? "");
|
|
117
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
118
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC show TapClient tip Pannel " + result.result + " , error = " + result.errorMsg);
|
|
119
|
+
string tipPannelPath = "Prefabs/TapClient/TapClientConnectTipPanel";
|
|
120
|
+
if (Resources.Load<GameObject>(tipPannelPath) != null)
|
|
121
|
+
{
|
|
122
|
+
var pannel = UIManager.Instance.OpenUI<TapClientConnectTipController>(tipPannelPath);
|
|
123
|
+
pannel.Show(result.result);
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (TimeoutException e)
|
|
130
|
+
{
|
|
131
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
132
|
+
TapCoreTracker.Instance.TrackFailure(TapCoreTracker.METHOD_LAUNCHER, sessionId, (int)TapSDKInitResult.Timeout, e.Message ?? "");
|
|
133
|
+
|
|
134
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC check timeout");
|
|
135
|
+
string tipPannelPath = "Prefabs/TapClient/TapClientConnectTipPanel";
|
|
136
|
+
if (Resources.Load<GameObject>(tipPannelPath) != null)
|
|
137
|
+
{
|
|
138
|
+
var pannel = UIManager.Instance.OpenUI<TapClientConnectTipController>(tipPannelPath);
|
|
139
|
+
pannel.Show(TapSDKInitResult.Timeout);
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
catch (Exception e)
|
|
144
|
+
{
|
|
145
|
+
lastIsLaunchedFromTapTapPCResult = 0;
|
|
146
|
+
TapCoreTracker.Instance.TrackFailure(TapCoreTracker.METHOD_LAUNCHER, sessionId, (int)TapSDKInitResult.Unknown, e.Message ?? "");
|
|
147
|
+
|
|
148
|
+
TapLogger.Debug("IsLaunchedFromTapTapPC check exception = " + e.Message + " \n" + e.StackTrace);
|
|
149
|
+
string tipPannelPath = "Prefabs/TapClient/TapClientConnectTipPanel";
|
|
150
|
+
if (Resources.Load<GameObject>(tipPannelPath) != null)
|
|
151
|
+
{
|
|
152
|
+
var pannel = UIManager.Instance.OpenUI<TapClientConnectTipController>(tipPannelPath);
|
|
153
|
+
pannel.Show(TapSDKInitResult.Unknown);
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private static async Task<TapInitResult> RunClientBridgeMethodWithTimeout(string clientId, string pubKey)
|
|
160
|
+
{
|
|
161
|
+
TaskCompletionSource<TapInitResult> task = new TaskCompletionSource<TapInitResult>();
|
|
162
|
+
try
|
|
163
|
+
{
|
|
164
|
+
TapInitResult result = await ExecuteWithTimeoutAsync(() =>
|
|
165
|
+
{
|
|
166
|
+
bool needQuitGame = TapClientBridge.TapSDK_RestartAppIfNecessary(clientId);
|
|
167
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke TapSDK_RestartAppIfNecessary result = " + needQuitGame);
|
|
168
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke TapSDK_RestartAppIfNecessary finished " );
|
|
169
|
+
if (needQuitGame)
|
|
170
|
+
{
|
|
171
|
+
tapInitResult = new TapInitResult(needQuitGame);
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
{
|
|
175
|
+
string outputError;
|
|
176
|
+
TapSDKInitResult tapSDKInitResult = TapClientBridge.CheckInitState(out outputError, pubKey);
|
|
177
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke CheckInitState result = " + tapSDKInitResult + ", error = " + outputError);
|
|
178
|
+
tapInitResult = new TapInitResult(tapSDKInitResult, outputError);
|
|
179
|
+
}
|
|
180
|
+
return tapInitResult;
|
|
181
|
+
}, TimeSpan.FromSeconds(5));
|
|
182
|
+
task.TrySetResult(tapInitResult);
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
catch (TimeoutException ex)
|
|
186
|
+
{
|
|
187
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke CheckInitState 方法执行超时!");
|
|
188
|
+
task.TrySetException(ex);
|
|
189
|
+
}
|
|
190
|
+
catch (Exception ex)
|
|
191
|
+
{
|
|
192
|
+
TapLogger.Debug("RunClientBridgeMethodWithTimeout invoke C 方法出错!" + ex.Message);
|
|
193
|
+
task.TrySetException(ex);
|
|
194
|
+
}
|
|
195
|
+
return await task.Task;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/// <summary>
|
|
199
|
+
/// 在 IO 线程执行 C 方法,超时 5 秒后切回主线程
|
|
200
|
+
/// </summary>
|
|
201
|
+
private static async Task<T> ExecuteWithTimeoutAsync<T>(Func<T> cMethod, TimeSpan timeout)
|
|
202
|
+
{
|
|
203
|
+
using (var cts = new CancellationTokenSource())
|
|
204
|
+
{
|
|
205
|
+
Task<T> ioTask = Task.Run(cMethod); // 在后台线程执行 C 方法
|
|
206
|
+
Task delayTask = Task.Delay(timeout); // 超时任务
|
|
207
|
+
|
|
208
|
+
Task completedTask = await Task.WhenAny(ioTask, delayTask);
|
|
209
|
+
|
|
210
|
+
if (completedTask == delayTask)
|
|
211
|
+
{
|
|
212
|
+
cts.Cancel(); // 取消 C 方法任务
|
|
213
|
+
throw new TimeoutException("C 方法执行超时!");
|
|
214
|
+
}
|
|
215
|
+
else
|
|
216
|
+
{
|
|
217
|
+
cts.Cancel();
|
|
218
|
+
return await ioTask;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/// <summary>
|
|
224
|
+
/// 是否需要从启动器登录
|
|
225
|
+
/// </summary>
|
|
226
|
+
public static bool IsNeedLoginByTapClient()
|
|
227
|
+
{
|
|
228
|
+
return isChannelPackage;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
private static Action<bool, string> currentLoginCallback;
|
|
233
|
+
|
|
234
|
+
/// <summary>
|
|
235
|
+
/// 发起登录授权
|
|
236
|
+
/// </summary>
|
|
237
|
+
public static bool StartLoginWithScopes(string[] scopes, string responseType, string redirectUri,
|
|
238
|
+
string codeChallenge, string state, string codeChallengeMethod, string versonCode, string sdkUa, string info, Action<bool, string> callback)
|
|
239
|
+
{
|
|
240
|
+
if (lastIsLaunchedFromTapTapPCResult == -1)
|
|
241
|
+
{
|
|
242
|
+
// UIManager.Instance.OpenToast("IsLaunchedFromTapTapPC 正在执行,请在完成后调用授权接口", UIManager.GeneralToastLevel.Error);
|
|
243
|
+
TapLogger.Error(" login must be invoked after IsLaunchedFromTapTapPC success");
|
|
244
|
+
throw new Exception("login must be invoked after IsLaunchedFromTapTapPC success");
|
|
245
|
+
}
|
|
246
|
+
TapLogger.Debug("LoginWithScopes start login by tapclient thread = " + Thread.CurrentThread.ManagedThreadId);
|
|
247
|
+
try
|
|
248
|
+
{
|
|
249
|
+
TapClientBridge.RegisterCallback(TapEventID.AuthorizeFinished, loginCallbackDelegate);
|
|
250
|
+
AuthorizeResult authorizeResult = TapClientBridge.LoginWithScopes(scopes, responseType, redirectUri,
|
|
251
|
+
codeChallenge, state, codeChallengeMethod, versonCode, sdkUa, info);
|
|
252
|
+
TapLogger.Debug("LoginWithScopes start result = " + authorizeResult);
|
|
253
|
+
if (authorizeResult != AuthorizeResult.OK)
|
|
254
|
+
{
|
|
255
|
+
TapClientBridge.UnRegisterCallback(TapEventID.AuthorizeFinished,loginCallbackDelegate);
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
else
|
|
259
|
+
{
|
|
260
|
+
currentLoginCallback = callback;
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
catch (Exception ex)
|
|
266
|
+
{
|
|
267
|
+
TapLogger.Debug("LoginWithScopes start login by tapclient error = " + ex.Message);
|
|
268
|
+
TapClientBridge.UnRegisterCallback(TapEventID.AuthorizeFinished,loginCallbackDelegate);
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
[AOT.MonoPInvokeCallback(typeof(TapClientBridge.CallbackDelegate))]
|
|
276
|
+
static void loginCallbackDelegate(int id, IntPtr userData)
|
|
277
|
+
{
|
|
278
|
+
TapLogger.Debug("LoginWithScopes recevie callback " + id);
|
|
279
|
+
if (id == (int)TapEventID.AuthorizeFinished)
|
|
280
|
+
{
|
|
281
|
+
TapLogger.Debug("LoginWithScopes callback thread = " + Thread.CurrentThread.ManagedThreadId);
|
|
282
|
+
TapClientBridge.AuthorizeFinishedResponse response = Marshal.PtrToStructure<TapClientBridge.AuthorizeFinishedResponse>(userData);
|
|
283
|
+
TapLogger.Debug("LoginWithScopes callback = " + response.is_cancel + " uri = " + response.callback_uri);
|
|
284
|
+
if (currentLoginCallback != null)
|
|
285
|
+
{
|
|
286
|
+
currentLoginCallback(response.is_cancel != 0, response.callback_uri);
|
|
287
|
+
TapClientBridge.UnRegisterCallback(TapEventID.AuthorizeFinished,loginCallbackDelegate);
|
|
288
|
+
currentLoginCallback = null;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// 初始化校验结果
|
|
294
|
+
private class TapInitResult
|
|
295
|
+
{
|
|
296
|
+
internal TapSDKInitResult result;
|
|
297
|
+
internal string errorMsg;
|
|
298
|
+
|
|
299
|
+
internal bool needQuitGame = false;
|
|
300
|
+
|
|
301
|
+
public TapInitResult(TapSDKInitResult result, string errorMsg)
|
|
302
|
+
{
|
|
303
|
+
this.result = result;
|
|
304
|
+
this.errorMsg = errorMsg;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
public TapInitResult(bool needQuitGame)
|
|
308
|
+
{
|
|
309
|
+
this.needQuitGame = needQuitGame;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
#endif
|
|
314
|
+
}
|