mediasfu-reactnative
Version:
MediaSFU Prebuilt React Native SDK
42 lines • 1.75 kB
JavaScript
/**
* Handles the end of a poll by emitting an "endPoll" event through the provided socket.
* Displays an alert based on the success or failure of the operation.
*
* @param {HandleEndPollOptions} options - The options for ending the poll.
* @param {string} options.pollId - The ID of the poll to end.
* @param {Socket} options.socket - The socket instance to emit the event.
* @param {Function} [options.showAlert] - Optional function to display alerts.
* @param {string} options.roomName - The name of the room where the poll is being conducted.
* @param {Function} options.updateIsPollModalVisible - Function to update the poll modal visibility.
*
* @example
* ```typescript
* handleEndPoll({
* pollId: "poll123",
* socket: socketInstance,
* showAlert: (message) => console.log(message),
* roomName: "roomA",
* updateIsPollModalVisible: (isVisible) => setIsPollModalVisible(isVisible),
* });
* ```
*/
export const handleEndPoll = async ({ pollId, socket, showAlert, roomName, updateIsPollModalVisible, }) => {
try {
socket.emit('endPoll', { roomName, poll_id: pollId }, (response) => {
if (response.success) {
showAlert === null || showAlert === void 0 ? void 0 : showAlert({
message: 'Poll ended successfully',
type: 'success',
});
updateIsPollModalVisible(false);
}
else {
showAlert === null || showAlert === void 0 ? void 0 : showAlert({ message: response.reason || 'Failed to end poll', type: 'danger' });
}
});
}
catch (error) {
console.error('Error ending poll:', error);
}
};
//# sourceMappingURL=handleEndPoll.js.map