This commit is contained in:
Peter Maquiran
2022-02-08 19:17:44 +01:00
parent 31fc4039d2
commit 53fbba4094
6 changed files with 60 additions and 51 deletions
+3
View File
@@ -152,10 +152,13 @@ export class HomePage implements OnInit {
} else {
this.synchWhenOnline()
}
//this.WsChatService.login()
});
window.addEventListener('offline', () => {
console.log('Became offline')
this.backgroundservice.offline()
//this.WsChatService.logout()
});
this.updateList()
+2
View File
@@ -174,6 +174,7 @@ export class AuthService {
return true
} catch(e) {
console.log(e)
return false
}
@@ -187,6 +188,7 @@ export class AuthService {
return true
} catch(e) {
console.log(e)
return false
}
+2 -2
View File
@@ -129,7 +129,7 @@ export class MessageService {
this.offline = false
})
} else if(this.WsChatService.isLogin == false) {
alert('registerCallback')
this.WsChatService.registerCallback({
type: 'reConnect',
@@ -141,7 +141,7 @@ export class MessageService {
})
} else if(uploadSuccessfully == false) {
alert('this.WsChatService.isLogin '+ this.WsChatService.isLogin+ '')
this.errorUploadingAttachment = true
}
+1 -2
View File
@@ -132,7 +132,6 @@ export class RoomService {
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
})
this.WsChatService.registerCallback
}
@@ -160,7 +159,7 @@ export class RoomService {
}
)
this.WsChatService.registerCallback
}
/**
@@ -69,6 +69,39 @@ export class WsChatMethodsService {
}
})
// console.log("ROOMS" + JSON.stringify(rooms))
// this.WsChatService.registerCallback({
// type:'Onmessage',
// funx:(message) => {
// if(message.msg =='changed' && message.collection == "stream-room-messages") {
// if(message.fields.args[0].rid) {
// // new message
// const ChatMessage = message.fields.args[0]
// const messageId = ChatMessage.rid
// setTimeout(()=>{
// this.sortRoomList()
// }, 100)
// }
// }
// if(message.msg =='changed' && message.collection == "stream-notify-room") {
// if(message.fields.eventName.includes('deleteMessage')){
// // delete message
// const DeletedMessageId = message.fields.args[0]._id;
// setTimeout(()=>{
// this.sortRoomList()
// }, 100)
// }
// }
// }
// })
}
getRoomFromDb() {
@@ -132,32 +165,6 @@ export class WsChatMethodsService {
this._dm = []
this._group = []
// console.log("ROOMS" + JSON.stringify(rooms))
this.WsChatService.registerCallback({
type:'Onmessage',
funx:(message)=>{
if(message.msg =='changed' && message.collection == "stream-room-messages") {
if(message.fields.args[0].rid) {
setTimeout(()=>{
this.sortRoomList()
}, 100)
}
}
if(message.msg =='changed' && message.collection == "stream-notify-room") {
if(message.fields.eventName.includes('deleteMessage')){
setTimeout(()=>{
this.sortRoomList()
}, 100)
}
}
}
})
await rooms.result.update.forEach( async (roomData: room) => {
await this.prepareRoom(roomData);
});
@@ -276,20 +283,20 @@ export class WsChatMethodsService {
*/
private getUserStatus(id?:string) {
this.WsChatService.getUserStatus((d) => {
// this.WsChatService.getUserStatus((d) => {
const username = d.fields.args[0][1]
const statusNum = d.fields.args[0][2]
// const username = d.fields.args[0][1]
// const statusNum = d.fields.args[0][2]
const statusText = this.statusNumberToText(statusNum)
// const statusText = this.statusNumberToText(statusNum)
const user = this.getUserByName(username)
// const user = this.getUserByName(username)
if(user) {
user.status = statusText
}
// if(user) {
// user.status = statusText
// }
})
// })
}
+10 -12
View File
@@ -15,13 +15,6 @@ export class WsChatService {
loginResponse = {}
constructor() {
window.addEventListener('online', ()=>{
this.connect()
this.login()
});
}
connect() {
@@ -612,13 +605,16 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
private wsCallbacks: {[key: string]: wsCallbacksParams} = {}
private wsReconnect = 0
private n = 0
private ws = {
connected: false,
registerCallback:(params: wsCallbacksParams) => {
let id = params.requestId || params.key || uuidv4()
this.wsCallbacks[id] = params
this.n++
console.log('n', this.n)
return id
},
connect:()=> {
@@ -629,7 +625,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
this.socket.onclose = this.ws.onclose;
this.socket.onerror = this.ws.onerror;
},
onopen:()=> {
onopen: async ()=> {
this.ws.connected = true
console.log('================== welcome to socket server =====================')
@@ -639,9 +635,10 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
if(this.wsReconnect >= 1) {
for (const [key, value] of Object.entries(this.wsCallbacks)) {
if(value.type== 'reConnect') {
const dontRepeat = value.funx()
const dontRepeat = await value.funx()
if(dontRepeat) {
this.n--
delete this.wsCallbacks[key]
}
@@ -681,15 +678,16 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
return requestId
},
onmessage:(event: any)=> {
onmessage: async (event: any)=> {
const data = JSON.parse(event.data)
for (const [key, value] of Object.entries(this.wsCallbacks)) {
if(value.type== 'Onmessage') {
const dontRepeat = value.funx(data)
const dontRepeat = await value.funx(data)
if(dontRepeat) {
delete this.wsCallbacks[key]
this.n--
}
}