पर क्लिक करते समय एक कस्टम यूआरएल खोलें, मैं अपनी वेबसाइट के उपयोगकर्ताओं को पुश नोटिफिकेशन भेजने के लिए Webpush ruby gem लागू कर रहा हूं।वेब पुश अधिसूचना
सर्वर कोड:
Webpush.payload_send({
message: notification.message,
url: notification.url, # I can't figure out how to access this key
id: notification.id, # or this key from the service worker
endpoint: endpoint,
p256dh: p256dh_key,
vapid: vapid_keys,
ttl: 24 * 60 * 60,
auth: auth_key,
})
मैं एक सेवा कार्यकर्ता अधिसूचना दिखाने के लिए और यह क्लिक करने योग्य बना क्लाइंट पक्ष पर स्थापित किया है।
self.addEventListener("push", function (event) {
var title = (event.data && event.data.text()) || "New Message";
event.waitUntil(
self.registration.showNotification(title, {
body: "New push notification",
icon: "/images/[email protected]",
tag: "push-notification-tag",
data: {
url: event.data.url, // This is returning null
id: event.data.id // And this is returning null
}
})
)
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(
clients.openWindow(event.data.url + "?notification_id=" + event.data.id)
);
})
यह सब ठीक कस्टम कुंजी (url
, id
) है कि मैं के माध्यम से गुजर रहा हूँ सेवा कार्यकर्ता के भीतर से सुलभ नहीं हैं को छोड़कर काम कर रहा है,।
क्या कोई भी वेबपश मणि के माध्यम से कस्टम डेटा को पारित करने के बारे में जानता है?
इसमें कोई विशेषज्ञ नहीं है, लेकिन मैं ऐसा करूंगा: संदेश: JSON.stringify (अधिसूचना) सर्वर, और JSON.parse क्लाइंट पर ... –
@ जोनास - मैं आपके समाधान के साथ जा रहा था। यदि आप इसे उत्तर के रूप में लिखते हैं, तो मैं इसे स्वीकार करूंगा। सहायता के लिए धन्यवाद। – BananaNeil