Player Services

PlayerServices can be used to call a function on player runtime

PlayerServices type

Function Description
getPresentation() Return object which represents a presentation. This object implements several functions related to accessing the presentation and its pages.
getCurrentPageIndex() Return index of a current page.
getCommands() Return object which implements different commands you can call from your addon.
getEventBus() Return object which implements event bus.
getScore() Return object which implements commands for accessing the player score.
getModule(moduleID) Return module presenter based on the given ID.
getTextParser() Return object which is a parser for text elements like definition links.
getStaticFilesPath() Returns path to static files included with the player.
isBook() Returns true is player is in book mode (shows 2 pages).
hasCover() Returns true if first page is shown always as single page.

Presentation type

Function Description
getPageCount() Return number of pages.
getPage(index) Return page at given index.
getTableOfContents() Return hierarchical table of contents which consists of Chapters and Pages. Chapter has the following methods:
  • type - "chapter"
  • getName() - Chapter name
  • size() - number of chapter nodes
  • get(index) - get node (Chapter or Page)
Page has the following methods:
  • type - "page"
  • getName() - Page name
  • getBaseURL() - URL base
  • isReportable() - Return true if page is reportable

Page type

Function Description
getId() Return page id.
getName() Return page name.
getBaseURL() Return page base URL with slash '/' at the end.
isReportable() Return true if page contains should be included in lesson report.
getModules() Returns list of ids of all modules on the page.

Commands type

Function Description
executeEventCode(code) Send the script code to be executed by player
gotoPage(name) Go to page with a given name.
gotoPageIndex(index) Go to page at given index.
getTimeElapsed() Returns time in seconds elapsed form the start of the lesson session.
checkAnswers() Sets the presentation to showErrorsMode.
uncheckAnswers() Restores the presentation to workMode.

EventBus

Function Description
addEventListener(event_name, listener) Register the listener for a specific event. Listener is the object which implements: onEventReceived(eventName, eventData) function.
  • eventName - event name
  • eventData - an array with event data
sendEvent('ItemSelected', data); Send event
  • eventName - event name
  • eventData - an array with event data

Score

Function Description
getMaxScore() Return max score for the whole presentation
getTotalScore() Return score calculated for all opened pages.
getPageScore(pageName) (depreciated) Return score for a given page. The score is hashmap with values:
  • score - actual score
  • maxScore - max page score
  • checkCount - how many times the check button was pressed on this page
  • mistakeCount - total number of shown errors
getPageScoreById(pageId) Return score for a given page. The score is hashmap with values:
  • score - actual score
  • maxScore - max page score
  • checkCount - how many times the check button was pressed on this page
  • mistakeCount - total number of shown errors

TextParser

Function Description
parse(text) Parse given text and replace definition \def{word} with links
connectLinks(element); Connect all definition links to event bus. Each link will send Definition event.