mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
improve rocket-chat-cliente interface
This commit is contained in:
@@ -22,7 +22,7 @@ export class AESEncrypt {
|
||||
|
||||
//Decrypting the string contained in cipherParams using the PBKDF2 key
|
||||
var decrypted = CryptoJS.AES.encrypt(encryptData, key128Bits1000Iterations, { mode: CryptoJS.mode.CBC, iv: iv, padding: CryptoJS.pad.Pkcs7 });
|
||||
console.log('AES encrypt',decrypted.toString());
|
||||
// console.log('AES encrypt',decrypted.toString());
|
||||
|
||||
return decrypted.toString();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export class SocketInterfaceService {
|
||||
private url = ''
|
||||
private connected = false
|
||||
private callBacks: {
|
||||
type: 'Offline' | 'Online' | 'Onmessage' | 'Chat' | 'Notification' | 'Notifications' | '',
|
||||
type: 'Offline' | 'Online' | 'Open' ,
|
||||
object?: string
|
||||
funx: Function
|
||||
}[] = []
|
||||
@@ -17,6 +17,14 @@ export class SocketInterfaceService {
|
||||
|
||||
constructor() { }
|
||||
|
||||
registerCallback(type: 'Offline' | 'Online' | 'Open', funx: Function, object = '') {
|
||||
this.callBacks.push({
|
||||
type,
|
||||
funx,
|
||||
object
|
||||
})
|
||||
}
|
||||
|
||||
connect(url) {
|
||||
|
||||
this.url = url
|
||||
@@ -28,8 +36,20 @@ export class SocketInterfaceService {
|
||||
this.socket.onerror = this.onerror;
|
||||
}
|
||||
|
||||
onopen() {
|
||||
this.connected = true
|
||||
|
||||
// send all saved data due to internet connection
|
||||
this.msgQueue.forEach((item, index, object) => {
|
||||
this.send(item);
|
||||
object.splice(index, 1);
|
||||
})
|
||||
}
|
||||
|
||||
send(message: object) {
|
||||
if (!this.connected) { // save data to send when back online
|
||||
console.log(this.connected, message)
|
||||
|
||||
if (this.connected === false) { // save data to send when back online
|
||||
this.msgQueue.push(message)
|
||||
} else {
|
||||
let messageStr = JSON.stringify(message)
|
||||
@@ -37,12 +57,12 @@ export class SocketInterfaceService {
|
||||
}
|
||||
}
|
||||
|
||||
onopen() {
|
||||
|
||||
onmessage(event: any) {
|
||||
console.log('event.data', JSON.parse(event.data))
|
||||
}
|
||||
onmessage() {}
|
||||
|
||||
onclose(event: any) {
|
||||
this.connected = false
|
||||
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
|
||||
setTimeout(()=>{
|
||||
this.connect(this.url)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SocketInterfaceService } from './interface/socket-interface.service'
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -9,16 +10,25 @@ export class RocketChatClientService {
|
||||
|
||||
private SocketInterfaceService = new SocketInterfaceService()
|
||||
|
||||
constructor() {
|
||||
const url = environment.apiChatUrl.replace('https','wss')
|
||||
// this.SocketInterfaceService.connect(url);
|
||||
constructor() {}
|
||||
|
||||
connect(url = 'wss://gabinetedigitalchat.dyndns.info/websocket') {
|
||||
|
||||
this.SocketInterfaceService.connect(url);
|
||||
|
||||
const connectMessage = {
|
||||
msg: "connect",
|
||||
version: "1",
|
||||
support: ["1"]
|
||||
}
|
||||
this.SocketInterfaceService.send(connectMessage)
|
||||
}
|
||||
|
||||
login(user) {
|
||||
const loginRequest = {
|
||||
msg: "method",
|
||||
method: "login",
|
||||
id: "42",
|
||||
id: uuidv4(),
|
||||
params: [
|
||||
{
|
||||
"user": { "username": user.username },
|
||||
@@ -29,17 +39,31 @@ export class RocketChatClientService {
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// this.SocketInterfaceService.send(loginRequest)
|
||||
this.SocketInterfaceService.send(loginRequest)
|
||||
}
|
||||
|
||||
logout(){ }
|
||||
|
||||
send(roomId, message, option) {}
|
||||
send(roomId, message, option) {
|
||||
var request = {
|
||||
"msg": "method",
|
||||
"method": "sendMessage",
|
||||
"id": uuidv4(),
|
||||
"params": [{
|
||||
"_id": "message-id",
|
||||
"rid": "room-id",
|
||||
"msg": "Hello World!"
|
||||
}]
|
||||
}
|
||||
|
||||
this.SocketInterfaceService.send(request);
|
||||
}
|
||||
|
||||
receive() {}
|
||||
joinRoom(){}
|
||||
deleteMessage() {}
|
||||
|
||||
createRoom() {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ export class ToastService {
|
||||
</div>
|
||||
`;
|
||||
|
||||
console.log(document.querySelector('body').classList)
|
||||
// console.log(document.querySelector('body').classList)
|
||||
document.body.append(loader)
|
||||
|
||||
loader.addEventListener('click', ()=>{
|
||||
|
||||
Reference in New Issue
Block a user