mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
send offline message
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Subject, timer } from 'rxjs';
|
||||
import { BehaviorSubject, Observable, Subject, timer } from 'rxjs';
|
||||
import { Platform } from '@ionic/angular';
|
||||
import { SignalRConnection } from './signalR';
|
||||
import { Plugins } from '@capacitor/core';
|
||||
@@ -102,6 +102,16 @@ export class SignalRService {
|
||||
this.sendDataSubject.next(data)
|
||||
this.deadConnectionBackGround.next()
|
||||
})
|
||||
|
||||
this.connection.getConnectionState().subscribe((data) => {
|
||||
this.connectingSubject.next(data)
|
||||
})
|
||||
} else {
|
||||
|
||||
setTimeout(() => {
|
||||
this.establishConnection()
|
||||
}, 2000)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -131,6 +141,9 @@ export class SignalRService {
|
||||
getData() {
|
||||
return this.sendDataSubject.asObservable()
|
||||
}
|
||||
public getConnectionState(): Observable<boolean> {
|
||||
return this.connectingSubject.asObservable();
|
||||
}
|
||||
|
||||
async sendMessage(data: Object) {
|
||||
return await this.connection.sendMessage(data as any)
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user