mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
save
This commit is contained in:
@@ -95,7 +95,7 @@ export class HomePage implements OnInit {
|
||||
private RouteService: RouteService,
|
||||
private RocketChatClientService: RocketChatClientService) {
|
||||
|
||||
this.RocketChatClientService.loadHistory('fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM', 10).then((message)=>{
|
||||
/* this.RocketChatClientService.loadHistory('fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM', 10).then((message)=>{
|
||||
console.log('loadHistory', message)
|
||||
})
|
||||
|
||||
@@ -118,12 +118,12 @@ export class HomePage implements OnInit {
|
||||
(Chatmessage)=>{
|
||||
console.log('chat', Chatmessage)
|
||||
}
|
||||
)
|
||||
) */
|
||||
|
||||
|
||||
window['jj'] = ()=>{
|
||||
//send message // roomId // Message
|
||||
this.RocketChatClientService.send('fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM', 'Mensagem enviada programaticamente.'+ new Date().toISOString())
|
||||
//this.RocketChatClientService.send('fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM', 'Mensagem enviada programaticamente.'+ new Date().toISOString())
|
||||
}
|
||||
|
||||
// this.RocketChatClientService.send()
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
<ion-label class="title">Chat</ion-label>
|
||||
</div>
|
||||
<div class="div-icon">
|
||||
<button class="btn-no-color" (click)="sendMsg()">
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " slot="end" src="assets/images/theme/gov/icons-chat-new-conversation.svg"></ion-icon>
|
||||
</button>
|
||||
<button class="btn-no-color" (click)="openContactsPage()">
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " slot="end" src="assets/images/icons-chat-new-conversation.svg"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " slot="end" src="assets/images/theme/gov/icons-chat-new-conversation.svg"></ion-icon>
|
||||
|
||||
@@ -31,6 +31,7 @@ import { ThemeService } from 'src/app/services/theme.service'
|
||||
import { DataService } from 'src/app/services/data.service';
|
||||
import { SqliteService } from 'src/app/services/sqlite.service';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { WebsocketService } from 'src/app/services/websocket.service';
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +39,7 @@ import { StorageService } from 'src/app/services/storage.service';
|
||||
selector: 'app-chat',
|
||||
templateUrl: './chat.page.html',
|
||||
styleUrls: ['./chat.page.scss'],
|
||||
providers: [WebsocketService, ChatService]
|
||||
})
|
||||
export class ChatPage implements OnInit {
|
||||
|
||||
@@ -123,7 +125,8 @@ export class ChatPage implements OnInit {
|
||||
private router: Router,
|
||||
private sqlservice: SqliteService,
|
||||
private platform: Platform,
|
||||
private storageservice: StorageService
|
||||
private storageservice: StorageService,
|
||||
private wsService: WebsocketService,
|
||||
|
||||
) {
|
||||
this.loggedUserChat = authService.ValidatedUserChat['data'];
|
||||
@@ -137,9 +140,9 @@ export class ChatPage implements OnInit {
|
||||
|
||||
console.log("CHAT PAGE");
|
||||
|
||||
/* chatService.messages.subscribe(msg => {
|
||||
wsService.messages.subscribe(msg => {
|
||||
console.log("Response from Websocket server: "+msg);
|
||||
}); */
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -157,7 +160,7 @@ export class ChatPage implements OnInit {
|
||||
});
|
||||
|
||||
/* websocket functions */
|
||||
this.sendMsg();
|
||||
//this.sendMsg();
|
||||
|
||||
/* Fim websocket functions */
|
||||
this.hideRefreshButton();
|
||||
@@ -235,13 +238,13 @@ export class ChatPage implements OnInit {
|
||||
|
||||
|
||||
loadMessage(){
|
||||
this.chatService.messages.subscribe(msg => {
|
||||
this.wsService.messages.subscribe(msg => {
|
||||
console.log("Response from websocket: " + msg);
|
||||
});
|
||||
}
|
||||
sendMsg() {
|
||||
console.log("new message from client to websocket: ", this.message);
|
||||
this.chatService.messages.next(this.message);
|
||||
this.wsService.messages.next(this.message);
|
||||
this.message.msg = "";
|
||||
this.loadMessage();
|
||||
}
|
||||
|
||||
@@ -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