简体   繁体   中英

Running javascript function on background while receiving push notification?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM