How to receive server side events similar to Facebook notifications - javascript

I am wondering on how to implement user notifications just like facebook does on its site. At the moment I am calling a php script using angular timer which tells me if any notification is available in the database. Is there any technique that I can use to push notifications to angular code?

Related

Laravel and Flutter Notifications System

I Want to Build a Web App with Mobile App in one platform. So, Both of Them will use the Same Database which is MySQL.
I want to use Laravel as backend and flutter for mobile app
Also, I want to build notifications system "when the user does something he will get pop up notification"
and that is the problem.
I searched a lot about this but I found nothing.
for Laravel, I can use Pusher and it's pretty easy.
but I didn't found anything to integrate it to flutter.
NOTE:
I'm beginner at flutter. But i'm good at laravel.
UPDATE
it's okey if there is any other method to do this
For flutter there is package called flutter_local_notifications,
link: https://pub.dev/packages/flutter_local_notifications
also there is pusher package
https://pub.dev/packages/pusher
so you can use these 2 together, so when a user trigger an event with API, a listener will send notification to pusher, so the other user would listen to it using pusher package.
At this moment you got the notification on your mobile using pusher package, only then you can trigger local notification using the other package instantly.

How to handle offline messages in React-Native using NodeJS and SocketIO

I am currently using SocketIO and NodeJS to handle messages. However the problem is that when the user becomes offline there's no way that the other user will receive the message.
The solution I came up with was to store the message in the database.
But a new problem arise, when fetching the message and push notification.
If I do fetch for "n" minutes in the server when the app is in background/inactive. There will be a lot of request in the server, and I personally think that it is inefficient. and also it drains the battery.
What is the proper way how to handle fetching the messages from database or pushing notification in app without making too much request in "n" minutes and draining too much power?
You need to save the last sync time in the App. And whenever app comes from background/Inactive state. You need to call an API with this time. This API will give you all the messages and the Push notification which has comes after the last sync time. In this way, With one API call, you will be able to get all the messages and push notifications. I had used this approach to syncing my data in one of my app.
My suggestion is to implement a system of background jobs in the API, checking when there is a new notification to be launched, or with the notification already ready waiting to be launched in the queue. You can search for queue manager like Bull, Bee-Queue.
To launch push notification in the closed/inactive app, you can use a service like OneSignal or Firebase.
I implemented this a few weeks ago and did it this way.
API = Node.js, Bull Queue
App = React Native, OneSignal
Going back to this question if somebody stumbled upon this question.
The best way to handle offline messages regardless if you are using NodeJS/MongoDB, etc. is to store it on server's database. Then call an API that fetches the the messages which is equal to user's ID whenever the mobile app comes to foreground.
If your problem is that you needed notification and you are using
react-native-push-notifications / react-native-push-notification-ios
Then you should use the data notification to include the message on notification parameter on the server's side(Assuming that you are using Firebase Cloud Messaging). With this way you can directly save the message on the mobile's database.

Server Sent Events with Hybrid Application

I'm working on a hybrid app that is based on Angular 1.5. In part of the app now, the client wants a messaging system for the admin of a group to be able to message the normal worker/user. I want to check and see if this is done, would server sent events be the solution? If so, do I continue to let it run as the user has the app open? How does this affect performance?
I am presuming authentication would need to be performed against users in order to differentiate between admin and worker accounts.
Have Angular send AJAX calls to your server, which will check the users' authentication status before the client-side view is rendered.
You should research the resolve property in Angular in order to implement this type of solution.

How can I send notifications to Chrome when the website tab is closed?

I'm trying to understand how to send notifications using the browser when my website is closed.
I see that Facebook does it but I can't get how.
Any help is welcome.
You are looking for the Push API:
The Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the foreground, or even currently loaded, on a user agent. This lets developers deliver asynchronous notifications and updates to users that opt in, resulting in better engagement with timely new content.
And the Notifications API:
The Notification interface of the Notifications API is used to configure and display desktop notifications to the user.
You must use these in combination with a Service Worker. From the Push API documentation:
For an app to receive push messages, it has to have an active service worker. When the service worker is active, it can subscribe to push notifications using PushManager.subscribe().
You can use Roost. Roost is a push notification platform for websites. You can see its documentation to perform both client-side and server-side integrations, so that you can customize your Roost notifications as needed.

How application that use twitter API is communicating with twitter

I want to implement similar API as twitter and what to know how it's implemented. I didn't read much about oAuth and didn't develop twitter app.
When user click on button it execute javascript that popup new window with twitter page and user click connect or authenticate an app. How processing is passed back to application and how application know that on twitter side execution is finished and user authorize the app?
You need to provide callback function/url of your application where twitter returns with access token after the twitter side execution is finished.

Categories

Resources