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

Callbacks have been refactored as events. You can bind handlers to the events using the bindEvent method. And unbindEvent when needed.

📘

Recommend Using in the Playlist HTML Overlay

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

CallbackDescriptionReturns
ApiStatusHandler(status)Called when the API Status changes. You can use this to react to the device going online or offline.The current status string
PageChangeHandler(page)Called when the Playlist transitions to a new page. Useful for overrides and responding to different pages.The current page object
PlaylistChangeHandler(playlist)Called when the Playlist is updated, typically when playlist name or id is changed.The current playlist object
GeoChangeHandler(coordinates)Called 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
OverrideStartHandler(override)Called when an Override startsThe starting override object
OverrideEndHandler(override)Called when an Override endsThe ending override object
SerialConnectHandler(message) SerialCommandsHandler(message)Called when a message is received (a string) from the configured serial port on the deviceThe message string
PageDurationHandler(seconds)called 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 as events:

import { bindEvent, unbindEvent } from '@telemetrytv/sdk'

function apiStatusHandler (status) {
  console.log(`API Status change to: ${status}`)
}

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

function pageDurationHandler (seconds) {
  window.console.log('Duration of page:', seconds)
}

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

function geoChangeHandler (coordinates) {
  console.log('My Geo cordinates are now:', coordinates)
}

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

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

function serialConnectionHandler (message) {
  console.log('Serial Connection received:', message)
}

function serialCommandsHandler (message) {
  console.log('Serial Commands received:', message)
}

// Bind / Unbind event handlers one-by-one
bindEvent('apiStatusChange', apiStatusHandler)
bindEvent('pageChange', pageChangeHandler)
bindEvent('pageDuration', pageDurationHandler)
bindEvent('playlistChange', playlistChangeHandler)
bindEvent('geoChange', geoChangeHandler)
bindEvent('overrideStart', overrideStartHandler)
bindEvent('overrideEnd', overrideEndHandler)
bindEvent('serialConnection', serialConnectionHandler)
bindEvent('serialCommands', serialCommandsHandler)
//... other codes
unbindEvent('apiStatusChange', apiStatusHandler)
unbindEvent('pageChange', pageChangeHandler)
unbindEvent('pageDuration', pageDurationHandler)
unbindEvent('playlistChange', playlistChangeHandler)
unbindEvent('geoChange', geoChangeHandler)
unbindEvent('overrideStart', overrideStartHandler)
unbindEvent('overrideEnd', overrideEndHandler)
unbindEvent('serialConnection', serialConnectionHandler)
unbindEvent('serialCommands', serialCommandsHandler)


// Or bind / unbind ALL event handlers at once
bindEvent({
  'apiStatusChange': apiStatusHandler,
  'pageChange': pageChangeHandler,
  'pageDuration': pageDurationHandler,
  'playlistChange': playlistChangeHandler,
  'geoChange': geoChangeHandler,
  'overrideStart': overrideStartHandler,
  'overrideEnd': overrideEndHandler,
  'serialConnection': serialConnectionHandler,
  'serialCommands': serialCommandsHandler,
})
// ... other codes
unbindEvent({
  'apiStatusChange': apiStatusHandler,
  'pageChange': pageChangeHandler,
  'pageDuration': pageDurationHandler,
  'playlistChange': playlistChangeHandler,
  'geoChange': geoChangeHandler,
  'overrideStart': overrideStartHandler,
  'overrideEnd': overrideEndHandler,
  'serialConnection': serialConnectionHandler,
  'serialCommands': serialCommandsHandler,
})

We have also added more events to help getting updates from the player. For more information check the Events section in the README.md.


What’s Next