1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    1
    Vote Rating
    0
    Sukima is on a distinguished road

      0  

    Default Bi-Directional Syncing for offline apps

    Bi-Directional Syncing for offline apps


    I'm at a loss which is why I'm reaching out to the community. I have been trying to find the best framework stack for a project of mine and have found no success at all. I find it even more frustrating that the web community at large has no libraries or example code on how to complete this obvious solution. Most forums just leave the answer as an exercise for the student.

    I have a Rails based REST application. It has it's HTML output and it's XML REST API and a budding community. However the Mobile version of it's HTML have one glaring problem. It requires online access since it is a web-page. The offline solutions that describe Sencha Touch are nothing but a way to cache the data from a web site for offline viewing and don't offer any solutions for offline data manipulation. The application I would build is a very client side dependent as the data being manipulated is rather complex hence the interest in a web application framework not at mobile version of a web site.

    I'm looking at a JavaScript HTML 5 solution for two reasons. Cross-platform (iPhone and Andriod) and the fact that this is a open source community project that does not fit well with the Apple SDK AppStore platform.

    Sencha.io seems to be a in-house solution to data synchronization between Sencha application (iPhone to iPad to Android) and is not a library to handle communications with an already established REST service running on your own web server.

    That being said I'd like to describe what I want to accomplish in hopes someone has done something like this before and be willing to offer help.
    • An HTML5/JavaScript based Web application that runs offline (as an app you can install using the "Add to home screen" button).
    • Have the ability to convert to a native app in the future is desired.
    • Designed for the iPhone and Android phone platform (iPad and tablet would be nice too)
    • Ability to download the data via a REST API (xml or json)
    • Manipulate that data offline
    • Once online sync that data back to the server and update from changes from that server.

    For further details this is a task management application that interfaces with a rails based application called Tracks which provides a REST API using standard CRUD operations (the usual). I want this JavaScript application to cache on the mobile device via the cache manifest and other offline tricks that WebKit and Apple iOS offers. I want the user to sync the data between the server and the mobile device so that the user can add new entires, organize models, and essentially manipulate the data on the mobile device while they are on an airplane with airplane mode then once network is back these changes can be sent to the server.

    There is not a multi user environment for the data as each record is only used by it's assign user (no sharing of data between users) so multiuser conflicts are not a problem. However it is very possible and likely that a user might make a change on the mobile device and forget to sync before using the web interface to make changes and this kind of conflict would need some resolution (Maybe latest transactions clobber older ones?)

    So for the only pre-build solutions I have found are on the backbone.js world called backbone.offline which has brought me to think doing this in backbone instead of Sencha Touch a viable option. I have also been very unsuccessful finding good algorithm documentation on how one could implement their own code to do this.

    My question is has anything like this been done using Sencha / ExtJS? If not is there any recommendations?

  2. #2
    Sencha Premium Member tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,695
    Vote Rating
    114
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    take a look at:
    http://docs.sencha.com/touch/2-0/#!/...y.LocalStorage

    you can dynamically exchange the proxy of a model / store.
    check if you are online, in cause you are not switch to localStorage, save changes there and push them to your backend when you get online again.
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  3. #3
    Ext JS Premium Member
    Join Date
    Aug 2007
    Location
    Antwerp, Belgium
    Posts
    561
    Vote Rating
    45
    joeri is a jewel in the rough joeri is a jewel in the rough joeri is a jewel in the rough

      0  

    Default


    Quote Originally Posted by tobiu View Post
    ... check if you are online ...
    Ha, if there was only a reliable way of doing that. navigator.onLine is a lie. There is no solution (native or web) that gives you a truthful answer whether you're online or not, aside from just trying to contact the server and seeing if you can reach it. And even that last one doesn't give the whole picture, because you don't know the bandwidth or latency of the connection (perhaps you're on GPRS at 4 KB / sec), and because in a moving vehicle connection quality changes every second.

    What I do to handle sync is robust handling of timeout errors combined with user-driven synchronization. I'm assuming that when the user presses "synchronize" they have a pretty good idea about their connectivity.

    As far as handling conflicts, you have these solutions:
    - Optimistic conflict handling: store a hash of the downloaded data. If at synchronization time the data on the server has changed, refuse to synchronize (first to commit wins). This solution is best suited when conflicts are rare. http://en.wikipedia.org/wiki/Optimis...rrency_control
    - Locking: when you take something offline, take a lock on it. You have to worry about users walking away halfway through (lock stealing needs to be possible). This is an extension of optimistic conflict handling that adds a roadblock to making a conflicting change. This solution is best when conflicts are operationally forbidden but technically possible.
    - Merging: merge the data of both commits in some way, e.g. last field written overwrites earlier fields. This solution is best if you have a clear way to merge without losing data (which is almost never the case).
    - Operational Transformation: extending the editing logic into the sync logic so that conflicts become impossible. Google docs does this, but the algorithm is not easy to understand. http://en.wikipedia.org/wiki/Operational_transformation

Thread Participants: 2

Tags for this Thread