Listen to update
Guide: Listening to Poll Updates with pollz-js SDK
Prerequisites
Before you proceed with listening to poll updates using the pollz-js SDK, ensure that you have already initialized the SDK and created a poll by following the relevant guides in the "Guides" section.
Listen to Poll Updates
Stay informed about real-time changes in a specific poll by setting up a listener using the pollz-js SDK.
Step 1: Import the SDK
In your Node.js application, ensure you have already imported the pollz-js SDK:
const { PollzSDK } = require('pollz-js');
Step 2: Listen to Updates
Use the listen
method provided by the polls
module of the SDK to set up a listener for a specific poll. Provide the poll ID and a callback function to handle the updates.
const pollz = new PollzSDK();
// Replace 'your-app-id' and 'your-app-secret' with actual credentials
const initInput = {
appId: 'your-app-id',
appSecret: 'your-app-secret',
};
// Initialize the SDK
await pollz.init(initInput);
// Replace with the actual poll ID
const pollIdToListen = 1;
// Define a callback function to handle updates
const handlePollUpdate = (updatedPoll) => {
console.log('Poll Updated:', updatedPoll);
};
// Set up the listener
const unsubscribe = pollz.polls.listen(pollIdToListen, handlePollUpdate);
// To stop listening, call the unsubscribe function
// unsubscribe();
Replace 'your-app-id' and 'your-app-secret' with the actual credentials obtained from the Pollz platform. Adjust the pollIdToListen
according to the poll you want to receive updates for.
Congratulations! You have successfully set up a listener to receive real-time updates for a specific poll using the pollz-js SDK. Explore more SDK features and functionalities to enhance your application's polling experience. Refer to the relevant guides for detailed instructions on other SDK capabilities.
Last updated