Inicialize and register browser for web notification

This commit is contained in:
Eudes Inácio
2021-09-07 12:09:01 +01:00
parent 23d73c6d5f
commit 7929d9f3fb
15 changed files with 282 additions and 331 deletions
+5 -1
View File
@@ -35,6 +35,8 @@ import {MatDatepickerModule} from '@angular/material/datepicker';
import {MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
import { NgxMatDateFormats, NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
import { Network } from '@ionic-native/network/ngx';
import { Media } from '@ionic-native/media/ngx';
import { File } from '@ionic-native/file/ngx';
import {
@@ -106,7 +108,9 @@ import { PdfViewerModule } from 'ng2-pdf-viewer';
WebsocketService,
ChatService,
ScreenOrientation,
Network
Network,
Media,
File
],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
+10 -3
View File
@@ -18,6 +18,8 @@ import { ExpedienteGdStore } from '../store/expedientegd-store.service';
import { InativityService } from '../services/inativity.service';
import { SessionStore } from '../store/session.service';
import { StorageService } from '../services/storage.service';
import { Media, MediaObject } from '@ionic-native/media/ngx';
import { File } from '@ionic-native/file/ngx';
@Component({
selector: 'app-home',
@@ -60,6 +62,9 @@ export class HomePage implements OnInit {
synchro = synchro
status:string="";
audioFile:MediaObject = this.media.create(this.file.externalRootDirectory+"/audioGabinete.mp3");
audioName:string="";
constructor(
private zone: NgZone,
private router: Router,
@@ -72,7 +77,9 @@ export class HomePage implements OnInit {
public documentCounterService: DocumentCounterService,
private despachoRule: DespachoService,
private inativityService: InativityService,
private storageService: StorageService,) {
private storageService: StorageService,
private media: Media,
private file: File ) {
this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
@@ -110,14 +117,14 @@ export class HomePage implements OnInit {
console.log('Active route ', this.router.url)
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.webnotification.webconnection();
this.webnotification.onReceviNotificationWeb();
this.webnotification.register();
} else {
this.mobilefirstConnect();
this.notificationsService.getAndpostToken2();
this.notificationsService.onReceviNotification();
}
}
mobilefirstConnect() {
if(window['WLAuthorizationManager']) {
@@ -255,6 +255,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
const roomId = this.roomId
this.chatService.getRoomMessages(roomId).subscribe(async res => {
console.log("Chat message",res)
if (res == 502) {
// Connection timeout
+1 -78
View File
@@ -60,7 +60,7 @@ export class NotificationsService {
getAndpostToken(username) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Notifications not supported')
//console.log('Notifications not supported')
} else {
const geturl = environment.apiURL + 'notifications/token';
@@ -113,87 +113,10 @@ export class NotificationsService {
}
}
}
}
getAndpostToken2() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Notifications not supported')
} else {
const geturl = environment.apiURL + 'notifications/token';
if(window['WLAuthorizationManager']) {
if(window['WLAuthorizationManager'].obtainAccessToken) {
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
window['MFPPush'].initialize(
function (successResponse) {
console.log("Push notification Successfully Service intialized: " + successResponse);
},
function (failureResponse) {
console.log("Push notification failure Service intialized: " + failureResponse);
}
);
window['MFPPush'].registerDevice(null, (successResponse) => {
console.log("Successfully registered: " + JSON.stringify(successResponse));
console.log('token: ', successResponse.deviceId)
/* this.storageService.store(username, successResponse.deviceId);
this.storageService.get(username).then(value => {
console.log('STORAGE TOKEN', value)
this.storageService.get(AuthConnstants.USER).then(res => {
console.log('USERID', res);
const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' };
const body = {
UserId: res.UserId,
TokenId: successResponse.deviceId,
Status: 1,
Service: 1
};
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
console.log('TOKEN USER MIDLE', data);
})
});
}); */
},
function (failureResponse) {
console.log("Successfully failue: " + JSON.stringify(failureResponse));
}
);
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
)
} else {
console.log('not called')
}
} else {
console.log('not called')
}
}
}
removeDepartment(index): void {
/* this.DataArray[this.DataArray.findIndex(item => item.index == index)];
this.DataArray.splice( this.DataArray.findIndex(item => item.indexOf(index.to) === 'William'),1); */
const indexx = this.DataArray.indexOf(index, 0);
if (indexx > -1) {
this.DataArray.splice(index, 1);
console.log('This notificatio', this.DataArray);
}
}
tempClearArray(){
this.DataArray = [];
}
+136 -125
View File
@@ -5,7 +5,7 @@ import { StorageService } from 'src/app/services/storage.service';
import { AuthConnstants } from 'src/app/config/auth-constants';
import { Token } from '../models/token.model';
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
import { NavigationExtras,Router } from '@angular/router';
import { NavigationExtras, Router } from '@angular/router';
import { ToastService } from './toast.service';
import MFPPush from 'ibm-mfp-web-push';
@@ -31,29 +31,142 @@ export class WebNotificationsService {
webconnection() {
/* MFPPush.initialize({
appId: "com.gpr.gabinetedigital",
mfpContextRoot: "/mfp",
}); */
MFPPush.registerDevice()
.then((res) => {
console.log("WEB Successfully Registered Device...");
})
.catch((err) => {
console.log("WEB Registration Failed" + err);
});
var inicializeObj = {
appId: "com.gpr.gabinetedigital",
mfpContextRoot: "/mfp",
/* serverUrl: "http://gpr-dev-10.gabinetedigital.local:9080",
safariWebsitePushId: "http://gpr-dev-10.gabinetedigital.local:9080", */
}
MFPPush.initialize({
appId: "com.gpr.gabinetedigital",
mfpContextRoot: "/mfp",
});
}
async onReceviNotificationWeb() {
register(){
MFPPush.registerDevice()
.then((res) => {
console.log("WEB Successfully Registered Device...", res);
})
.catch((err) => {
console.log("WEB Registration Failed" + err);
});
}
async onReceviNotificationWeb() {
if (window['WLAuthorizationManager']) {
if (window['WLAuthorizationManager'].obtainAccessToken) {
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
MFPPush.initialize(
function (successResponse) {
console.log("Push notification Successfully intialized: " + successResponse);
MFPPush.registerNotificationsCallback(notificationReceived);
},
function (failureResponse) {
console.log("Push notification failure intialized: " + failureResponse);
}
);
var notificationReceived = (message) => {
console.log(message);
var data = JSON.parse(message.payload);
console.log(data.Service);
console.log(data.IdObject);
console.log(data.Object);
if (message.actionName) {
//this.notificatinsRoutes(data);
console.log("Web notification")
} else {
console.log("Web notification")
//this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
}
}
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
);
}
}
}
/* getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
return this.http.get<Token[]>(`${geturl}`);
} */
/* getAndpostToken(username) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Notifications not supported')
} else {
const geturl = environment.apiURL + 'notifications/token'; */
/*
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
if(window['WLAuthorizationManager']) {
if(window['WLAuthorizationManager'].obtainAccessToken) {
MFPPush.initialize(
function (successResponse) {
console.log("Push notification Successfully Service intialized: " + successResponse);
},
function (failureResponse) {
console.log("Push notification failure Service intialized: " + failureResponse);
}
);
MFPPush.registerDevice(null, (successResponse) => {
console.log("Successfully registered: " + JSON.stringify(successResponse));
console.log('token: ', successResponse.deviceId)
this.storageService.store(username, successResponse.deviceId);
this.storageService.get(username).then(value => {
console.log('STORAGE TOKEN', value)
this.storageService.get(AuthConnstants.USER).then(res => {
console.log('USERID', res);
const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' };
const body = {
UserId: res.UserId,
TokenId: successResponse.deviceId,
Status: 1,
Service: 1
};
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
console.log('TOKEN USER MIDLE', data);
})
});
});
},
function (failureResponse) {
console.log("Successfully failue: " + JSON.stringify(failureResponse));
}
);
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
);
}
} */
/*
async onReceviNotification() {
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
MFPPush.initialize(
function (successResponse) {
console.log("Push notification Successfully intialized: " + successResponse);
@@ -69,122 +182,20 @@ async onReceviNotificationWeb() {
console.log(data.Service);
console.log(data.IdObject);
console.log(data.Object);
if(message.actionName){
//this.notificatinsRoutes(data);
console.log("Web notification")
this.notificatinsRoutes(data);
} else {
console.log("Web notification")
//this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
}
}
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
);
}
}
}
/* getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
return this.http.get<Token[]>(`${geturl}`);
} */
/* getAndpostToken(username) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Notifications not supported')
} else {
const geturl = environment.apiURL + 'notifications/token'; */
/*
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
MFPPush.initialize(
function (successResponse) {
console.log("Push notification Successfully Service intialized: " + successResponse);
},
function (failureResponse) {
console.log("Push notification failure Service intialized: " + failureResponse);
}
);
MFPPush.registerDevice(null, (successResponse) => {
console.log("Successfully registered: " + JSON.stringify(successResponse));
console.log('token: ', successResponse.deviceId)
this.storageService.store(username, successResponse.deviceId);
this.storageService.get(username).then(value => {
console.log('STORAGE TOKEN', value)
this.storageService.get(AuthConnstants.USER).then(res => {
console.log('USERID', res);
const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' };
const body = {
UserId: res.UserId,
TokenId: successResponse.deviceId,
Status: 1,
Service: 1
};
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
console.log('TOKEN USER MIDLE', data);
})
});
});
},
function (failureResponse) {
console.log("Successfully failue: " + JSON.stringify(failureResponse));
}
);
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
);
}
} */
/*
async onReceviNotification() {
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
MFPPush.initialize(
function (successResponse) {
console.log("Push notification Successfully intialized: " + successResponse);
MFPPush.registerNotificationsCallback(notificationReceived);
},
function (failureResponse) {
console.log("Push notification failure intialized: " + failureResponse);
}
);
var notificationReceived = (message) => {
console.log(message);
var data = JSON.parse(message.payload);
console.log(data.Service);
console.log(data.IdObject);
console.log(data.Object);
if(message.actionName){
this.notificatinsRoutes(data);
} else {
this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
}
}
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
);
} */
} */
/* notificatinsRoutes = (data) => {
if (data.Service === "agenda") {