mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
improve
This commit is contained in:
@@ -36,6 +36,7 @@ export class WsChatService {
|
||||
|
||||
this.ws.registerCallback({
|
||||
type:'Onmessage',
|
||||
key:'ping-pong',
|
||||
funx:(message: any) => {
|
||||
if(message.msg == "ping") {
|
||||
this.ws.send({message:{msg:"pong"}, loginRequired: false})
|
||||
@@ -157,9 +158,7 @@ export class WsChatService {
|
||||
}
|
||||
|
||||
// send message to room
|
||||
send({roomId, msg, attachments = null, file = null}) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
send({roomId, msg, attachments = null, file = null, requestId = uuidv4()}) {
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
@@ -178,7 +177,7 @@ export class WsChatService {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
resolve({message, requestId})
|
||||
return true
|
||||
}
|
||||
}})
|
||||
@@ -677,7 +676,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
this.wsMsgQueue[requestId] = {message, requestId, loginRequired}
|
||||
} else {
|
||||
let messageStr = JSON.stringify(message)
|
||||
|
||||
console.log('messageStr', messageStr)
|
||||
this.socket.send(messageStr)
|
||||
}
|
||||
return requestId
|
||||
@@ -686,6 +685,8 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
onmessage: async (event: any)=> {
|
||||
const data = JSON.parse(event.data)
|
||||
|
||||
console.log('onmessage', data)
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if(value.type== 'Onmessage') {
|
||||
const dontRepeat = await value.funx(data)
|
||||
|
||||
Reference in New Issue
Block a user