DEMOS / Synchronized Elements

Nitrogen provides an easy mechanism to synchronize page elements across multiple clients by registering elements directly to a comet pool.

Calling element_sync_panel:refresh(Trigger) will trigger all the elements on all connected clients to refresh their contents by calling their assigned render function (which might typically read contents from a database or other data source).

In this demo, we will simulate users clicking one of the 'Msg' buttons, changing the status in the database and triggering a redraw on all connected clients, with the 'database' here being a simple text file on the hard drive.

To fully appreciate this demo, you'll want more than one browser window opened on this page to see the contents change in the other window.

To help you understand why this is useful, there is a blog post describing a specific use case (after all, Nitrogen provides a number of comet/asynchronous tools and it might not be obvious why this rather simple tool is useful). The key is that it provides a simple mechanism for all connected clients page contents to be synchronized with only a few simple lines.

View Module Source
Open this page in a couple browser windows then click some of the buttons below
Boromir Says: One does not simply walk into Mordor.
Copyright © 2008-2024 Nitrogen Web Framework. Released under the MIT License.