diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 436971e6b..81f69a237 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -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() diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index f0d13f94e..d9e4db818 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -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 } diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 142619315..b33c0f323 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -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 } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index a68b496f4..0e0f7a6e6 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -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 + } /** diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index c9056f1ef..a10357427 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -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 + // } - }) + // }) } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 5b9cf96c8..8c47f8827 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -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-- } }