How to detect the offline Meteor Cordova application, and then use GroundDB to temporarily store data until it appears on the Internet?

Here is the goal:

The farmer has a smartphone and enters his barn to take an inventory using the app. Sometimes his phone does not receive an Internet connection in the barn, so the application must work offline, store data offline and then synchronize it with the cloud after reconnecting it.

The farmer will also only need to register and register the application once, and then every time they open the application, it should simply open on the main screen and no longer ask for account information. How exactly can this be done?

I use Meteor to build the app, and Meteor in Cordoba to pack the app. I saw GroundDB: https://github.com/GroundMeteor/db

As far as I can tell from the docs, I know how to create a local collection and use collection.insert to add data to this collection.

But I'm lost on how to encode the application to open on the phone without the need for the Internet and discover if the Internet is present or not?

Then, how to determine if the Internet has returned, and then synchronize all the data stored offline?

If someone can help lay out how this will work, it will be very useful!

+6
source share
2 answers

Use this code to find offline / online

jQuery(window).on('offline', function (e) { console.log('offline'); }).on('online', function (e) { console.log('online'); }); 

You can also combine it with this plugin https://github.com/apache/cordova-plugin-network-information/blob/master/doc/index.md to determine additional information about the status of networks, if necessary.

+3
source

With Meteor, you should use Meteor.status (), which return an object of this form:

Object {status: "connected", connected: true, retryCount: 0}

will obviously be erroneous if you lose the connection.

This is better than a jQuery or cordova approach, because it will handle a lost connection to a meteorite server, which will also lead to a server or network failure not only in Internet status.

+9
source

Source: https://habr.com/ru/post/981246/


All Articles