@vestra-player/sdk - v1.11.3
    Preparing search index...

    Interface Trigger

    A trigger (plugin.trigger()): a place for one condition the player keeps and evaluates, also while the plugin is in standby, and the functions to call when it becomes true (enter) and false (leave).

    When it flips while the plugin has no process, the player starts the plugin; activate() declares the same triggers again and the waiting notification reaches the same trigger. Every method returns the trigger, so the calls chain.

    The window stays on top while a file plays in fullscreen and goes back when either ends. The player evaluates the condition itself, so the plugin may be in standby in between.

    const { when, window } = plugin;
    plugin
    .trigger()
    // The player keeps this condition and calls back when it flips.
    .firesOn(when.playing.and(when.fullscreen))
    .enter(() => window.setAlwaysOnTop(true))
    .leave(() => window.setAlwaysOnTop(false));

    1.10.0

    interface Trigger {
        firesOn(condition: Condition): Trigger;
        enter(fn: (event: TriggerEvent) => unknown): Trigger;
        leave(fn: (event: TriggerEvent) => unknown): Trigger;
        off(): Trigger;
    }
    Index
    • Hands the player this condition, replacing the one it has (without a leave for the old one). A condition already true is entered at once, except a range list given again for the same source while the position is still in the range it was entered with (the same start, end and lead; a list that grew as a scan went on): that range stays entered, with no second enter, and an enter of it still on its way (a plugin woken for it) reaches enter all the same. The same condition again changes nothing. A refusal (invalid, limit) reaches the plugin's error handlers.

      Parameters

      Returns Trigger

      TypeError (throws) Not a condition from plugin.when, or one with two position lists.

      A command arms the trigger for the file open now: its condition holds from ten seconds before the end, and enter pauses. Pressing it again replaces the condition, without a leave for the old one.

      const { when, player } = plugin;
      const nearEnd = plugin.trigger("near-end").enter(() => player.setPaused(true));
      plugin.commands.add({
      id: "pause-near-end",
      path: ["Tools", "Pause Near the End"],
      run: () => {
      const duration = player.state.duration;
      // Bound to the current file: another file never matches it.
      if (duration !== null)
      nearEnd.firesOn(when.position.in([{ start: Math.max(0, duration - 10) }]));
      },
      });

      1.10.0

    • fn runs each time the condition turns from false to true. One trigger's functions run one after another: the next waits for the promise of the one before. A second call replaces the function.

      Parameters

      Returns Trigger

      TypeError (throws) fn is not a function.

      The OSD names the part of the file as playback reaches it. range says which of the ranges was entered: index is its place in the list the condition was given.

      const { when, osd } = plugin;
      plugin
      .trigger()
      .firesOn(when.position.in(parts))
      // `range` is set because the condition has a position list.
      .enter(async ({ range }) => {
      if (range) await osd.show("Now: {}", [parts[range.index].name]);
      });

      1.10.0

    • Removes the condition, without a leave. The trigger stays declared and can be given a new condition.

      Returns Trigger

      A second command disarms the timer the first one set: the player forgets the condition, so the plugin is not started for it.

      const sleep = plugin.trigger("sleep").enter(() => plugin.player.setPaused(true));
      plugin.commands.add({
      id: "sleep-cancel",
      path: ["Tools", "Cancel Sleep Timer"],
      run: () => sleep.off(), // the trigger stays; only its condition goes
      });

      1.10.0