diff --git a/src/app/models/rochet-chat-cliente-service.ts b/src/app/models/rochet-chat-cliente-service.ts index 46698ca58..96e2aeb57 100644 --- a/src/app/models/rochet-chat-cliente-service.ts +++ b/src/app/models/rochet-chat-cliente-service.ts @@ -1,5 +1,5 @@ export interface wsCallbacksParams { - type: 'Offline' | 'Online' | 'Open' | 'Onmessage', + type: 'Offline' | 'Online' | 'Open' | 'Onmessage' | 'reConnect', funx: Function runOnces?: boolean requestId?: string diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index fa9b44579..4208e6ca7 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -54,6 +54,18 @@ export class WsChatMethodsService { })() + + /** + * @description when the phone is in the background for a long time it could disconnects from the socket then the socket reconnects automatically, + * when the connection is lost the subscribe is also lost, so we have to subscribe again when reconnection is establish. + */ + this.WsChatService.registerCallback({ + type: 'reConnect', + funx: ()=>{ + this.subscribeToRoom() + } + }) + } openRoom(roomId) { @@ -116,11 +128,17 @@ export class WsChatMethodsService { this.loadingWholeList = false } + /** + * @description sort room list by last message date + */ sortRoomList() { this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse() this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse() } + /** + * @description subscribe all room + */ subscribeToRoom() { for (const id in this.dm) { diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index bf89d11eb..3abc1ae4e 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -572,6 +572,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { private socket!: WebSocket; private wsMsgQueue : {[key: string]: msgQueue} = {} private wsCallbacks: {[key: string]: wsCallbacksParams} = {} + private wsReconnect = 0 private ws = { connected: false, @@ -592,9 +593,26 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { }, onopen:()=> { this.ws.connected = true + console.log('================== welcome to socket server =====================') this.ws.wsMsgQueue() + + if(this.wsReconnect >= 1) { + for (const [key, value] of Object.entries(this.wsCallbacks)) { + if(value.type== 'reConnect') { + const dontRepeat = value.funx() + + if(dontRepeat) { + delete this.wsCallbacks[key] + } + + } + + } + } + + this.wsReconnect++; }, wsMsgQueue:()=> { diff --git a/src/app/services/fileExprorer/file-exprorer.service.spec.ts b/src/app/services/fileExprorer/file-exprorer.service.spec.ts new file mode 100644 index 000000000..3b67df09b --- /dev/null +++ b/src/app/services/fileExprorer/file-exprorer.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { FileExprorerService } from './file-exprorer.service'; + +describe('FileExprorerService', () => { + let service: FileExprorerService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(FileExprorerService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/fileExprorer/file-exprorer.service.ts b/src/app/services/fileExprorer/file-exprorer.service.ts new file mode 100644 index 000000000..ab477e33a --- /dev/null +++ b/src/app/services/fileExprorer/file-exprorer.service.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class FileExprorerService { + + constructor() { } +}