FormidableLabs/spectacle

Question: Accessing skipTo method

drewpotter opened this issue · 1 comments

Question

I would like to ask about accessing this skipTo method:

skipTo(options: { slideIndex: number; stepIndex: number }): void;

I am hoping to programmatically skipTo slides and also steps within a slide if possible, within a functional React JavaScript component I am using which contains spectacle as a sub-component.

Background Info/Attempts

I have tried modifying the spectacle code to allow me to do this, but I wanted to find the most elegant way of achieving this.

I have solved my issue simply by using the BroadcastChannel mechanism. For example, to jump to particular slide fragments at random every 2.5 seconds, I have done this:

  const channel = new BroadcastChannel("spectacle_presenter_bus");

  useEffect(() => {
    const intervalId = setInterval(() => {

      var randomNumber = Math.floor(Math.random() * (4 - 0 + 1) + 1)
      console.log("random: " + randomNumber);

      channel.postMessage(JSON.stringify({
        type: "SYNC",
        payload: {
          slideIndex: 4,
          stepIndex: randomNumber
        }
      }));
    }, 2500);

    return () => clearInterval(intervalId); //This is important
  }), []