Running javascript function on background while receiving push notification? - javascript

I know this one has probably been asked before, but not with the context of push notifications.
I'm developing an app using Ionic/Cordova that sends push notifications to clients, usually about new video messages for them to watch. The videos are not going to be streamed but transferred to the client-side (not my call), so I thought of implementing some background javascript function to store the video on the client-side when and while the push has been received.
I have looked on web-workers and multithreading but it needs the client-side running. The javascript code has an event listener for when pushes are being received, but of course it does not get executed until the app is being opened.
So my question is, is it even possible? I'll appreciate any words of advice on this matter, thanks!

I already did this in my app using signalr together with push notification. My app. is a chat app. that client X can send a rich text message with pictures or video to client Y.
when client X send message, it calls the signalr Server and the Server save the message in Server sql and save the picture or video in Web server.
if client Y is offline, it will get the message during next online. If client Y is already on-line:
case 1: online but in foreground: signalr Server call client Y JavaScript function to update the screen and local storage, client Y see the message and picture immediately. (and I also play a sound)
case 2: online but in background or the mobile phone in screen safe mode: signalr Server call client Y JavaScript function to update the screen and local storage, play another sound. then send a push notification to client Y too! So that when client Y see this notification, it open the app. and see the message in local storage. (just like Whatsapp)

Related

Real-time sockets between Android and server

For learning purposes I’m creating an Android app that does the following:
When a person arrives at school, he/she can check a button in the app and he/she is added in real-time to a list (in the server database) of everyone that also checked “at school” button within the app. He/she can also add a message before clicking the button.
The rest of the students then receive a toast in real-time with the person’s name that arrived and it’s message.
I know how to do the Android part, but what is the best way to do the real-time event queries and requests in communication with the server? For example, I send a socket with the persons confirmation, location and message to the server. From the server-side, I supose there’s a nodejs controller that receives the socket and updates the database in sql. Then it sends a socket to every client online and a confirmation to the checked client.
Is this the “professional” way to handle data like this? What is the best (fastest, more secure, standard) way? When I Google how to make this communication I can only find web server client-server communication with Apache, but I’m really looking for a real-time event with an Android app.
I’m not really looking for code but to know and understand technologies and design patterns on how this can be done. And what to search for in order to learn how to do this.

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.

Listening on a network for data - React Native App and Server

I'm wanting to create a react-native app that pulls data from a database on the same local network but only when there is a change.
The only way I know how to do this currently is have a loop that pulls the same data down from the database every X seconds but surely this is taxing on the database system?
Is there a way of having the database system (server) send a tiny bit of data out across the network telling any of the listening devices that they should update.
Question 1
Any information on the Broadcasting side? (the part that sends the information out that the database has changed)
Question 2
Any information on the Listener side? (that looks for incoming data from the broadcaster saying that the database has changed and they should update)
End Goal
I'm creating a system where If a button is clicked it updates a database and a react native app then displays where the button is clicked for this I need a server that runs a database that is updated when the buttons are pressed and a app that only calls to the server for the information when there's new information on it.

how to record video on server instead of browser using record rtc

Im building an application in which i have successfully implemented video chat functionality using easyrtc. Now what i want to do is record that video. I have done that as well by reading tutorials over the internet.
But I'm able to record the video at client side(on browser). while i want to record it on server directly. because in this way, my browser get hang and stops responding due to the size of video.
Is there any possible way to save it directly on server or it can be sent to server simultaneously when it recorded.
any help would be appreciated.
thanks
Neeraj

Auto updating text clipboard on two different machines connected to the same network?

I want to make a simple webapp on my macbook where I launch a page, and basically its just a massive full page clipboard. I paste my code in, and if I have that same page open on another machine (my windows XP machine), I want that code to auto update in that window.
This is so I can transfer code to and from my machine without having to use my USB key.
Where should I get started with this? I'm not asking for any code, just a push in the right direction, not entirely sure what I should be googling. If this is in the wrong site please move it.
Thanks.
essentially, what you want is like a chat program.
oldschool solution is that wep page polls server at regular intervals. Server needs to persist the data somehow, in order to provide it to the client during the next http request.
A new approach is to use html5 web sockets. Since this allows server to 'push' data to client as soon as its received, nothing needs to be persisted.
http://www.html5rocks.com/en/tutorials/websockets/basics/

Categories

Resources