chat retry

This commit is contained in:
Peter Maquiran
2022-12-26 15:41:11 +01:00
parent b83fff6fbd
commit 0a3fd0ec8b
79 changed files with 223 additions and 1025 deletions
+31 -1
View File
@@ -59,6 +59,7 @@ export class MessageService {
downloadAttachments = false;
downloadAttachmentsTemp = 0;
UploadAttachmentsTemp = 0;
manualRetry = false
constructor(
private NfService: NfService,
@@ -215,6 +216,9 @@ export class MessageService {
}
functionTimer = null;
async sendRequest(params) {
if(params?.attachments) {
@@ -228,16 +232,41 @@ export class MessageService {
this.RochetChatConnectorService.send(params).then(
(ChatMessage: any) => {
ChatMessage = ChatMessage.message.result
clearTimeout(this.functionTimer);
this.messageSend = true
this.redefinedMessage(ChatMessage)
}
).catch((error) => {
clearTimeout(this.functionTimer);
console.error(error)
})
this.functionTimer = setTimeout(() => {
this.RochetChatConnectorService.registerCallback({
type:'Onmessage',
key:'ping-pong-message',
funx:(message: any) => {
if(message.msg == "ping") {
if(this.sendAttempt >= 3) {
this.manualRetry = true
} else {
this.send()
}
return true
}
this.save()
}
})
this.RochetChatConnectorService.wsSend({message:{msg:"pong"}, loginRequired: false})
}, 8000)
} else {
// console.log("reconnect")
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: async ()=> {
@@ -335,6 +364,7 @@ export class MessageService {
channels: this.channels,
mentions: this.mentions,
//msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.UserName),
sendAttempt: this.sendAttempt,
msg:this.msg,
rid: this.rid,
ts: this.ts,
@@ -46,6 +46,10 @@ export class RochetChatConnectorService {
}
wsSend({message, requestId = uuidv4(), loginRequired = true}:send) {
this.ws.send({message:{msg:"pong"}, loginRequired: false})
}
login() {
// dont login if is already login
if(this.isLogin == true) {
@@ -739,7 +743,7 @@ export class RochetChatConnectorService {
} else {
let messageStr = JSON.stringify(message)
//
// console.log(messageStr)
console.log(messageStr)
this.socket.send(messageStr)
}
return requestId
@@ -747,6 +751,8 @@ export class RochetChatConnectorService {
onmessage: async (event: any)=> {
const data = JSON.parse(event.data)
console.log('data', data)
for (const [key, value] of Object.entries(this.wsCallbacks)) {
if(value.type== 'Onmessage') {