add endpoint

This commit is contained in:
Peter Maquiran
2024-08-02 16:20:26 +01:00
parent 68a7eb8bad
commit 643bfe8310
9 changed files with 168 additions and 198 deletions
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Subject, timer } from 'rxjs';
import { Platform } from '@ionic/angular';
import { SignalRConnection } from './signalR';
import { Plugins } from '@capacitor/core';
@@ -7,6 +7,7 @@ import { UserTypingDTO } from '../../data/dto/typing/typingInputDTO';
import { MessageOutPutDataDTO } from '../../data/dto/message/messageOutputDTO';
import { MessageDeleteInputDTO } from '../../data/dto/message/messageDeleteInputDTO';
import { object, z } from 'zod';
import { switchMap } from 'rxjs/operators';
const { App } = Plugins;
@@ -32,27 +33,34 @@ export class SignalRService {
private messageUpdateSubject: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
private sendDataSubject: BehaviorSubject<Object> = new BehaviorSubject<Object>(false);
private deadConnectionBackGround: Subject<any>;
constructor(
private platform: Platform) {
// this.startConnection();
// this.addMessageListener();
constructor(private platform: Platform) {
this.deadConnectionBackGround = new Subject()
this.deadConnectionBackGround.pipe(
switchMap(() => timer(300000)),
).subscribe(() => {
this.newConnection()
})
try {
if (!this.platform.is('desktop')) {
App.addListener('appStateChange', ({ isActive }) => {
if (isActive) {
// The app is in the foreground.
console.log('App is in the foreground');
// console.log('App is in the foreground');
this.deadConnectionBackGround.next()
this.newConnection()
} else {
// The app is in the background.
console.log('App is in the background');
// You can perform actions specific to the background state here.
}
});
} else {
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
this.deadConnectionBackGround.next()
}
});
}
} catch(error) {}
@@ -75,6 +83,7 @@ export class SignalRService {
})
this.connection.getMessages().subscribe((data) => {
console.log("receive message 55")
this.messageSubject.next(data)
})
this.connection.getTyping().subscribe((data) => {
@@ -89,12 +98,9 @@ export class SignalRService {
this.messageUpdateSubject.next(data)
})
this.connection.getMessageUpdateSubject().subscribe((data) => {
this.messageUpdateSubject.next(data)
})
this.connection.getData().subscribe((data) => {
this.messageUpdateSubject.next(data)
this.sendDataSubject.next(data)
this.deadConnectionBackGround.next()
})
}