Skip to content
Back

how to work with realtime?

  • 0
  • Android
  • Realtime
EmoKid
10 Mar, 2025, 16:23

hello everyone, I opened the realtime documentation, but I didn't understand how to work with it. It seems to show how to create an object, but how to use it and get, say, there is no value from the database

TL;DR
Learn to work with real-time updates by creating a document accessible to users. Set up a subscription that triggers an event when the document changes. Use Realtime's subscribe function in client code, like the Kotlin example provided, to listen for updates from the database and perform actions, such as logging the new data.
Steven
10 Mar, 2025, 16:24

It seems to show how to create an object

what do you mean?

EmoKid
10 Mar, 2025, 16:25
TypeScript
    suspend fun getRealtime(onUpdate: (Notification) -> Unit) {
        val realtime = Realtime(client)

        val subscription = realtime.subscribe("databases.$databaseId.collections.Notification.documents") { event ->
            val payload = event.payload
            Log.d("REALTIME_DATA", "new message: ${payload}")
        } 
    }
EmoKid
10 Mar, 2025, 16:25

this

Steven
10 Mar, 2025, 16:38

yes, so that subscribes and when an event comes in, it gets logged

Steven
10 Mar, 2025, 16:38

Docs say:

Instead of requesting new data via HTTP, the subscription will receive new data every time it changes

EmoKid
10 Mar, 2025, 16:39

how can this be used?

Steven
10 Mar, 2025, 16:39

create a document that the user has access to and the event will come through.

EmoKid
10 Mar, 2025, 16:44

and how do I output the document I need if there are no changes, but they will be?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more