send offline message

This commit is contained in:
Peter Maquiran
2024-08-07 15:23:23 +01:00
parent b0a334c9dd
commit bbacc35b08
9 changed files with 172 additions and 4 deletions
+10 -2
View File
@@ -27,6 +27,7 @@ export class SignalRConnection {
private sendDataSubject: BehaviorSubject<{method: string, data: any}> = new BehaviorSubject<{method: string, data: any}>(null);
private pendingRequests: Map<string, { resolve: Function; reject: Function }> = new Map();
url: string
private hasConnectOnce = false
constructor({url}) {
this.url = url
@@ -44,6 +45,7 @@ export class SignalRConnection {
hubConnection
.start()
.then(() => {
this.hasConnectOnce = true
console.log('Connection started');
this.connectionStateSubject.next(true);
this.hubConnection = hubConnection
@@ -54,7 +56,13 @@ export class SignalRConnection {
.catch(error => {
console.log('Error while starting connection: ' + error);
this.connectionStateSubject.next(false);
reject(err(false))
if(this.hasConnectOnce) {
setTimeout(()=> {
this.attempReconnect();
}, 2000)
}
resolve(err(false))
});
hubConnection.onclose(() => {
@@ -64,7 +72,7 @@ export class SignalRConnection {
this.pendingRequests.forEach((_, requestId) => {
const { reject } = this.pendingRequests.get(requestId);
reject(err('Connection closed================!s'));
reject(err(false));
this.pendingRequests.delete(requestId);
});