generateToken method
void
generateToken(
- String sessionId,
- String userAuthToken,
- dynamic onSuccess(
- GenerateToken generateToken
- dynamic onError(
- CometChatCallsException error
override
Implementation
@override
void generateToken(sessionId, userAuthToken, onSuccess, onError) async {
CometChatCallsUtils.showLog(tag, "generateToken: CALLED");
try{
if(sessionId.isEmpty){
onError(CometChatCallsException(CometChatCallsConstants.codeSessionIdNull, "Session ID is null", "Session ID is null"));
}else if(userAuthToken.isEmpty){
onError(CometChatCallsException(CometChatCallsConstants.codeUserAuthTokenNull, "User auth token is null", "User auth token is null"));
}else if(ApiConnection.callAppSettings == null){
onError(CometChatCallsException(CometChatCallsConstants.codeCometChatCallsSDKInitError, "CometChatCalls SDK is not initialized", "CometChatCalls SDK is not initialized, please call CometChatCall.init() first"));
}else{
/*final result = await methodChannel.invokeMethod<Map>('generateToken', {
"sessionId": sessionId,
"userAuthToken": userAuthToken
});
CometChatCallsUtils.showLog(tag, "generateToken: RESULT: $result");
if (result == null) {
onError(CometChatCallsException(CometChatCallsConstants.COMETCHATCALLS_SDK_INIT_ERROR, "CometChatCalls SDK is not initialized, requested result is null", "CometChatCalls SDK is not initialized, requested result is null"));
}else{
final GenerateToken generateToken = GenerateToken.fromMap(result);
onSuccess(generateToken);
}*/
ApiConnection().generateToken(GenerateToken(sessionId: sessionId), userAuthToken, (String response){
final obj = GenerateToken.fromJson(jsonDecode(response)["data"]);
onSuccess(obj);
}, (CometChatCallsException e){
CometChatCallsUtils.showLog(tag, "generateToken onError: ${e.message}");
onError(e);
});
}
} on PlatformException catch (platformException) {
onError(CometChatCallsException(platformException.code, platformException.message, platformException.details));
} catch (e) {
onError(CometChatCallsException(CometChatCallsConstants.codeError, e.toString(), e.toString()));
}
}