Skip to content

abnegate/android-realtime-shareboard

Repository files navigation

Appwrite Realtime Whiteboard 🖊️

A demo Realtime Whiteboard Android application using Appwrite's new realtime service.

Quick example

val client = Client(context)   
    .setEndpoint("https://[YOUR_HOSTNAME_OR_IP]/v1")
    .setProject("[YOUR_PROJECT_ID]")

val realtime = Realtime(client)

val subscription = realtime.subscribe("collections.6fabc4664gjb9.documents") {
    Log.d("Realtime", it.payload.toString())
}

Get Started

The MenuFragment.kt and MenuViewModel.kt contain the code to set up the private rooms. You choose a name and password and then share this information with others you want to join your board.

The RoomViewModel.kt initiates the realtime subscription, and contains a function to push new DrawPath objects to your Appwrite Database. Calling this function whenever you draw a new path is how everyone else in your room will receive your draw updates, as they're observing the same collection as you are pushing to.

This is the response model received for every real time update:

data class RealtimeResponseEvent<T>(
    val event: String,
    val channels: Collection<String>,
    val timestamp: Long,
    var payload: T
)

If subscribing to a single channel, you may provide a payloadType parameter to the subscribe function that allows you to set the type of every event's payload

When you leave the board, the ParticipantLeaveWatcherService.kt will ensure that the room's active participant count is decremented. This works in tandem with the room cleaner function to allow automatic cleanup of your database.

Learn more

You can use the following resources to learn more

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages