This commit is contained in:
Peter Maquiran
2022-02-10 18:07:06 +01:00
parent 382ee2fd1b
commit 08da9419bb
12 changed files with 66 additions and 34 deletions
+6 -5
View File
@@ -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)