mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
improve chat
This commit is contained in:
@@ -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 = ''
|
||||
|
||||
Reference in New Issue
Block a user