Polls
This guide explains how to create, vote on, and interact with polls in a meeting using Cloudflare RealtimeKit.
The meetings polls object can be accessed using meeting.polls. It provides methods to create polls, vote, and more.
console.log("Polls object:", meeting.polls);The meeting.polls.items property returns an array of all polls created in a meeting, where each element is an object of type Poll.
console.log("All polls:", meeting.polls.items);The Poll type is defined as follows:
interface Poll { id: string; question: string; options: PollOption[]; anonymous: boolean; hideVotes: boolean; createdBy: string; createdByUserId: string; voted: string[]; // stores participant ID}
interface PollOption { text: string; votes: { id: string; // stores participant ID name: string; }[]; count: number;}The meetings polls object can be accessed using meeting.polls. It provides methods to create polls, vote, and more.
console.log("Polls object:", meeting.polls);The meeting.polls.items property returns an array of all polls created in a meeting, where each element is an object of type Poll.
console.log("All polls:", meeting.polls.items);The Poll type is defined as follows:
interface Poll { id: string; question: string; options: PollOption[]; anonymous: boolean; hideVotes: boolean; createdBy: string; createdByUserId: string; voted: string[]; // stores participant ID}
interface PollOption { text: string; votes: { id: string; // stores participant ID name: string; }[]; count: number;}A new poll can be created using the create method from the meeting.polls object. The meeting.polls.create() method accepts the following parameters:
question(string) - The poll questionoptions(string[]) - Array of poll optionsanonymous(boolean) - Whether votes are anonymoushideVotes(boolean, optional) - Whether to hide vote counts
The following snippet creates a poll where votes are anonymous:
await meeting.polls.create( "Are you an early bird or a night owl?", ["Early bird", "Night owl"], true,);A new poll can be created using the create method from the meeting.polls object. The meeting.polls.create() method accepts the following parameters:
question(string) - The poll questionoptions(string[]) - Array of poll optionsanonymous(boolean) - Whether votes are anonymoushideVotes(boolean, optional) - Whether to hide vote counts
The following snippet creates a poll where votes are anonymous:
await meeting.polls.create( "Are you an early bird or a night owl?", ["Early bird", "Night owl"], true,);The meeting.polls.vote() method can be used to register a vote on a poll. It accepts the following parameters:
pollId(string) - The ID of the polloptionIndex(number) - The index of the selected option
The following snippet votes for the first option on the first poll created in the meeting:
const poll = meeting.polls.items[0];await meeting.polls.vote(poll.id, 0);The meeting.polls.vote() method can be used to register a vote on a poll. It accepts the following parameters:
pollId(string) - The ID of the polloptionIndex(number) - The index of the selected option
The following snippet votes for the first option on the first poll created in the meeting:
const poll = meeting.polls.items[0];await meeting.polls.vote(poll.id, 0);The total votes on a poll can be accessed in the following manner:
const poll = meeting.polls.items[0];const votes = poll.voted;votes is an array of participant IDs (meeting.participant.id).
The total votes on a poll option can be accessed in the following manner:
const poll = meeting.polls.items[0];const options = poll.options;options returns an array of objects, where each object is of type PollOption.
An event is fired each time meeting.polls.items is updated or created. You can listen for this to get the updated list of polls. The response object contains the following properties:
polls- List of all pollsnewPoll- A boolean variable which istruewhen a new poll has been created
meeting.polls.on("pollsUpdate", ({ polls, newPoll }) => { console.log("Polls updated:", polls); console.log("Is new poll:", newPoll);});The total votes on a poll can be accessed in the following manner:
const poll = meeting.polls.items[0];const votes = poll.voted;votes is an array of participant IDs (meeting.participant.id).
The total votes on a poll option can be accessed in the following manner:
const poll = meeting.polls.items[0];const options = poll.options;options returns an array of objects, where each object is of type PollOption.
An event is fired each time meeting.polls.items is updated or created. You can listen for this to get the updated list of polls. The response object contains the following properties:
polls- List of all pollsnewPoll- A boolean variable which istruewhen a new poll has been created
meeting.polls.on("pollsUpdate", ({ polls, newPoll }) => { console.log("Polls updated:", polls); console.log("Is new poll:", newPoll);});Alternatively, you can use React hooks to listen for poll updates:
import { useRealtimeKitSelector } from "@cloudflare/realtimekit-react";
// useRealtimeKitSelector hook only works when `RealtimeKitProvider` is used.const polls = useRealtimeKitSelector((m) => m.polls.items);Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-