Skip to content

Commit 6da3fb9

Browse files
committed
BRV-174: inform authorize failed in some case
1 parent 688bfaf commit 6da3fb9

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

Src/Authorizer.cs

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,27 @@ private void OnEULANotAccepted(object sender, string cortexToken)
9898

9999
private void OnErrorMsgReceived(object sender, ErrorMsgEventArgs errorInfo)
100100
{
101+
102+
UnityEngine.Debug.Log($"OnErrorMsgReceived: Code={errorInfo.Code}, Message={errorInfo.MessageError}, Method={errorInfo.MethodName}");
103+
104+
#if UNITY_ANDROID || UNITY_IOS || USE_EMBEDDED_LIB
105+
// For mobile and embedded lib platforms
101106
bool shouldLogout = false;
102107
bool shouldAuthorize = false;
103-
104108
switch (errorInfo.Code)
105109
{
106-
case ErrorCode.AuthorizeTokenError:
107-
case ErrorCode.LoginTokenError:
108-
case ErrorCode.NoAppInfoOrAccessRightError:
109-
UnityEngine.Debug.LogError($"OnErrorMsgReceived error: {errorInfo.MessageError}. Need to re-login for emotivId: {_emotivId}");
110-
#if UNITY_ANDROID || UNITY_IOS || USE_EMBEDDED_LIB
111-
shouldLogout = !string.IsNullOrEmpty(_emotivId);
112-
#endif
113-
break;
114-
case ErrorCode.CloudTokenIsRefreshing:
115-
case ErrorCode.NotReAuthorizedError:
116-
case ErrorCode.CortexTokenCompareErrorAppInfo:
117-
case ErrorCode.CortexTokenNotFit:
118-
var tokenInfo = Authorizer.LoadToken();
119-
if (string.IsNullOrEmpty(tokenInfo.CortexToken))
120-
{
121-
UnityEngine.Debug.Log($"OnErrorMsgReceived: No token found. Need to logout user {_emotivId}");
122-
#if UNITY_ANDROID || UNITY_IOS || USE_EMBEDDED_LIB
110+
case ErrorCode.LoginTokenError:
111+
case ErrorCode.NoAppInfoOrAccessRightError:
112+
case ErrorCode.AuthorizeTokenError:
123113
shouldLogout = !string.IsNullOrEmpty(_emotivId);
124-
#endif
125-
}
126-
else
127-
{
128-
UnityEngine.Debug.Log($"OnErrorMsgReceived: {errorInfo.MessageError} Re-authorize again until it is done");
114+
break;
115+
case ErrorCode.NotReAuthorizedError:
116+
case ErrorCode.CortexTokenCompareErrorAppInfo:
117+
case ErrorCode.CortexTokenNotFit:
118+
case ErrorCode.CloudTokenIsRefreshing:
129119
shouldAuthorize = true;
130-
}
131120
break;
132121
}
133-
134122
if (shouldLogout)
135123
{
136124
_ctxClient.Logout(_emotivId);
@@ -142,7 +130,19 @@ private void OnErrorMsgReceived(object sender, ErrorMsgEventArgs errorInfo)
142130
_ctxClient.Authorize(_licenseID, _debitNo);
143131
return;
144132
}
145-
133+
#else
134+
// For desktop without embedded lib
135+
switch (errorInfo.Code)
136+
{
137+
case ErrorCode.NoAppInfoOrAccessRightError:
138+
case ErrorCode.AuthorizeTokenError:
139+
case ErrorCode.NotReAuthorizedError:
140+
case ErrorCode.CortexTokenCompareErrorAppInfo:
141+
case ErrorCode.CortexTokenNotFit:
142+
ConnectServiceStateChanged?.Invoke(this, ConnectToCortexStates.Authorize_failed);
143+
return;
144+
}
145+
#endif
146146
// send other error messages to EmotivUnityItf
147147
ErrorMsgReceived?.Invoke(this, errorInfo);
148148
}
@@ -176,6 +176,13 @@ public void Logout() {
176176
_ctxClient.Logout(_emotivId);
177177
}
178178

179+
/// <summary>
180+
/// Retry authorization process
181+
/// </summary>
182+
public void RetryAuthorize() {
183+
_ctxClient.Authorize(_licenseID, _debitNo);
184+
}
185+
179186
private void OnGetLicenseInfoDone(object sender, License lic)
180187
{
181188
// UnityEngine.Debug.Log(" OnGetLicenseInfoDone: lic: " + lic.licenseId);

Src/EmotivUnityItf.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,15 @@ public void Logout()
319319
_dsManager.Logout();
320320
}
321321

322-
// acceep eula and privacy policy
322+
/// <summary>
323+
/// Retry authorization process
324+
/// </summary>
325+
public void RetryAuthorize()
326+
{
327+
_authorizer.RetryAuthorize();
328+
}
329+
330+
// accept eula and privacy policy
323331
public void AcceptEulaAndPrivacyPolicy()
324332
{
325333
_dsManager.AcceptEulaAndPrivacyPolicy();

0 commit comments

Comments
 (0)