Class: Device

.devices.Device

(abstract) new Device(config)

Abstract base class for Antie devices. Device classes contain an abstraction layer between the Application and the environment in which the application runs (usually a web-browser). Any of the methods below can be overriden by a device-specific subclass or implementation common to multiple devices can be loaded via requirejs modifiers for this module (referenced in the device config). Device-specific implementations take precendence over those in requirejs modifiers.
Parameters:
Name Type Description
config Object Device configuration document.
Source:
Requires:
  • module:antie.events.KeyEvent

Extends

  • antie.Class

Requires

  • module:antie.events.KeyEvent

Methods

(static) addLoggingMethod(moduleId, loggingMethods)

Adds a logging method at device init time
Parameters:
Name Type Description
moduleId String of require module that defined the logging methods - eg antie/devices/logging/default
loggingMethods Object object that contains implementations of each logging interface ( log,debug,info,warn,error )
Source:

(static) load(config, callbacks)

Loads a device configuration document, and its modifiers.
Parameters:
Name Type Description
config Object Device configuration document.
callbacks Object Object containing onSuccess and onError callback functions.
Source:

addClassToElement(el, className)

Adds a class name to an element
Parameters:
Name Type Description
el Element The element which will receive new class name.
className String The new class name to add.
Source:

addKeyEventListener()

Adds global key event listener(s) to the user-agent. This must be added in a way that all key events within the user-agent cause self._application.bubbleEvent(...) to be called with a KeyEvent object with the mapped keyCode.
Source:
Example
document.onkeydown = function(e) {
    self._application.bubbleEvent(new KeyEvent("keydown", keyMap[e.keyCode]));
};

appendChildElement(to, el)

Appends an element as a child of another.
Parameters:
Name Type Description
to Element Append as a child of this element.
el Element The new child element.
Source:

createBroadcastSource() → {Object}

Create a new widget giving control over broadcast television. Check whether the broadcast television API is available first with isBroadcastSourceSupported().
Source:
See:
  • antie.widgets.broadcastsource
Returns:
Device-specific implementation of antie.widgets.broadcastsource
Type
Object

(protected) createButton(idopt, classNamesopt)

-PROTECTED- Creates a button (an element that can be selected by the user to perform an action) in the device's user-agent. Do not use outside of antie. Create antie.widgets.Button objects if you need to use buttons within an application.
Parameters:
Name Type Attributes Description
id String <optional>
The id of the element to create.
classNames Array <optional>
An array of class names to apply to the element.
Source:
Returns:
A button within the device's user-agent.

(protected) createContainer(idopt, classNamesopt)

-PROTECTED- Creates a generic container element in the device's user-agent. Do not use outside of antie. Create antie.widgets.Container objects to use containers within applications.
Parameters:
Name Type Attributes Description
id String <optional>
The id of the element to create.
classNames Array <optional>
An array of class names to apply to the element.
Source:
Returns:
A container element within the device's user-agent.

(protected) createImage(idopt, classNamesopt, src)

-PROTECTED- Creates an image in the device's user-agent. Do not use outside of antie. Create antie.widgets.Image objects if you want to use images within an application
Parameters:
Name Type Attributes Description
id String <optional>
The id of the element to create.
classNames Array <optional>
An array of class names to apply to the element.
src String The source URL of the image.
Source:
Returns:
An image within the device's user-agent.

(protected) createLabel(idopt, classNamesopt, textopt)

-PROTECTED- Creates a label (an element that only contains text) in the device's user-agent. Do not use outside of antie. Create antie.widgets.Label objects if you need to use labels within an application.
Parameters:
Name Type Attributes Description
id String <optional>
The id of the element to create.
classNames Array <optional>
An array of class names to apply to the element.
text String <optional>
The text within the label.
Source:
Returns:
A label within the device's user-agent.

(protected) createList(idopt, classNamesopt)

-PROTECTED- Creates a list in the device's user-agent. Do not use outside of antie. Create antie.widgets.List objects if you need to use lists within an application.
Parameters:
Name Type Attributes Description
id String <optional>
The id of the element to create.
classNames Array <optional>
An array of class names to apply to the element.
Source:
Returns:
A list within the device's user-agent.

(protected) createListItem(idopt, classNamesopt)

-PROTECTED- Creates a list item in the device's user-agent. Do not use outside of antie. Create antie.widgets.ListItem objects or add widgets to a List if you want use list items within an application
Parameters:
Name Type Attributes Description
id String <optional>
The id of the element to create.
classNames Array <optional>
An array of class names to apply to the element.
Source:
Returns:
A list item within the device's user-agent.

createMediaInterface(id, mediaType, eventCallback)

Creates the interface that Media widgets use to communicate with the device.
Parameters:
Name Type Description
id ID to be used when creating DOM elements.
mediaType Type of media. "audio" or "video"
eventCallback Function that is called to processes media events.
Source:

crossDomainPost(url, data, opts)

Performs a POST HTTP request to a URL on a different host/domain.
Parameters:
Name Type Description
url String The URL to post to.
data Object Associative array of fields/values to post.
opts Object Object containing onLoad and onError callback functions.
Source:

decodeJson(json)

Decodes JSON.
Parameters:
Name Type Description
json String JSON to decode.
Source:

encodeJson(obj)

Encodes an object as JSON.
Parameters:
Name Type Description
obj object Object to encode.
Source:

executeCrossDomainGet(url, opts, jsonpOptionsopt)

Performs a cross domain GET for a decoded JSON object utilising CORS if supported by the device, falling back to a JSON-P call otherwise.
Parameters:
Name Type Attributes Description
url String The URL to load. A callback GET parameter will be appended if JSON-P is used.
opts Object Object containing callbacks and an optional bearer token.
Properties
Name Type Attributes Description
onSuccess function <optional>
Will be called with the decoded JSON object if the call is successful.
onError function <optional>
Will be called with error text, and HTTP status for CORS requests, if the calls fails.
bearerToken String <optional>
Used when making requests for resources that require authentication. For CORS requests, the token is used as a Bearer token in an Authorization header (see RFC 6750, section 2.1), and for JSON-P requests the token is included as a query string parameter. If not specified, no token is included in the request.
jsonpOptions Object <optional>
Options for the JSON-P fallback behaviour. All optional with sensible defaults.
Properties
Name Type Attributes Default Description
timeout Number <optional>
5000 Timeout for the JSON-P call in ms. Default: 5000.
id String <optional>
Used in the callback function name for the JSON-P call. Default: a random string.
callbackKey String <optional>
callback Key to use in query string when passing callback function name for JSON-P call. Default: callback
Source:

executeCrossDomainPost(url, data, opts)

Performs a cross domain POST HTTP using CORS or the content delivered as a single form field value depending on device capability
Parameters:
Name Type Description
url String The URL to post to.
data Object JavaScript object to be JSON encoded and delivered as payload.
opts Object Object containing callback functions, a form field name and an optional bearer token.
Properties
Name Type Attributes Description
fieldName String Name to be used for the POST form field for form based (non-CORS) requests.
onLoad function <optional>
Will be called with the decoded JSON response if the POST is successful.
onError function <optional>
Will be called with error text or an Exception object if the POST fails.
bearerToken String <optional>
Used when making POST requests for resources that require authentication. For CORS requests, the token is used as a Bearer token in an Authorization header (see RFC 6750, section 2.1), and for form requests the token is included as a bearerToken form field value. If not specified, no token is included in the request.
Source:

exit()

Exits the application directly - no history.
Source:

exitToBroadcast()

Exits to broadcast if this function has been overloaded by a modifier. Otherwise, calls exit().
Source:

getChildElementsByTagName(el, tagName)

Returns all direct children of an element which have the provided tagName.
Parameters:
Name Type Description
el Element The element who's children you wish to search.
tagName String The tag name you are looking for.
Source:
Returns:
An array of elements having the provided tag name.

getConfig()

Gets the current device configuration.
Source:
Returns:
The current device configuration document.

getCurrentRoute()

Gets the current route (a reference pointing to a location within the application).
Source:
Returns:
The current route (location within the application).

getElementOffset(el)

Returns the offset of the element within its offset container.
Parameters:
Name Type Description
el Element The element you wish to know the offset of.
Source:
Returns:
An literal object containing properties, top and left.

getElementSize(el)

Gets the size of an element.
Parameters:
Name Type Description
el Element The element of which to return the size.
Source:
Returns:
A size object containing the width and height of the element.

getKeyMap()

Gets the current key map from the device configuration.
Source:
Returns:
The current key map.

getLivePlayer() → {antie.devices.mediaplayer.MediaPlayer}

Get the live media player. This will return the correct implementation for the current device.
Source:
Returns:
Live media player for the current device.
Type
antie.devices.mediaplayer.MediaPlayer

getLiveSupport() → {String}

Get the level of live support. This will return the correct level of support for the current device.
Source:
Returns:
Live support level matching a value in {antie.devices.mediaplayer.MediaPlayer.LIVE_SUPPORT}.
Type
String

getLogger()

Get the logging object for the current device.
Source:
Returns:
The current device logging object.

getMediaPlayer() → {antie.devices.mediaplayer.MediaPlayer}

Get the media player. This will return the correct implementation for the current device.
Source:
Returns:
Media player for the current device.
Type
antie.devices.mediaplayer.MediaPlayer

getMuted()

Check to see if the volume is currently muted.
Source:
Returns:
Boolean true if the device is currently muted. Otherwise false.

getPlayerEmbedMode(mediaType)

Gets the player embed mode for the current device
Parameters:
Name Type Description
mediaType String "video" or "radio".
Source:
Returns:
The embed mode of the current player

getReferrer()

Gets the reference (e.g. URL) of the resource that launched the application.
Source:
Returns:
A reference (e.g. URL) of the resource that launched the application.

getScreenSize()

Gets the available screen size.
Source:
Returns:
An object with width and height properties.

getStorage(storageType, namespace)

Get a storage provider of a given type for the specified namespace.
Parameters:
Name Type Description
storageType Number The type of storage required (either StorageProvider.STORAGE_TYPE_SESSION or StorageProvider.STORAGE_TYPE_PERSISTENT).
namespace String The storage namespace.
Source:
Returns:
StorageProvider object.

getStylesheetElements()

Returns all the loaded stylesheet elements.
Source:
Returns:
An array containing all loaded stylesheet elements (link and style elements)

getTopLevelElement()

Returns the top-level element. This is the target of layout class names.
Source:
Returns:
The top-level DOM element.

getVolume()

Get the current volume.
Source:
Returns:
The current volume (0.0 to 1.0)

getWindowLocation() → {Object}

Get an object giving access to the current URL, query string, hash etc.
Source:
Returns:
Object containing, at a minimum, the properties: hash, host, href, pathname, protocol, search. These correspond to the properties in the window.location DOM API. Use getCurrentAppURL(), getCurrentAppURLParams() and getCurrentRoute() to get this information in a more generic way.
Type
Object

hideElement(options) → {Object}

Hides an element. Note: fps parameter currently only implemented when using styletopleft animation modifier. Consider using higher-level methods on the widget you want to hide (e.g. Component.hide()).
Parameters:
Name Type Description
options Object Details of the element to be hidden, with optional parameters.
Properties
Name Type Attributes Default Description
el Element The element you wish to hide.
skipAnim Boolean <optional>
By default the hiding of the element will be animated (faded out). Pass true here to prevent animation.
onComplete function <optional>
Callback function to be called when the element has been hidden.
fps Number <optional>
25 Frames per second for fade animation.
duration Number <optional>
840 Duration of fade animation, in milliseconds (ms).
easing String <optional>
linear Easing style for fade animation.
Source:
See:
Returns:
A handle to any animation started.
Type
Object

isAnimationDisabled() → {Boolean}

Check to see whether device has disabled animation.
Source:
Returns:
true if animation is disabled, false if animation is not disabled.
Type
Boolean

isBroadcastSourceSupported() → {Boolean}

Check to see whether the device has an API to control broadcast television.
Source:
Returns:
true if the API is available, false if not.
Type
Boolean

isHDEnabled()

Checks to see if HD output is currently enabled.
Source:
Returns:
True if HD is currently enabled.

isVolumeControlSupported()

Check to see if volume control is supported on this device.
Source:
Returns:
Boolean true if volume control is supported.

loadAuthenticatedURL(url, opts)

Loads a resource from a URL protected by device authentication.
Parameters:
Name Type Description
url String The URL to load.
opts Object Object containing onLoad and onError callback functions.
Source:
Returns:
The request object used to load the resource.

loadScript(url, callbackFunctionRegExp, callbacks, timeout, callbackSuffixopt)

Loads an external script that calls a specified callback function. Used for loading data via JSON-P.
Parameters:
Name Type Attributes Description
url String The URL of the script.
callbackFunctionRegExp RegExp Regular expression to replace matches with callback function name.
callbacks Object Object containing onSuccess and onLoad callback functions.
timeout Integer Timeout in milliseconds.
callbackSuffix String <optional>
Suffix to append to end of callback function name.
Source:
Returns:
The script element that will load the script.

loadStyleSheet(url, callbackopt)

Loads an external style sheet.
Parameters:
Name Type Attributes Description
url String The URL of the style sheet.
callback function <optional>
Callback function when style has loaded/failed
Source:
Returns:
The link element that will load the style sheet.

loadURL(url, opts) → {XMLHttpRequest}

Loads a resource from a URL.
Parameters:
Name Type Description
url String The URL to load.
opts Object Object containing onLoad and onError callback functions.
Source:
Returns:
The request object used to load the resource.
Type
XMLHttpRequest

moveElementTo(options) → {Object}

Moves an element so that its top-left corner is at the given position. Note: fps parameter currently only implemented when using styletopleft animation modifier. Consider using any animation methods on the widget you want to move. This method may be deprecated in future.
Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
el Element The element you wish to move.
to.left Integer <optional>
The x-coordinate you wish to position the top-left corner on. If null, the x-coordinate will not be altered.
to.top Integer <optional>
The y-coordinate you wish to position the top-left corner on. If null, the y-coordinate will not be altered.
skipAnim Boolean <optional>
By default the movement will be animated, pass true here to prevent animation.
onComplete function <optional>
Callback function to be called when the move has been completed.
fps Number <optional>
25 Frames per second for move animation
duration Number <optional>
840 Duration of move animation in milliseconds (ms).
easing.linear String <optional>
Easing move for scroll animation.
Source:
See:
Returns:
A handle to any animation started
Type
Object

preloadImage(url)

Forces the device to pre-load an image.
Parameters:
Name Type Description
url String The URL of the image to preload.
Source:

removeClassFromElement(el, className, deepopt)

Removes a class from an element (and optionally descendants)
Parameters:
Name Type Attributes Description
el Element The element from which to remove the class.
className String The class to remove.
deep Boolean <optional>
If true, and this element has the given class, remove the class from it's children recursively.
Source:

scrollElementTo(options) → {Object}

Scroll an element (within some masking container) so that its top-left corner is at the given position. Note: fps parameter currently only implemented when using styletopleft animation modifier. Consider using scrolling methods on the widget you wish to scroll (e.g. carousels). This method may be deprecated in future.
Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
el Element The element you wish to scroll.
to.left Integer <optional>
The x-coordinate you wish to position the top-left corner on. If null, the x-coordinate will not be altered.
to.top Integer <optional>
The y-coordinate you wish to position the top-left corner on. If null, the y-coordinate will not be altered.
skipAnim Boolean <optional>
By default the movement will be animated, pass true here to prevent animation.
onComplete function <optional>
Callback function to be called when the scroll has been completed.
fps Number <optional>
25 Frames per second for scroll animation
duration Number <optional>
840 Duration of scroll animation in milliseconds (ms).
easing.linear String <optional>
Easing move for scroll animation.
Source:
See:
Returns:
A handle to any animation started
Type
Object

setApplication(application)

Set a reference to the application the device is running.
Parameters:
Name Type Description
application antie.Application The application the device is running.
Source:

setCurrentRoute(route)

Sets the current route (a reference pointing to a location within the application).
Parameters:
Name Type Description
route Array A route pointing to a location within the application.
Source:

setElementClasses(el, classNames)

Sets the classes of an element.
Parameters:
Name Type Description
el Element The element which will receive new class names.
classNames Array An array of class names.
Source:

setElementSize(el, size)

Sets the size of an element.
Parameters:
Name Type Description
el Element The element of which to set the size.
size Size The new size of the element.
Source:

setMuted(muted)

Mute or unmute the device.
Parameters:
Name Type Description
muted Boolean The new muted state. Boolean true to mute, false to unmute.
Source:

setVolume(volume)

Set the current volume.
Parameters:
Name Type Description
volume Float The new volume level (0.0 to 1.0).
Source:

setWindowLocationUrl(url)

Browse to the specified location. Use launchAppFromURL() and setCurrentRoute() under Application to manipulate the current location more easily.
Parameters:
Name Type Description
url String Full URL to navigate to, including search and hash if applicable.
Source:

showElement(options) → {Object}

Shows an element. Note: fps and easing parameters only used by styletopleft modifier. Consider using higher-level methods on the widget you want to show (e.g. ComponentContainer.show()).
Parameters:
Name Type Description
options Object Details of the element to be shown, with optional parameters.
Properties
Name Type Attributes Default Description
el Element The element you wish to show.
skipAnim Boolean <optional>
By default the showing of the element will be animated (faded in). Pass true here to prevent animation.
onComplete function <optional>
Callback function to be called when the element has been shown.
fps Number <optional>
25 Frames per second for fade animation.
duration Number <optional>
840 Duration of fade animation, in milliseconds (ms).
easing String <optional>
linear Easing style for fade animation.
Source:
See:
Returns:
A handle to any animation started.
Type
Object

stopAnimation(anim)

Stops the specified animation. The any completeHandler for the animation will be executed.
Parameters:
Name Type Description
anim object A handle to the animation you wish to stop.
Source:

tweenElementStyle(options) → {Object}

Tweens a property (or properties) of an element's style from one value to another. Note: fps parameter currently only implemented when using styletopleft animation modifier.
Parameters:
Name Type Description
options Object Details of the element whose style will be tweened, with parameters describing tween.
Properties
Name Type Attributes Description
el Element The element with a style you wish to tween.
to Object A property: value map of the style properties you wish to tween and the numerical value of its destination, e.g { width: 30 }
duration: Number The duration of the tween in ms
from Object A property: value map of the style properties you wish to set at the start of the animation, e.g. { width: 0 }. If unset, the existing value will be used.
skipAnim Boolean <optional>
By default the tween will be animated. Set this to true for the tween to occur immediately. Any onComplete callback will still fire.
onComplete function <optional>
Callback function to be called when the tween is complete.
easing String <optional>
Easing style for animation.
units Object <optional>
Units to be appended to the style values in a property -> value map. (e.g. { width: 'px' }). Defaults are set in antie.devices.anim.shared.transitionendpoints
fps Number <optional>
Frames per second of animation (styletopleft only)
Source:
Returns:
A handle to animation started. This should only be used for passing to stopAnimation and nothing else should be inferred by its value. If no animation occurs, null may be returned but should not be used as an indicator.
Type
Object