Hiyve Components - v1.0.0
    Preparing search index...
    • Hook for poll synchronization via the semantic relay.

      Parameters

      Returns UsePollSyncResult

      Sync functions and connection state

      This hook handles real-time synchronization of poll state across all participants in a room.

      Message Flow:

      • When owner creates a poll, it's broadcast to all
      • When owner starts a poll, the start is broadcast to all
      • When a user votes, the vote is broadcast to all
      • When owner ends a poll, the end is broadcast to all
      • Late joiners request state from any participant who has it

      Owner Responsibilities:

      • Creating polls
      • Starting polls (making them active)
      • Ending polls
      • Deleting polls
      • Sharing results
      function PollsWithSync() {
      const pollsRef = useRef(new Map());
      const userVotesRef = useRef(new Map());

      const {
      createPoll,
      startPoll,
      endPoll,
      castVote,
      connected,
      } = usePollSync({
      isOwner,
      localUserId: userId,
      localUserName: userName,
      pollsRef,
      userVotesRef,
      onStateUpdate: setPolls,
      });
      }