Reacting to live updates
How to detect and react to real-time updates
The platform is real-time by nature with all client apps connected via a socket at all time. Data changes are broadcast to connected users as soon as you publish content, or as values change.
To ensure your app displays constantly relevant data, we offer the possibility to register listeners that are notified when those changes occur.
Responding to updates is commonly needed on several levels:
Project updates: for example Project Settings
Event updates: Elements being added, removed or other metadata changes
Element updates: for example content being changed
Reacting to Project updates
The following snippet demonstrates how you can react to changes in the Project. For example a change in its configuration fields or if a new Event is created.
class MyProjectUpdateDelegate: ProjectUpdateDelegate {
func didPublishEvent(project: Project, event: Event) {
// Code when an event is published
}
func didRemoveEvent(project: Project, event: Event) {
// Called when an event is removed
}
func didUpdateProjectFields(project: Project) {
// Called when the project fields change
}
}
let myDelegate = MyProjectUpdateDelegate()
project.add(listener: myDelegate)
// When we no longer need to be notified about project changes.
project.remove(listener: myDelegate)class MyProjectUpdateListener : ProjectUpdateListener {
override fun onEventPublished(project: Project, event: Event) {
// Code when an event is published
}
override fun onEventRemoved(project: Project, event: Event) {
// Called when an event is removed
}
override fun onProjectFieldsUpdated(project: Project) {
// Called when the project fields change
}
}
val myListener = MyProjectUpdateListener()
project.add(myListener)
// When we no longer need to be notified about project changes.
project.remove(myListener)Reacting to Event updates
The following snippet demonstrates how you can react to changes in the Event, be it a change in their fields, state, or Elements being added or removed. For example, a new Poll being published during a live Event.
React to Element updates
The following snippet demonstrates how you can be notified about changes in an Element. For example if the content creator changes a field after making a mistake.
Last updated

