0
내 웹 페이지가 백그라운드 (최소화 된 창 또는 다른 라벨)에있을 때 밀어 넣기 메시지를받을 수 없으므로 알림이 표시되지만 확인 메시지는 나타나지 않습니다. post.js를 게시 메시지를 다시 보내려고 할 때.FCM 웹 백그라운드 서비스 담당자
sw.js :
messaging.setBackgroundMessageHandler(function (payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
const title = '¡Mensaje Nuevo!';
const options = {
body: 'conductor: ' + payload.data.chofer_id + ' - ' + payload.data.mensaje,
icon: '/icono.png',
};
send_message_to_all_clients('sound');
return self.registration.showNotification(title, options);
});
function send_message_to_all_clients(msg) {
clients.matchAll().then(clients => {
clients.forEach(client => {
send_message_to_client(client, msg).then(m => console.log("SW Received Message: " + m));
})
})
}
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("SW Says: '" + msg + "'", [msg_chan.port2]);
});
}
page.js
// Handler for messages coming from the service worker
navigator.serviceWorker.addEventListener('message', function (event) {
console.log("Client 1 Received Message: " + event.data);
$.playSound('Sounds/Tethys.mp3');
});
내가 메시지를 보내
내가 웹 페이지에있어, 콘솔 로그 쇼와 사운드 재생 :클라이언트 1받은 메시지 : [object object]
배경에는 절대로 없습니다.
제발 도와주세요, 오래되었습니다.