Callbacks

There are a number of Javascript callbacks that you can access in order to respond to system events and react accordingly.

📘

Recommend Using in the Playlist HTML Overlay

These callbacks are usually more useful when implementing code within an HTML overlay vs a Webapp.

CallbackDescriptionReturns
onApiStatusChangeCalled when the API Status changes. You can use this to react to the device going online or offline.The current status string
onPageChangeCalled when the Playlist transitions to a new page. Useful for overrides and responding to different pages.The current page object
onPlaylistChangeCalled when the Playlist is updated, typically when playlist name or id is changed.The current playlist object
onGeoChangeCalled when the geographic coordinates of the device change. You'll need a device and a Player that supports forwarding geographic coordinates such as our Android Player running on an Android tablet.The current coordinates object
onOverrideStartCalled when an Override startsThe starting override object
onOverrideEndCalled when an Override endsThe ending override object
onSerialMessageCalled when a message is received (a string) from the configured serial port on the deviceThe message string
onPageDurationcalled when page start or page duration changes. Only works for:

page with a fixed "duration" set

page without a "duration" but there's a video (E.g. YouTube) that would cause the playlist to advance.
The number 'float'

Example of callbacks usage:

window.onloadTelemetryTV = function (ttv) {
  ttv.onApiStatusChange(function (status) {
    console.log(`API Status change to: ${status}`);
  });

  ttv.onPageChange(function (page) {
    console.log(`Current Page: ${page.name} (${page.id})`);
  });

  ttv.onPlaylistChange(function (playlist) {
    console.log(`Current Playlist: ${playlist.name} (${playlist.id})`);
  });

  ttv.onGeoChange(function (coordinates) {
    console.log('My oordinates are now:', coordinates);
  });

  ttv.onOverrideStart(function (override) {
    console.log(`Override started: ${override.name} (${override.id})`);
  });

  ttv.onOverrideEnd(function (override) {
    console.log(`Override ended: ${override.name} (${override.id})`);
  });

  ttv.onSerialMessage(function (message) {
    console.log('Serial Message received:', message);
  });
  
  ttv.onPageDuration((cb) => {
    window.console.log('Length of video', cb)
  })
};