start method
- required String serverUrl,
- bool debugLogs = false,
- OnAutoReauthenticationFails? onAutoReauthenticationFails,
- Future<
WebRTCParams> getWebRTCParams(- USER_ID userId
Init and start Askless. This method should be called before making any operations using Askless.
serverUrl The server URL, must start with ws:// or wss://. Example: ws://192.168.0.8:3000.
debugLogs Show Askless internal logs for debugging
onAutoReauthenticationFails is a callback that is triggered once the automatic re-authentication attempt fails.
This happens when the user loses the internet connection and Askless tries to reconnect, but the previous credential
is no longer valid. This is a good place to handle the logic of refreshing the Access Token or moving
the user to the logout page. onAutoReauthenticationFails is NOT called after AsklessClient.instance.authenticate(..) is finished.
getWebRTCParams For video and audio calls only. (optional)
⚠️ Requires configuration, click here to proceed
A function that returns a future object of type WebRTCParams which allows you to
set configuration and constraints Map objects from WebRTC,
it's recommended to set your TURN servers in the configuration field.
Example:
void main() {
AsklessClient.instance.start(
serverUrl: 'ws://192.168.0.8:3000',
debugLogs: false,
onAutoReauthenticationFails: (String credentialErrorCode, void Function() clearAuthentication) {
// Add your logic to handle when the user credential
// is no longer valid
if (credentialErrorCode == "EXPIRED_ACCESS_TOKEN") {
refreshTheAccessToken();
} else {
clearAuthentication();
goToLoginPage();
}
},
// Only in case you want to use video and/or audio calls:
getWebRTCParams: (userId) => Future.value(
WebRTCParams(
configuration: {
'iceServers': [
{
"urls": [
'stun:stun1.l.google.com:19302',
'stun:stun2.l.google.com:19302'
],
},
{
// setting up TURN servers are important for Apps behind symmetric nat
"urls": "turn:a.relay.metered.ca:80",
"username": "turn.username",
"credential": "turn.password",
},
{
"urls": "turn:a.relay.metered.ca:80?transport=tcp",
"username": "turn.username",
"credential": "turn.password",
}
]
}
)
)
);
runApp(const MyApp());
}
Implementation
void start({
required String serverUrl,
bool debugLogs = false,
OnAutoReauthenticationFails? onAutoReauthenticationFails,
Future<WebRTCParams> Function(USER_ID userId)? getWebRTCParams,
}) {
_getWebRTCParams = getWebRTCParams ?? (userId) => Future.value(
WebRTCParams(configuration: {
'iceServers': [
{
"urls": [
'stun:stun1.l.google.com:19302',
'stun:stun2.l.google.com:19302'
],
}
]
})
);
_startedAt = DateTime.now();
setAsklessLogger(Logger(debugLogs: debugLogs));
_checkStartTasks();
getIt.get<ConnectionService>().start(serverUrl: serverUrl);
getIt.get<AuthenticateService>().start(onAutoReauthenticationFails: onAutoReauthenticationFails);
}