Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_syncClient() {
const opts = {
baseUrl: this.homeserver,
accessToken: this.accessToken,
userId: this.userId,
deviceId: this.deviceId,
};
this.client = matrixcs.createClient(opts);
this.client.on('sync', (state, prevState, data) => {
switch (state) {
case 'PREPARED':
this._debugLog('Sync completed');
this.synced = true;
this.emit('syncComplete');
break;
}
});
this.client.on('RoomMember.membership', (event, member) => {
const room = this.client.getRoom(member.roomId);
switch (member.membership) {
case 'invite':
if (member.userId === this.userId) {
if (!room || room.getJoinedMembers()
setTimeout(() => {
if (this.accessToken) {
this.userId = localStorage.getItem('mxvr_user_id');
this.deviceId = localStorage.getItem('mxvr_device_id');
this._debugLog('Logged in successfully');
if (this._persist) {
this._persistCredentials();
}
this._syncClient();
return;
}
const loginClient = matrixcs.createClient(this.homeserver);
let loginPromise;
if (this.guest) {
this.username = 'mxvr' + Date.now();
this._debugLog('Registering guest user:', this.username);
loginPromise = loginClient.register(
this.username,
Math.random().toString(36).substring(7),
null,
{type: 'm.login.dummy'},
);
} else {
this._debugLog('Logging in...');
loginPromise = loginClient.loginWithPassword(this.username,
this.password);
}
loginPromise.then((data) => {