Additional Methods with Scheduler

getTime method

Asynchronously get the current timestamp in seconds (floating point) since Captivate started.

ServiceHandler.scheduler?.getTime(callback);
  • callback: Function taking a single argument that will receive the time value once it is retrieved.

Example:

ServiceHandler.scheduler?.getTime((time) => {
  // do something with time
  console.log(`Captivate has been running for ${time} seconds`);
});

saveSettings method

Store an input-specific settings string with the project.

// callback method
ServiceHandler.scheduler?.saveSettings(inputName, settingsString, callback);

// promises method
await ServiceHandler.saveSettings(inputName, settingsString);
  • inputName: Name of the input that should hold the settings (can be anything for short-term settings, but must match the name of an attached input for it to be saved with the project).

  • settingsString: String value to store.

  • callback: This function will always be called with a single null argument

Example:

let settings = {
  version: 1,
  showColors: true,
  myLabel: 'Hello, World',
};

// note the use of JSON.stringify here
ServiceHandler.scheduler?.saveSettings('Simple HTML Input', JSON.stringify(settings));

loadSettings method

Asynchronously load an input-specific settings string that was saved with the project.

// callback method
ServiceHandler.scheduler?.loadSettings(inputName, callback);

// promises method
await ServiceHandler.loadSettings(inputName);
  • inputName: Input behavior name matching the defintion XML.

  • callback: Function with a single argument that will receive the settings string once it is retrieved.

Example:

ServiceHandler.scheduler?.loadSettings('Simple HTML Input', (settingsString) => {
  try {
    let settings = JSON.parse(settingsString);
    // process settings
  } catch (e) {
    // handle JSON parsing errors here.
  }
});

updateInputDefinition method

Updates the definition of the named Input with new variables and types. This overrides all variable definitions specified in the XML file and is necessary when a new variable name is added to the Input or when a Variable pattern needs to be changed. This function will also trigger a re-render on all Titles connected to this Input, so use it sparingly.

ServiceHandler.scheduler?.updateInputDefinition(inputName, definition);
  • inputName: Input name must match the name from the input definition XML file.

  • definition: JavaScript object containing the new variable definitions (see below). By default, this definition will completely replace the variables defined previously. That is, new variables will be created if they weren’t defined before, and variables omitted from this definition will be deleted from the Input for this project. However, you may send a method parameter set to one of the following values to change this behavior:

    • reset: All current variables will be deleted, and the supplied variables will constitute the new definition. (This is the default for backwards compatibility, but if there are a lot of variables, this might cause an expensive re-render. Use the merge option whenever you can.)

    • delete: Supplied variables will be deleted from the input definition.

    • merge: Supplied variables will be added to the input definition, possibly replacing previous variables.

For more information on the variable definition, see Creating Input Behaviors section of the XML Definition page for description of definition parameters. They are the same here as in the XML specification with the exception that both attributes and child nodes from the XML are represented in JavaScript by object fields. Specifically notice that <value> nodes are here represented by a values list.

Example:

const definition = {
  method: 'reset', // if omitted, `reset` is the default, may also be `delete` or `merge`
  variables: {
    'Home Score': {
      type: 'text',
    },
    'Visitor Score': {
      type: 'text',
    },
    'Shot Clock': {
      type: 'text',
      pattern: '[0-2][0-9].[0-9]',
    },
    'Period Number': {
      type: 'text',
      values: ['1', '2', '2.5', '3', '4', '5'], // 2.5 = halftime, 5 = OT
    },
  },
};

ServiceHandler.scheduler?.updateInputDefinition('Simple HTML Scoreboard', definition);

Last updated