Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do live updating similar to Google Docs?

I want to do something very similar to Google Doc's live updating - where all users can "immediately" see the actions of the other users in the doc.

To achieve this, my ideas so far:

  • Continuous AJAX requests being done in the background (this would seem performance-intensive)?
  • Surely there's not a way for the server to push notifications to all its clients and update them accordingly?
  • AJAX requests every X seconds with a buffer/time-lapse of actions to be accomplished in those X seconds (simulating a real-time effect)?

I would like to know others experience in trying to achieve this effect. What is the best way to do this?

All help is appreciated.

NOTE: I'm not specifically looking for a real-time document editing solution. I'm looking for a solution to the same concept of what Google does with their Docs. I will actually be using that solution in a slightly different manner.

like image 892
Stephen Watkins Avatar asked Sep 10 '10 17:09

Stephen Watkins


People also ask

How do you do live edit on Google Docs?

In Google Docs we believe that collaboration works best when it works for everyone. To see live edits, open the Accessibility settings by going to Tools > Accessibility settings and check “Turn on screen reader support.” Then, select “Show live edits” from the Accessibility menu.

Does Google Doc update in real time?

The latest is for Google Docs and helps keep track of real-time updates made by document collaborators. “Live edits” in Google Docs is designed to be used alongside screen readers (ChromeVox, NVDA, JAWS, or VoiceOver) or Braille displays.

Can multiple people update a Google Doc at the same time?

How many people can edit a Google Docs file simultaneously? Well, with documents and presentations, up to 10 people can work on the file at the same time. Up to 50 people can edit a Google Docs spreadsheet together. And Google Docs allows up to 200 simultaneous viewers of any type of Google Docs file.


4 Answers

I vote for Long-poll strategy : each client opens a request to the server, but the server never breaks up connections, and just send pieces of java-script from time to time.

Constant AJAX requests would kill your server.

like image 121
BarsMonster Avatar answered Oct 11 '22 15:10

BarsMonster


Check out google mobwrite. It's a drop-in library that enables collaborative editing of html forms via operational transformation.

Getting events pushed back from the server is the easy part, there are many ways to do it. Ensuring that the state is consistent across all clients, that's the hard part. That's where the operational transformation algorithm comes in.

like image 24
Joeri Sebrechts Avatar answered Oct 11 '22 15:10

Joeri Sebrechts


A Ajax approach is one way to go. You could implement it like the chat applications. The actual way will depend on the data being view. In short

  1. Create a session. It could house the users sharing the doc (eg excel file)
  2. When user A make a change (eg. update cell A5), use Ajax to send the changes to the server. The change can be stored with the date of arrival or some index value.
  3. A background Ajax call is fired by the page from time to time. As part of the request, the last date of access is passed as well.
  4. Upon receiving the request, you simply serve all the changes made from the last time or index. You could include the new date or index value as part of the response so that it can be use for the next request.
  5. When you are sure that the top X elements will not be access, you could remove them

Whether it will be performance intensive or not will depend largely on how to structure everything.

Your other option is web sockets. Haven't used it personally but if you have control over what browser your users will use, you could give it a shot. It allows the server to push data to the browser. Some Links: Web Sockets JS and Web Sockets in Firefox

like image 40
ritcoder Avatar answered Oct 11 '22 16:10

ritcoder


Another alternative is Orbited:

Orbited provides a pure JavaScript/HTML socket in the browser. It is a web router and firewall that allows you to integrate web applications with arbitrary back-end systems. You can implement any network protocol in the browser—without resorting to plugins.

Orbited is an HTTP daemon that is optimized for long-lasting comet connections. It is designed to be easily integrated with new and existing applications. Orbited allows you to write real-time web applications, such as a chat room or instant messaging client, without using any external plugins like Flash or Java.

like image 38
LarsH Avatar answered Oct 11 '22 16:10

LarsH