简体   繁体   中英

Sync solutions for IndexedDB in chrome extension

I have developed a chrome extension which saves data locally using IndexedDB. I want to add a feature to sync data between multiple computers. Can you suggest me a solution. Thanks

Edit : I don't maintain any server and do not collect any users private information. The extension is basically a mashup of data from free third parties. So if my user makes any changes to data in computer A, it should also reflect in computer B or device C (for future todo support :)

Here is a good answer which explains how to make a browser to browser (peer to peer) connection.

Other solution would be making some kind of server side application which would allow users to store data on your server or some third party storage and later retrieve the data to other computers.

Update: Based on your edit, I believe Mr. Deni Mf's link is a nice pointer to getting peer to peer working. But I believe that technology isn't available yet for general usage, and that you will probably be better off syncing against a server, possibly even a third party allowing you to do this (Amazon S3 and/or similar services). Chrome has some sync service built in already - How to synchronize Chrome extension data on different computers? - but you can only use that for small amounts of data, so realistically those can only be pointers to real data hosted elsewhere.

Original answer below:

There are a few aspects you need to figure out. Firstly, when you say "multiple computers", does that mean multiple computers talking to the same set of server(s), or do you actually mean multiple computers in a peer to peer sense (each computer is both a client and a server).

Secondly, you need a synchronization mechanism and protocol. If everything is nice and everybody is trusted with no real secrets and running You've got at least a couple of challenges; on a private network of some kind, you may very well use something like CouchDB or similar which works great out of the box (but becomes challenging as soon as you try to add authentication and authorization to data). If not, you need to roll your own.

Assuming you have clients talking to a specific set of servers (using HTTP or similar), and assuming you can not use CouchDB or similar (for the reasons stated in the previous paragraph), rolling your own isn't too hard. Since database rows (or similar) may be created on any client or server, using a traditional serial integer primary key will most likely not be worth it, and you need to use UUID or similar for unique keys (so each machine can create it's own - assumed unique - key for any object). Add at least one column for each row which contains it "updated" timestamp (when the object was created or updated) and add another database containing the last synchronization timestamp. Whenever the client connects, ask the server for any updates since you last connected, and send the server any updates you created locally since you last connected. Things like deleting rows is a bit trickier since a deleted row has no "updated" timestamp, so consider just adding a simple "deleted" flag to each row to make things simpler.

This should at least be enough to get you going.

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