Introduction
You can access the polls functionality in a meeting using the meeting.polls
object. This object provides methods to create polls, vote, and perform other poll-related actions.
To retrieve all polls created during a meeting, use meeting.polls.items
. This returns an array where each element is an object of type com.cloudflare.realtimekit.polls.Poll
.
class Poll(
val id: String,
val question: String,
val anonymous: Boolean,
val hideVotes: Boolean,
val createdBy: String,
val options: List<PollOption>,
val voted: List<String>,
)
The Poll
type represents a poll within a meeting. Each poll contains a list of PollOption
objects, representing the available options for that poll.
Every PollOption
includes a list of PollVote
objects, where each vote contains the voter's id
and name
.
class PollOption(
val text: String,
val votes: List<PollVote>,
val count: Int
)
class PollVote(
val id: String,
val name: String
)
One can easily create, vote and view polls by listening to callbacks on
meeting
object.
Listening to new polls in a meeting
To receive updates about new polls or poll changes during a meeting, implement the RtkPollsEventListener
interface. Register your listener using meeting.addPollsEventListener(rtkPollsEventListener)
.
The onNewPoll()
method is called whenever a new poll is created in the meeting.
The onPollUpdate()
method is invoked when a specific poll is updated, such as when participants vote or poll details change. The onPollUpdates()
method is called when there are updates to the list of polls, including new polls being created or multiple polls being updated at once. Use these callbacks to keep your poll UI in sync with the latest poll data.
meeting.addPollsEventListener(object : RtkPollsEventListener {
override fun onNewPoll(poll: Poll) {
}
override fun onPollUpdate(poll: Poll) {
}
override fun onPollUpdates(pollItems: List<Poll>) {
}
}
)