Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor() {
this.client = Voximplant.getInstance();
// Connection to the Voximplant Cloud is stayed alive on reloading of the app's
// JavaScript code. Calling "disconnect" API here makes the SDK and app states
// synchronized.
PushManager.init();
(async() => {
try {
this.client.disconnect();
} catch (e) {
}
})();
this.client.on(Voximplant.ClientEvents.ConnectionClosed, this._connectionClosed);
}
async loginWithToken() {
try {
let state = await this.client.getClientState();
if (state === Voximplant.ClientState.DISCONNECTED) {
await this.client.connect();
}
if (state !== Voximplant.ClientState.LOGGED_IN) {
const username = await AsyncStorage.getItem('usernameValue');
const accessToken = await AsyncStorage.getItem('accessToken');
console.log('LoginManager: loginWithToken: user: ' + username + ', token: ' + accessToken );
const authResult = await this.client.loginWithToken(username + '.voximplant.com', accessToken);
await this._processLoginSuccess(authResult);
}
} catch (e) {
console.log('LoginManager: loginWithToken: ' + e.name);
if (e.name === Voximplant.ClientEvents.AuthResult) {
console.log('LoginManager: loginWithToken: error code: ' + e.code);
}
}
}
init() {
this.client.on(Voximplant.ClientEvents.IncomingCall, this._incomingCall);
AppState.addEventListener('change', this._handleAppStateChange);
}