Save Application State

This example uses Orbiter, JavaScript, and HTML to save a shared application state to a server-side data source. The data source, in this case, is Union Server's built-in database, Apache Derby. However, in a production environment, the data source could be customized to use any backend system, such as MySQL or a web service.

In Union applications, application state is shared among connected users via room attributes. This example demonstrates how a collaborative presentation-application could use a room attribute, currentSlide, to synchronize and save the current slide in a presentation. When the currentSlide attribute is set, as shown in the following code, it is automatically shared with other occupants in the presentation room and also saved to the server, as follows:

appRoom.setAttribute("currentSlide", newCurrentSlide, true, true);

If the presentation room shuts down because, for example, the meeting is adjourned for the day, the currentSlide is retained in Union Server's data source. The next time the presentation room starts, currentSlide is automatically loaded, and immediately available for use by any client that joins the room.

The example presentation application is shown below. Try opening it in two browser windows to see the shared current slide change in both windows. Then refresh the page to see the saved current slide automatically load.

[Edit Live on JSFiddle] [Download]

This application demonstrates the following Orbiter features:

  • Creating a room that shuts down when the last occupant leaves
  • Joining a room
  • Sharing a room attribute
  • Saving a room attribute
  • Responding to room-attribute updates

The Code

Here is the code for the preceding example. Click the "+" button to edit it live on JSFiddle.