Merge branch 'feature/websocket' of https://bitbucket.org/equilibriumito/gabinete-digital into feature/websocket

This commit is contained in:
tiago.kayaya
2022-01-14 09:14:11 +01:00
3 changed files with 28 additions and 18 deletions
+2 -1
View File
@@ -99,9 +99,10 @@ export class LoginPage implements OnInit {
loader.remove()
// login to API successfully
if (attempt) {
if (attempt.UserId == SessionStore.user.UserId) {
if (attempt.UserId == SessionStore.user.UserId) {
await this.authService.SetSession(attempt, this.userattempt);
await this.authService.loginChat(this.userattempt);
this.getToken();
+19 -17
View File
@@ -114,6 +114,8 @@ export class AuthService {
setTimeout(()=>{
console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
this.WsChatService.connect();
this.WsChatService.login().then((message) => {
console.log('rocket chat login successfully', message)
@@ -123,24 +125,24 @@ export class AuthService {
})
}, 1)
// let responseChat = await this.httpService.post('login', postData).toPromise();
let responseChat = await this.httpService.post('login', postData).toPromise();
// if(responseChat) {
// console.log('Login to Rocket chat OK');
// this.ValidatedUserChat = responseChat;
// localStorage.setItem('userChat', JSON.stringify(responseChat));
// localStorage.setItem('Meteor.loginToken', responseChat['data'].authToken);
// localStorage.setItem('Meteor.userId',responseChat['data'].userId);
// this.cookieService.set('rc_token', responseChat['data'].authToken);
// this.cookieService.set('rc_uid', responseChat['data'].userId);
// this.storageService.store(AuthConnstants.AUTH, responseChat);
// return true;
// }
// else{
// console.log('Network error');
// this.presentAlert('Network error');
// return false;
// }
if(responseChat) {
console.log('Login to Rocket chat OK');
this.ValidatedUserChat = responseChat;
localStorage.setItem('userChat', JSON.stringify(responseChat));
localStorage.setItem('Meteor.loginToken', responseChat['data'].authToken);
localStorage.setItem('Meteor.userId',responseChat['data'].userId);
this.cookieService.set('rc_token', responseChat['data'].authToken);
this.cookieService.set('rc_uid', responseChat['data'].userId);
this.storageService.store(AuthConnstants.AUTH, responseChat);
return true;
}
else{
console.log('Network error');
this.presentAlert('Network error');
return false;
}
}
//Get user data from RocketChat | global object
+7
View File
@@ -12,10 +12,12 @@ import { chatHistory, Rooms } from 'src/app/models/chatMethod';
export class WsChatService {
isLogin = false;
loginResponse = {}
constructor() {}
connect() {
if(this.ws.connected == true) { return false }
this.ws.connect();
@@ -41,6 +43,9 @@ export class WsChatService {
}
login() {
if(this.isLogin == true) { return new Promise((resolve, reject)=>{ resolve(this.loginResponse) }) }
const requestId = uuidv4()
const message = {
@@ -66,7 +71,9 @@ export class WsChatService {
if(message.result.token) {
this.isLogin = true
this.loginResponse = message
console.log('wsMsgQueue', this.wsMsgQueue)
this.ws.wsMsgQueue()
resolve(message)