improve chat

This commit is contained in:
Peter Maquiran
2022-01-12 11:52:05 +01:00
parent b8b4ba6a05
commit 5552aa484b
13 changed files with 46 additions and 44 deletions
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { v4 as uuidv4 } from 'uuid'
import { wsCallbacksParams, msgQueue } from 'src/app/models/rochet-chat-cliente-service'
import { deepFind } from 'src/plugin/deep'
import { environment } from 'src/environments/environment';
/**
* Use this class to interact with rocketChat realtime API
*/
@@ -10,17 +11,15 @@ import { deepFind } from 'src/plugin/deep'
})
export class RocketChatClientService {
private hasPing = false
private firstPingFunx: Function
isLogin = false;
constructor() {}
connect(firstPingFunx: Function) {
this.hasPing = false
this.firstPingFunx = firstPingFunx
this.firstPingFunx = firstPingFunx //
this.ws.connect('wss://gabinetedigitalchat.dyndns.info/websocket');
this.ws.connect(environment.apiWsChatUrl);
const connectMessage = {
msg: "connect",
@@ -29,19 +28,8 @@ 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) {
// first ping
firstPingFunx()
this.hasPing = true
}
}
}})
this.ws.send({msg:"pong"},'recoonect', false)
firstPingFunx()
}
@@ -65,13 +53,12 @@ import { deepFind } from 'src/plugin/deep'
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
if(message.id == requestId || deepFind(message, 'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
if(message.result.token) {
this.isLogin = true
setTimeout(()=>{
this.ws.wsMsgQueue()
},0)
this.ws.wsMsgQueue()
resolve(message)
} else {
@@ -88,7 +75,7 @@ import { deepFind } from 'src/plugin/deep'
}
getRooms() {
getRooms(roomOlder = 1480377601) {
const requestId = uuidv4()
@@ -281,6 +268,10 @@ import { deepFind } from 'src/plugin/deep'
}
registerCallback(data:wsCallbacksParams) {
return this.ws.registerCallback(data)
}
// socket class ==================================================================
private socket!: WebSocket;
private wsUrl = ''