monit notification

This commit is contained in:
Peter Maquiran
2024-06-18 12:03:38 +01:00
parent 869d403f4e
commit 6a6f58ec0d
9 changed files with 182 additions and 134 deletions
+25 -8
View File
@@ -18,7 +18,7 @@ import { ChatService } from 'src/app/services/chat.service';
import { FCM } from '@capacitor-community/fcm';
import { ChatSystemService } from './chat/chat-system.service';
import {ChatController} from 'src/app/controller/chat'
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
@Injectable({
providedIn: 'root'
})
@@ -99,7 +99,8 @@ export class NotificationsService {
}
}
private getAndpostToken(username) {
@XTracerAsync({name:'Notification/getAndpostToken', log: false, bugPrint: true, module:'notification', autoFinish: false})
private getAndpostToken(username, tracing?: TracingType) {
const geturl = environment.apiURL + 'notifications/token';
if (this.platform.is('mobile')) {
@@ -109,31 +110,44 @@ export class NotificationsService {
if (this.platform.is('ios')) {
FCM.getToken()
.then(r => {
this.postToken(r.token, geturl)
this.postToken(r.token, geturl, tracing)
this.token = r.token
tracing.setAttribute('notification.token', 'true')
tracing.setAttribute('outcome', 'success')
// alert(this.token)
})
.catch(err => console.log(err));
.catch(err => {
console.log(err)
tracing.setAttribute('notification.token', 'false')
tracing.setAttribute('outcome', 'failed')
});
} else {
PushNotifications.addListener('registration',
(token: Token) => {
this.postToken(token.value, geturl)
this.postToken(token.value, geturl, tracing)
this.token = token.value
tracing.setAttribute('notification.token', 'true')
}
);
}
} else {
tracing.setAttribute('notification.request', 'true')
this.afMessaging.requestToken.subscribe(
(token) => {
// Save the token to your server for sending notifications
console.log('Permission granted! Token:', token);
this.postToken(token, geturl)
this.postToken(token, geturl, tracing)
this.token = token
tracing.setAttribute('notification.token', 'true')
tracing.setAttribute('outcome', 'success')
},
(error) => {
console.error('Permission denied:', error);
tracing.setAttribute('notification.token', 'false')
tracing.setAttribute('outcome', 'failed')
}
);
}
@@ -146,7 +160,7 @@ export class NotificationsService {
this.DeleteToken(geturl)
}
postToken(token, geturl) {
postToken(token, geturl, tracing: TracingType) {
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {
UserId: SessionStore.user.UserId,
@@ -156,8 +170,11 @@ export class NotificationsService {
};
this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
this.active = true
tracing.setAttribute('outcome','success')
tracing.finish()
}, (error) => {
tracing.setAttribute('outcome','failed')
tracing.finish()
})
}