mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
fix message
This commit is contained in:
@@ -1,117 +0,0 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
/* eslint-disable no-undef */
|
||||
/* eslint-disable no-restricted-globals */
|
||||
|
||||
// const regex = /{{\s*([^}]+)\s*}}/g;
|
||||
// var _pushVaribales = "";
|
||||
|
||||
// function interpolate(messageData) {
|
||||
// return function interpolate(o) {
|
||||
// return messageData.replace(regex, function (a, b) {
|
||||
// var r = o[b];
|
||||
// return typeof r === 'string' || typeof r === 'number' ? r : a;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// function createTemplateMessage(messageData) {
|
||||
// if (Object.keys(_pushVaribales).length > 0 ) {
|
||||
// var message = interpolate(messageData)(_pushVaribales);
|
||||
// return message;
|
||||
// } else {
|
||||
// return messageData;
|
||||
// }
|
||||
// }
|
||||
|
||||
// function displayNotification(event) {
|
||||
// var messageJson = event.data.text();
|
||||
// messageJson = JSON.parse(messageJson);
|
||||
// var title = messageJson.title ? messageJson.title : "New message";
|
||||
// var imageUrl = messageJson.iconUrl ? messageJson.iconUrl : "images/icon.png";
|
||||
// // var tagJson = messageJson.payload;
|
||||
// // var tag = tagJson.tag ? tagJson.tag : "";
|
||||
// var bodyAlert = messageJson.alert ? messageJson.alert : "Example message"
|
||||
// var payloadData = messageJson.payload ? messageJson.payload : "Example message"
|
||||
// let messageTemp;
|
||||
// if ((messageTemp = regex.exec(bodyAlert)) !== null) {
|
||||
// bodyAlert = createTemplateMessage(bodyAlert);
|
||||
// }
|
||||
// self.registration.showNotification(title, {
|
||||
// body: bodyAlert,
|
||||
// icon: imageUrl,
|
||||
// data: payloadData,
|
||||
// // tag: tag
|
||||
// });
|
||||
// return Promise.resolve();
|
||||
// }
|
||||
|
||||
|
||||
// function triggerSeenEvent(strMsg) {
|
||||
// send_message_to_all_clients("msgEventSeen:" + strMsg);
|
||||
// }
|
||||
|
||||
// function triggerOpenEvent(strMsg) {
|
||||
// send_message_to_all_clients("msgEventOpen:" + strMsg);
|
||||
// }
|
||||
|
||||
// function onPushNotificationReceived(event) {
|
||||
|
||||
// if (event.data) {
|
||||
|
||||
// }
|
||||
// event.waitUntil(displayNotification(event).then(() => triggerSeenEvent(event.data.text())));
|
||||
// };
|
||||
|
||||
// self.addEventListener('push', onPushNotificationReceived);
|
||||
|
||||
// function send_message_to_client(client, msg) {
|
||||
// return new Promise(function (resolve, reject) {
|
||||
// var msg_chan = new MessageChannel();
|
||||
|
||||
// msg_chan.port1.onmessage = function (event) {
|
||||
// if (event.data.error) {
|
||||
// reject(event.data.error);
|
||||
// } else {
|
||||
// resolve(event.data);
|
||||
// }
|
||||
// };
|
||||
|
||||
// client.postMessage(msg, [msg_chan.port2]);
|
||||
// });
|
||||
// }
|
||||
|
||||
// function send_message_to_all_clients(msg) {
|
||||
// clients.matchAll().then(clients => {
|
||||
// clients.forEach(client => {
|
||||
// send_message_to_client(client, msg);
|
||||
// })
|
||||
// });
|
||||
// }
|
||||
|
||||
// self.addEventListener('install', function (event) {
|
||||
// self.skipWaiting();
|
||||
|
||||
// //event.postMessage("SW Says 'Hello back!'");
|
||||
// });
|
||||
|
||||
// self.addEventListener('message', function (event) {
|
||||
// replyPort = event.ports[0];
|
||||
// _pushVaribales = event.data;
|
||||
// });
|
||||
|
||||
// self.addEventListener('activate', function (event) {
|
||||
|
||||
// event.waitUntil(self.clients.claim());
|
||||
// });
|
||||
|
||||
// self.addEventListener('notificationclick', function (event) {
|
||||
|
||||
// let nidjson = event.notification.data;
|
||||
// event.notification.close();
|
||||
// event.waitUntil(triggerOpenEvent(nidjson));
|
||||
// });
|
||||
|
||||
// self.addEventListener('pushsubscriptionchange', function () {
|
||||
|
||||
// send_message_to_all_clients("updateRegistration:");
|
||||
// });
|
||||
@@ -0,0 +1,71 @@
|
||||
importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js');
|
||||
importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js');
|
||||
|
||||
// Initialize the Firebase app in the service worker by passing the generated config
|
||||
var firebaseConfig = {
|
||||
apiKey: "AIzaSyAAdHmTFznCMerdT99nrewJgISRvtxPqoY",
|
||||
authDomain: "gabinete-digital-2020.firebaseapp.com",
|
||||
databaseURL: "https://gabinete-digital-2020.firebaseio.com",
|
||||
projectId: "gabinete-digital-2020",
|
||||
storageBucket: "gabinete-digital-2020.appspot.com",
|
||||
messagingSenderId: "800733765231",
|
||||
appId: "1:800733765231:web:28e7792ab150006513779a",
|
||||
measurementId: "G-8QN4BLZ8XK"
|
||||
};
|
||||
|
||||
firebase.initializeApp(firebaseConfig);
|
||||
|
||||
// Retrieve firebase messaging
|
||||
const messaging = firebase.messaging();
|
||||
|
||||
messaging.onBackgroundMessage(function(payload) {
|
||||
console.log('Received background message 22 bbb ', payload);
|
||||
|
||||
const notificationTitle = payload.notification.title;
|
||||
const notificationOptions = {
|
||||
body: payload.notification.body,
|
||||
};
|
||||
|
||||
/* self.registration.showNotification(notificationTitle,
|
||||
notificationOptions); */
|
||||
});
|
||||
|
||||
|
||||
self.addEventListener('install', function(event) {
|
||||
self.skipWaiting();
|
||||
// console.log('Installed', event);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', function(event) {
|
||||
// console.log('Activated', event);
|
||||
});
|
||||
|
||||
self.addEventListener('push', function(event) {
|
||||
|
||||
var uid = "EXISTS_IN_CORE.JS";
|
||||
var token = "ALSO_EXISTS_IN_CORE.JS";
|
||||
|
||||
// console.log("Push recieved - we need to know the uid and token here, from core.js");
|
||||
});
|
||||
|
||||
self.addEventListener('message', function(event){
|
||||
// var data = JSON.parse(event.data);
|
||||
|
||||
// console.log("SW Received Message:");
|
||||
// console.log(event.data);
|
||||
|
||||
|
||||
});
|
||||
|
||||
/* self.addEventListener('notificationclick', function(event) {
|
||||
console.log("Push Clicked ", event);
|
||||
// Enviar uma mensagem para o cliente (componente)
|
||||
self.clients.matchAll().then((clients) => {
|
||||
console.log("Push Clicked 2", clients);
|
||||
if (clients && clients.length) {
|
||||
clients.forEach((client) => {
|
||||
client.postMessage({ notificationClicked: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
}); */
|
||||
Reference in New Issue
Block a user