When implementing push notifications using service worker, we can directly push the notifications to the endpoint. But in my website the notifications are fetched from an outside API. So Is there any way from my service worker to poll for notifications so that I can identify if a new notification is present?
If your web application is open, you can show notifications by checking for some criteria (polling an API, etc.) and then using the Notifications API.
This does not require a service worker. Using a service worker + push events to trigger your notifications means that your notifications will appear even if your web application is closed, and it also is more efficient to rely on listening for push events vs. repeatedly polling an API.
You could theoretically use a combination of polling and explicitly calling the Notifications API when your web app is open in addition to registering a service worker that listens for push events. But if you're putting in the effort to support the service worker use case, just relying on the service worker for all of your notifications might be cleaner.
One difference between the two approaches is that using the Notifications API while your web application is supported in more browsers (as of August 2017) than service worker-based push notifications.
Related
I need to send push notification even the site is closed, So I've tried service worker and web worker even web socket but it didn't works fine. It need FCM(Firebase Cloud messaging) to transfer payload from server
,but my server don't support Nodejs so I can't use Firebase
I need a solution to create a custom endpoint to delivery payload to a client in the Background. So, I can push a notification from the Service worker instantly even the site is closed
I am designing a Notification Engine (Java Based) which will be used as an one stop shop for various other systems to send notification to different channels (push notifications, SMS, email etc). I wish to build this system to use Kafka as a message broker component (there will be many other components as well).
My query is specific to app push notifications (our current system uses FCM topic based subscribed notifications coming from individual systems who publish). The New Notification Engine will be working as the Kafka Producer and publish messages in regular intervals ( as configured in the Scheduler Component of this system) to the topics. How do the app user get the notifications as soon as they are published ? I am assuming the apps here have to work as Kafka Consumer. What is the best way to achieve this ? Is Kafka REST Proxy an option for the Mobile Apps to act like Kafka Consumers ? Would it be overload for mobile app to handle all the consumer responsibility ?
I am making a website and one of the features is that whenever a contract is nearing its end, the user should be notified about it. So I was looking for a way to notify users and I found out about push notifications.
Now, there are lots of things written about it. I heard a lot about Google Cloud Messaging, Firebase Cloud Messaging and Service Workers.
Now the thing is that my website will probably be on an Intranet. So maybe I won't be able to use GCM/FCM.
But I have a few questions regarding GCM, FCM and Service-Workers:
Why do I need FCM/GCM?
What is the difference between FCM and Service Workers?
Is there a way to push notifications even if the browser is closed?
Because my website is on an Intranet, is there another way to push notifications to the users?
1. Why do I need FCM/GCM?
You may check here the features of FCM.
Notification payload: 4KB, Message payload: 2KB. Note that the notification includes device and app information too.
Stores 100 notification/messages per device if the device is offline.
Stores notification/messages for 30 days if the device is offline, and deleted them all one this period is over and the device is still offline.
FCM supports Android and iOS devices, and even chrome web apps. The notifications are sent to iOS devices in this way: App Server -> FCM -> Apple Push Notification Server (APNs) -> iOS device -> App.
GCM supports 1 million subscribers while FCM do not have this limitation.
Supports programming in C++.
Less requirements for coding.
2. What is the difference between FCM and Service Workers?
Service Worker is a background service that handles network requests. Ideal for dealing with offline situations and background syncs or push notifications. Cannot directly interact with the DOM. Communication must go through the Service Worker’s postMessage method. Service Workers are pretty perfect for creating offline-first web apps. They let you interact with the server when you can (to fetch new data from the server, or push updated info back to the server), so your app can work regardless of your user’s connectivity.
While using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.
3. Is there a way to push notifications even if the browser is closed?
Check this thread: Notifications while browser is closed
4. Because my website is on an Intranet, is there another way to push notifications to the users?
Unfortunately, I don't see any documentation regarding this.
Hope my answers help you.
I have an architectural question with signalR
Let's say I have a web app (pure front JS) that use a web api and the web app query an API that do a long task and want to be notified when the task is finished.
So the web api create a fire and forget task, and we use SSE with signalR to notify the web app. It's working. Great, thanks to signalR.
But now, I want the long task to be run in another process, let's say with a msmq based system.
So, the web app query the API, the web api create a message, and the msmq service process the message asynchronously.
Can the msmq service hosted in another process (maybe another machine !) notify the web app that the task is finished ? It can be possible to put the connection id in the message, but the service can be able to send the notification ?
I would use a servicebus, you can then use this library to forward the message directly to the clients.
https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy
What is the difference between the newly release ASP.NET WebHooks and Signal-R? What are the advantages or disadvantages? What are the use cases for each technology?
SignalR is for notification within an ASP.NET app using WebSockets. You can exchange event notifications through WebSockets, however it requires a constant network connection.
WebHooks are for event notification across other web applications and other external services. (Think B2B communication). For instance, you can receive a WebHook when someone sends you money to your PayPal account. PayPal fires off a POST request to your predefined URL handler and then your app does something with that notification. You pre-configure everything on the PayPal side first. You also set up an application to handle the incoming POST request. The event notification is "pushed" to you in (near) real-time. No need to hold open a network connection while waiting for events.
The two can be complementary. For example, when you receive the WebHook from PayPal, you can notify a logged in user on your webapp (using SignalR/WebSockets) that money has been received successfully.
TLDR: Event notification across different web applications
It really depends on service you want to integrate with and how. WebHooks is a simple pattern for integrating event notifications across different SaaS services. If the service you want to integrate with supports WebHooks then you can use that. If it supports SignalR then you can use that. In that sense the two are quite complementary.
Check Henrik F Nielsen post at
http://blogs.msdn.com/b/webdev/archive/2015/09/04/introducing-microsoft-asp-net-webhooks-preview.aspx