mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
save
This commit is contained in:
@@ -11,6 +11,8 @@ import { SessionStore } from '../store/session.service';
|
||||
import { AESEncrypt } from '../services/aesencrypt.service';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { RocketChatClientService } from '../services/socket/rocket-chat-client.service';
|
||||
import { ChatService } from './chat.service';
|
||||
import { WebsocketService } from './websocket.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -20,7 +22,9 @@ export class AuthService {
|
||||
userId$ = new BehaviorSubject<any>('');
|
||||
headers: HttpHeaders;
|
||||
public ValidatedUser: UserSession;
|
||||
public wsValidatedUserChat:any;
|
||||
public ValidatedUserChat:any;
|
||||
public isWsAuthenticated: boolean = false;
|
||||
opts:any;
|
||||
|
||||
constructor(
|
||||
@@ -30,6 +34,7 @@ export class AuthService {
|
||||
public alertController: AlertController,
|
||||
private aesencrypt: AESEncrypt,
|
||||
private cookieService: CookieService,
|
||||
private wsService: WebsocketService,
|
||||
private RocketChatClientService: RocketChatClientService) {
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
@@ -38,7 +43,7 @@ export class AuthService {
|
||||
this.ValidatedUser = SessionStore.user
|
||||
|
||||
console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
|
||||
this.RocketChatClientService.connect(()=>{
|
||||
/* this.RocketChatClientService.connect(()=>{
|
||||
this.RocketChatClientService.login({
|
||||
username: SessionStore.user.RochetChatUser,
|
||||
password: SessionStore.user.Password
|
||||
@@ -47,7 +52,7 @@ export class AuthService {
|
||||
}).catch((message)=>{
|
||||
console.log('rocket chat login failed', message)
|
||||
})
|
||||
})
|
||||
}) */
|
||||
|
||||
}
|
||||
|
||||
@@ -107,6 +112,22 @@ export class AuthService {
|
||||
this.ValidatedUser = null;
|
||||
}
|
||||
|
||||
loginWsChat(){
|
||||
let msg = {
|
||||
"msg": "method",
|
||||
"method": "login",
|
||||
"id":"42",
|
||||
"params":[
|
||||
{
|
||||
"user": { "username": "paulo.pinto" },
|
||||
"password": "tabteste@006"
|
||||
}
|
||||
]
|
||||
}
|
||||
this.wsService.messages.next(msg);
|
||||
this.isWsAuthenticated = true;
|
||||
}
|
||||
|
||||
//Login to rocketChat server
|
||||
async loginChat(user: UserForm): Promise<boolean> {
|
||||
let postData = {
|
||||
@@ -115,7 +136,7 @@ export class AuthService {
|
||||
}
|
||||
|
||||
|
||||
this.RocketChatClientService.connect(()=>{
|
||||
/* this.RocketChatClientService.connect(()=>{
|
||||
|
||||
this.RocketChatClientService.login({
|
||||
username: SessionStore.user.RochetChatUser,
|
||||
@@ -127,7 +148,7 @@ export class AuthService {
|
||||
}).finally(()=>{
|
||||
})
|
||||
|
||||
})
|
||||
}) */
|
||||
|
||||
|
||||
let responseChat = await this.httpService.post('login', postData).toPromise();
|
||||
|
||||
@@ -21,7 +21,7 @@ export class ChatService {
|
||||
X_Auth_Token:any;
|
||||
|
||||
//SERVER_URL = 'wss://www.tabularium.pt/websocket';
|
||||
public messages: Subject<any>;
|
||||
//public messages: Subject<any>;
|
||||
loggedUserChat:any;
|
||||
bindOnMessage: any;
|
||||
|
||||
@@ -44,15 +44,42 @@ export class ChatService {
|
||||
|
||||
console.log("CHAT SERVICE");
|
||||
|
||||
this.messages = <Subject<any>>this.wsService
|
||||
wsService.messages = <Subject<any>>this.wsService
|
||||
.connect(environment.apiWsChatUrl)
|
||||
.map((response: MessageEvent): any => {
|
||||
let data = JSON.parse(response.data);
|
||||
console.log(data);
|
||||
|
||||
if(data.msg == 'ping'){
|
||||
wsService.messages.next({msg:'pong'});
|
||||
if(!this.authService.isWsAuthenticated){
|
||||
//this.authService.loginWsChat();
|
||||
|
||||
let msg = {
|
||||
"msg": "method",
|
||||
"method": "login",
|
||||
"id":"1",
|
||||
"params":[
|
||||
{
|
||||
"user": { "username": "paulo.pinto" },
|
||||
"password": "tabteste@006"
|
||||
}
|
||||
]
|
||||
}
|
||||
wsService.messages.next(msg);
|
||||
console.log('Authenticate');
|
||||
this.authService.isWsAuthenticated = true;
|
||||
|
||||
}
|
||||
//this.authService.loginWsChat();
|
||||
}
|
||||
if(data.id == '1'){
|
||||
this.authService.wsValidatedUserChat = data;
|
||||
}
|
||||
return (JSON.stringify(data));
|
||||
});
|
||||
|
||||
console.log(this.messages);
|
||||
console.log(wsService.messages);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import { deepFind } from 'src/plugin/deep'
|
||||
this.ws.send(connectMessage, 'connect', false)
|
||||
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message: any) => {
|
||||
|
||||
if(message.msg == "ping") {
|
||||
this.ws.send({msg:"pong"},'recoonect', false)
|
||||
if(this.hasPing == false) {
|
||||
@@ -40,7 +39,6 @@ import { deepFind } from 'src/plugin/deep'
|
||||
this.hasPing = true
|
||||
}
|
||||
}
|
||||
|
||||
}})
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import * as Rx from "rxjs/Rx";
|
||||
import { Observable, Subject } from "rxjs/Rx";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -7,7 +8,7 @@ import * as Rx from "rxjs/Rx";
|
||||
export class WebsocketService {
|
||||
|
||||
message = '';
|
||||
messages = [];
|
||||
public messages: Subject<any>;
|
||||
currentUser = '';
|
||||
private subject: Rx.Subject<MessageEvent>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user