VideoAdUnit

VideoAdUnit

new VideoAdUnit(vastChain, videoAdContainer, optionsopt)

This class provides shared logic among all the ad units.

Parameters:
Name Type Attributes Description
vastChain VastChain

The VastChain with all the VastResponse

videoAdContainer VideoAdContainer

container instance to place the ad

options Object <optional>

Options Map. The allowed properties are:

Properties
Name Type Attributes Description
logger Console <optional>

Optional logger instance. Must comply to the Console interface. Defaults to window.console

viewability boolean <optional>

if true it will pause the ad whenever is not visible for the viewer. Defaults to false

responsive boolean <optional>

if true it will resize the ad unit whenever the ad container changes sizes Defaults to false

Implements:
Source:

Extends

Members

error

If an error occurs it will contain the reference to the error otherwise it will be bull

Source:

errorCode

If an error occurs it will contain the Vast Error code of the error

Source:

icons

Array of VastIcon definitions to display from the passed VastChain or null if there are no icons.

Source:

type

Ad unit type

Source:

vastChain

Reference to the VastChain used to load the ad.

Source:

videoAdContainer

Reference to the VideoAdContainer that contains the ad.

Source:

Methods

cancel()

Cancels the ad unit.

Source:
Throws:

if ad unit is finished.

currentTime() → {number}

Returns the current time of the ad Creative or 0 if there is no creative.

Source:

duration() → {number}

Returns the duration of the ad Creative or 0 if there is no creative.

Source:

emit(eventName) → {boolean}

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

Parameters:
Name Type Description
eventName string

The name of the event.

Inherited From:
Source:

getVolume() → {number}

Gets the volume of the ad unit.

Source:
Throws:
  • if ad unit is not started.

  • if ad unit is finished.

isFinished() → {boolean}

Source:

isStarted() → {boolean}

Source:

on(eventName, listener) → {Emitter}

Adds the listener function to the end of the listeners array for the event named eventName.

Parameters:
Name Type Description
eventName string

The name of the event.

listener function

Listener fn that handles the evt.

Inherited From:
Source:

once(eventName, listener) → {Emitter}

Adds a one time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

Parameters:
Name Type Description
eventName string

The name of the event.

listener function

Listener fn that handles the evt.

Inherited From:
Source:

onError(callback)

Register a callback function that will be called if there is an error while running the ad.

Parameters:
Name Type Description
callback function

will be called on ad unit error passing the Error instance and an object with the adUnit and the VastChain.

Source:
Throws:

if ad unit is finished.

onFinish(callback)

Register a callback function that will be called whenever the ad finishes. No matter if it was finished because de ad ended, or cancelled or there was an error playing the ad.

Parameters:
Name Type Description
callback function

will be called once the ad unit finished

Source:
Throws:

if ad unit is finished.

pause()

Pauses the ad unit.

Source:
Throws:
  • if ad unit is not started.

  • if ad unit is finished.

paused()

Returns true if the ad is paused and false otherwise

Source:

removeAllListeners(eventName) → {Emitter}

Removes all listeners, or those of the specified eventName.

Parameters:
Name Type Description
eventName string

The name of the event. Optional if omitted all listeners will be removed.

Inherited From:
Source:

removeListener(eventName, listener) → {Emitter}

Removes the specified listener from the listener array for the event named eventName.

Parameters:
Name Type Description
eventName string

The name of the event.

listener function

Listener fn that handles the evt.

Inherited From:
Source:

(async) resize() → {Promise}

This method resizes the ad unit to fit the available space in the passed VideoAdContainer

Source:
Throws:
  • if ad unit is not started.

  • if ad unit is finished.

resume()

Resumes a previously paused ad unit.

Source:
Throws:
  • if ad unit is not started.

  • if ad unit is finished.

setVolume(volume)

Sets the volume of the ad unit.

Parameters:
Name Type Description
volume number

must be a value between 0 and 1;

Source:
Throws:
  • if ad unit is not started.

  • if ad unit is finished.

Events

adProgress

fires on ad progress.

Source:

finish

Fires when the adUnit's has finished.

Source:

volumeChanged

Fires when the adUnit's volume has changed.

Source: