Class adways.interactive.Experience
Extends: adways.event.EventDispatcherSUMMARY
Overview
"Experience" is the climax of the interactive video underlying processes. It brings in one "easy to deal with" class all the required stuff to manage the interactive video. It is a kind of "entry point" for developers who want to investigate more around the capabilities of the Adways interactive engine. It is a top level "public" tool to enhance productivity and help the setup of the interactivity in front of a video.
Setting the player
The "player builder" object
The player parameters
The media parameters
Setting the delegate
The "delegate builder" object
The delegate parameters
Additional options
Setting the scene
A scene is tied to a publication ID and the corresponding publication JSON.
Examples
Reminder:
- The static method "createExperience" is a helper that performs the "new" operation.
- There is a live demo here.
- Importing the Adways library is a pre-requisit:
<script src="//dj5ag5n6bpdxo.cloudfront.net/adways/libs/interactive/loader.js"></script>
Example #1: simple interactivity setup
The "Example #1: quick and simple interactive video setup" on the "AdwaysLib - interactive" documentation home page
shows the most simple and quick way to instanciate the interactivity. But it uses the createExperience
static method.
Here is how to manually perform the same operations:
// creates the new "Experience" object var experience = new adways.interactive.Experience(); console.log("new experience created: "+experience.getExperienceID()); // sets where the player will have to be instanciated experience.setPlayerContainer(domEelementOrDomId); // sets the publication ID (ie: the interactivity id) experience.setPublicationID("GSPfHsV"); // loads and builds everything experience.load();
Example #2: manual setup progression
It is possible to avoid the use of the load method by manually orchestrating the setups progression:
// creates the new "Experience" object var experience = new adways.interactive.Experience(); console.log("new experience created: "+experience.getExperienceID()); // sets where the player will have to be instanciated experience.setPlayerContainer(domEelementOrDomId); // sets the publication ID (ie: the interactivity id) experience.setPublicationID("GSPfHsV"); //since requesting the data is an async process, building the objects will have to wait until its // reception before starting: experience.addEventListener(adways.interactive.Experience.Event.PUBLICATION_JSON_CHANGED, function(){ if (experience.getPublicationJSON()!=null) { // builds the player from the data (asynchronous process) experience.buildPlayer(); // builds the scene from the data experience.buildScene(); } }); // The delegate cannot be built before the player is. But since building the player is an async process // (as for requesting the data), building the delegate has to wait for the player to be built: experience.addEventListener(adways.interactive.Experience.Event.PLAYER_STATE_CHANGED, function(){ if (experience.getPlayerState().valueOf()==adways.interactive.Experience.playerStates.BUILT) { // builds the delegate experience.buildDelegate(); } }); // gather the data of the publication (asynchronous process) experience.requestPublicationJSON();
Example #3: adding interactivity on top of an already instanciated video player
Here, the engine is not responsible of loading the player. The interactivity is added on top of an already instanciated one.
Yes, it is possible to add any interactive scenario on top of any stream of a known player.
(Contact the team to know if your player is compatible)
<!-- standard HTML5 video player instanciation --> <video id="video-player" style="width:600px;max-width:100%;" controls> <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"> <source src="http://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video. </video>
<script type="text/javascript"> // creates the new "Experience" object var experience = new adways.interactive.Experience(); // sets the player helper constant corresponding to the existing player experience.setPlayerClass("HTML5"); // adways.playerHelpers.HTML5 parameter is deprecated // sets the player API // the argument is the javascript object that represents the player API experience.setPlayerAPI(document.getElementById("video-player")); // sets the publication ID (ie: the interactivity id) experience.setPublicationID("GSPfHsV"); // loads and builds everything experience.load(); </script>
Example #4: gathering information on the interactions that occured while a video is playing
The next example shows the most easiest way to be aware of the "user media route".
Before launching the load of everything, it is possible to add some "event listeners" that will be triggered as soon as something happens.
Creates the experience object:
var experience = new adways.interactive.Experience(); experience.setPublicationID("GSPfHsV"); experience.setPlayerContainer("adways-interactive-video");
Now, prior to calling the "load" method, define and add a set of callback methods:
- Being aware of the scene loading:
// definning the callback var sceneStateChangedCB = function () { var s = "scene state changed: "; switch (experience.getSceneState().valueOf()) { case adways.interactive.Experience.sceneStates.EMPTY: s += "is now \"EMPTY\""; break; case adways.interactive.Experience.sceneStates.BUILDING: s += "is currently \"BUILDING\""; break; case adways.interactive.Experience.sceneStates.BUILT: s += "is now \"BUILT\" and available"; break; } console.log(s); }; // adding the event listener experience.addEventListener (adways.interactive.Experience.Event.SCENE_STATE_CHANGED, sceneStateChangedCB);
- Being aware of an action:
var actionExecutedCB = function (event) { var s = "action executed: "; switch (arguments[0].getAction().getKind()) { case adways.hv.actionKinds.SEEK_TO: s += "SEEK_TO ("+event.getAction().getTime().valueOf()+" seconds)"; break; case adways.hv.actionKinds.ACTIVATION: var enrichment = event.getAction().getEnrichment(); s += "enrichment ACTIVATION ("+enrichment.getName().valueOf()+" , "+enrichment.getEnrichmentId().valueOf()+")"; break; case adways.hv.actionKinds.PLAYPAUSE: s += "PLAY/PAUSE state changed to "+event.getAction().getPlayState().valueOf(); break; case adways.hv.actionKinds.URL: s += "URL opened ("+event.getAction().getURL().valueOf()+")"; break; } console.log (s); }; experience.addEventListener(adways.interactive.Experience.Event.ACTION_EXECUTED, actionExecutedCB);
- Being aware of a user click on a content:
var contentClickedCB = function (event) { var s = "content clicked. It belongs to the enrichment "; var enrichment = event.getContent().getEnrichment(); s += enrichment.getName().valueOf(); s += " of id "; s += enrichment.getEnrichmentId().valueOf(); console.log(s); }; experience.addEventListener(adways.interactive.Experience.Event.CONTENT_CLICKED, contentClickedCB);
- Being aware of a stat sent from on a content:
var contentStatCB = function (event) { var statKey = event.getKey(); var statValue = event.getValue(); var s = "stat sent. Key : "+statKey+", value : "+statValue+". It belongs to the enrichment "; var enrichment = event.getContent().getEnrichment(); s += enrichment.getName().valueOf(); s += " of id "; s += enrichment.getEnrichmentId().valueOf(); console.log(s); }; experience.addEventListener(adways.interactive.Experience.Event.CONTENT_STAT, contentStatCB);
- Being aware of an enrichment open/close operation:
var enrichmentActivationChangedCB = function (event) { var enrichment = event.getEnrichment(); var s = "enrichment ("; s += enrichment.getName().valueOf(); s += " , "; s += enrichment.getEnrichmentId().valueOf(); s += ") activation changed to: "; s += enrichment.getActivated().valueOf(); console.log(s); }; experience.addEventListener(adways.interactive.Experience.Event.ENRICHMENT_ACTIVATION_CHANGED, enrichmentActivationChangedCB);
And now it is possible to launch the experience's "load" method:
experience.load();
Nested classes: Event, PercentConsumedEvent, ActionEvent, ContentEvent, ContentStatEvent, EnrichmentEvent,
adways.interactive.Experience
(
)
public
Fired when the scene state changed.
Fired every 10 percent played of video total time.
Fired when a content sends a custom stat.
Fired when an enrichment activation changed.
Fired when the engine execute an action.
Fired when a content is clicked.
addEventListener
( kind, callback, [instance=null], [priority=0], [useWeakReference=false]
)
public
Parameters:
-
kind
<Constant>kind of the event to listen -
callback
<FUNCTION>function called when the event is fired -
[instance=null]
<Object> optionalcallback's instance. Useful when the callback is binded to an object:Class = function () {}; Class.prototype.callback = function () {}; var a = new Class(); aDispatcher.addEventListener(AN_EVENT_KIND, a.callback, a);
-
[priority=0]
<Number> optionalpriority -
[useWeakReference=false]
<Boolean> optionalnot yet used
instance==null
, the callback should be accessible from the global context and be a "static" method. Exemple:namespaceA.subnamespace.myCallback = function (event) { ... }; aDispatcher.addEventListener(AN_EVENT_KIND, namespaceA.subnamespace.myCallback);
buildDelegate
(
)
public
Builds the delegate calling the delegate builder class.
see delegate
- 1: delegateBuilder successfully called
- -1: invalid playerAPI or no player already built
- -2: invalid delegateBuilderClassname
- -3: invalid delegateBuilderURL
buildPlayer
(
)
public
Builds the player calling the player builder class.
see player
- .
- 1: player builder successfully called
- -1: the playerContainer is not valid (not a DOMElement)
- -2: invalid playerBuilderCassname
- -3: invalid playerBuilderURL
- -4: a player may be under construction
buildScene
(
)
public
Builds the scene if a publication JSON is valid.
The scene could be built asynchronously once a publication JSON is given / requested.
see scene
1 if success, 0 otherwise.
clearAll
(
)
public
Resets the experience into the same state as it was right after a simple "new".
1 if success, 0 otherwise (currently always 1 since it is currently "brute forced").
clearPlayer
( [withConfig=false]
)
public
May destroy the player and the associated delegate object. There is 2 cases to consider:
- the current "Experience" object is used to build everything: the player and the interactivity above
Since the experience was responsible of building the player, it is also responsible of destroying it. A call to "clearPlayer" then removes the player from the web page and destructs it. - the current "Experience" object is used to add interactivity on top of an already instanciated player
Since the experience was only responsible of adding the interactivity, not building the player, a call to "clearPlayer" then only removes and destroys what was added to make the interactivity working: the delegate. It does not modify the "already in place" player.
withConfig=false
- the "delegate" object is destroyed and the attribute reset to
null
- the "delegateBuilder" is destroyed and the attribute reset to
null
- the "playerAPI" is reset to
null
- the "playerBuilder" is destroyed (if any, depending on the 2 cases above), which also destroys the player; and the attributes are reset
to
null
=>buildPlayer()
is callable right after and the player will be rebuilt.- the "delegate" object is destroyed and the attribute reset to
withConfig=true
buildPlayer()
is not callable right after because all the tied data are cleared. Performs the same operations as "withConfig=false", plus:- reset the delegate params to
new Object()
- reset the player params to
new Object()
- reset the media params to
new Object()
- reset the options to
new Object()
- reset the player container to
null
- reset the playerBuilderURL to
null
- reset the playerBuilderClassname to
null
- reset the delegateBuilderURL to
null
- reset the delegateBuilderClassname to
null
- reset the delegate params to
Parameters:
-
[withConfig=false]
<Boolean> optionalwhether to "deeply" clear all the attributes linked to the player.
Fired when player state changed.
Fired when delegate state changed.
1 if success, 0 otherwise (currently always 1 since it is currently "brute forced").
clearScene
(
)
public
Clears the scene. Reset elements:
- the "publicationID" string, to
""
- the "publicationJSON" json, to
null
- the "scene" object
pause()
is called on the "s2p" and "p2s" objects.Fired when publication id changed.
Fired when publication JSON changed.
Fired when scene state changed.
1 if success, 0 otherwise (currently always 1 since it is currently "brute forced").
getDelegateBuilderClassname
(
)
public
Description is coming soon.
?.
getDelegateBuilderURL
(
)
public
Description is coming soon.
?.
getDelegateParams
( key
)
public
Gives one "delegate parameter".
Parameters:
-
key
<String>the parameter's name.
the "key" parameter's value.
getDelegateParams
(
)
public
Gives the "delegate parameters".
Be careful, the current method gives a pointer onto the parameters, not a copy of them. So changing them may impact a current
running interactivity setup process. Example:
... experience.buildDelegate(); // asynchronous experience.getDelegateParams()["key1"] = newValue; // dangerous ! ...Such a code changes the parameters named "key1" while the delegate is building...
"Prefer using setDelegateParams() instead, it checks whether you can set or not."
the JSON formatted set of <key,value>.
getDelegateState
(
)
public
Description is coming soon.
?.
getExperienceID
(
)
public
Description is coming soon.
?.
getMediaParams
(
)
public
Gives the "media parameters".
Be careful, the current method gives a pointer onto the parameters, not a copy of them. So changing them may impact a current
running interactivity setup process. Example:
... experience.buildPlayer(); experience.getmediaParams()["key1"] = newValue; // dangerous ! ...Such a code changes the parameters named "key1" while the player is building...
"Prefer using setMediaParams() instead, it checks whether you can set or not."
the JSON formatted set of <key,value>.
getMediaParams
( key
)
public
Gives one "media parameter".
Parameters:
-
key
<String>the parameter's name.
the "key" parameter's value.
getOptions
( key
)
public
Gives one "option".
Parameters:
-
key
<String>the option's name.
the "key" option's value.
getOptions
(
)
public
Gives the "options".
Be careful, the current method gives a pointer onto the options, not a copy of them. So changing them may impact a current
running interactivity setup process. Example:
... experience.buildPlayer(); experience.getOptions()["key1"] = newValue; // dangerous ! ...Such a code changes the options named "key1" while the player is building...
"Prefer using setOptions() instead, it checks whether you can set or not."
the JSON formatted set of <key,value>.
getP2S
(
)
public
Description is coming soon.
?.
getPlayerBuilderClassname
(
)
public
Description is coming soon.
see player
?.
getPlayerBuilderURL
(
)
public
Gives the player builder script url.
This points the script that holds the "player builder" class, a class capable of building, setuping and displaying the player acording to some
parameters.
see player
the player builder script url.
getPlayerContainer
(
)
public
Description is coming soon.
see player
?.
getPlayerParams
(
)
public
Gives the "player parameters".
Be careful, the current method gives a pointer onto the parameters, not a copy of them. So changing them may impact a current
running interactivity setup process. Example:
... experience.buildPlayer(); experience.getPlayerParams()["key1"] = newValue; // dangerous ! ...Such a code changes the parameters named "key1" while the player is building...
"Prefer using setPlayerParams() instead, it checks whether you can set or not."
the JSON formatted set of <key,value>.
getPlayerParams
( key
)
public
Gives one "player parameter".
Parameters:
-
key
<String>the parameter's name.
the "key" parameter's value.
getPlayerState
(
)
public
Description is coming soon.
see player
?.
getS2P
(
)
public
Description is coming soon.
?.
getScene
(
)
public
Description is coming soon.
see scene
?.
getSceneState
(
)
public
Description is coming soon.
see scene
?.
hasEventListener
( kind, callback, [instance=null]
)
public
Parameters:
-
kind
<Constant>the event's kind -
callback
<FUNCTION>the listener's function -
[instance=null]
<Object> optionalthe listener callback's instance
load
(
)
public
Description is coming soon.
?.
nbEventListeners
( kind
)
public
Parameters:
-
kind
<Constant>the event's kind
removeAllEventListeners
(
)
public
removeEventListener
( kind, callback, [instance=null]
)
public
Parameters:
-
kind
<Constant>kind of the event to listen -
callback
<FUNCTION>function called when the event is fired -
[instance=null]
<Object> optionalcallback's instance
requestPublicationJSON
(
)
public
Description is coming soon.
see scene
1 if success, 0 otherwise.
setDelegateBuilderClassname
(
)
public
Description is coming soon.
- 1 on successful affectation
- -1 when the argument is missing
- -2 when the argument is not a string
- -3 if the current experience already has a delegate, so when
getDelegateState().valueOf()==delegateStates.EMPTY
setDelegateBuilderURL
(
)
public
Description is coming soon.
- 1 on successful affectation
- -1 when the argument is missing
- -2 when the argument is not a string
- -3 if the current experience already has a delegate, so when
getDelegateState().valueOf()==delegateStates.EMPTY
setDelegateParams
( key, value
)
public
Sets/updates one "delegate parameter".
Parameters:
-
key
<String>the parameter's name.
-
value
<?>the parameter's value.
- 1: the parameter is newly set
- 2: the parameter is updated (the key already exists, the value is updated)
- 0: nothing happened: trying to set the same value
- -1: arguments error: expected 1 argument at least
- -4: arguments error: the key is not a string or is an empty string
- -5: arguments error: the value is undefined
- -10: usage error: calling
setDelegateParams
whilegetDelegateState().valueOf()!==EMPTY
setDelegateParams
( paramsSet
)
public
Sets multiple "delegate parameters" at once.
Be careful: overrides all the already set "delegate parameters".
Parameters:
-
paramsSet
<Object>a JSON formatted <key,value> set of parameters. Example:
{ "key1": value1, "key2": value2, ... }
- 1: the parameters are set
- -1: arguments error: there is no argument
- -2: arguments error: the argument is not an object
- -3: arguments error: the argument is null
- -10: usage error: calling
setDelegateParams
whilegetDelegateState().valueOf()!==EMPTY
setMediaParams
( key, value
)
public
Sets/updates one "media parameter".
Parameters:
-
key
<String>the parameter's name.
-
value
<?>the parameter's value.
- 1: the parameter is newly set
- 2: the parameter is updated (the key already exists, the value is updated)
- 0: nothing happened: trying to set the same value
- -1: arguments error: expected 1 argument at least
- -4: arguments error: the key is not a string or is an empty string
- -5: arguments error: the value is undefined
- -10: usage error: calling
setMediaParams
whilegetPlayerState().valueOf()!==EMPTY
setMediaParams
( paramsSet
)
public
Sets multiple "media parameters" at once.
Be careful: overrides all the already set "media parameters".
Parameters:
-
paramsSet
<Object>a JSON formatted <key,value> set of parameters. Example:
{ "key1": value1, "key2": value2, ... }
- 1: the parameters are set
- -1: arguments error: there is no argument
- -2: arguments error: the argument is not an object
- -3: arguments error: the argument is null
- -10: usage error: calling
setMediaParams
whilegetPlayerState().valueOf()!==EMPTY
setOptions
( optionsSet
)
public
Sets multiple "options" at once.
Be careful: overrides all the already set "options".
Parameters:
-
optionsSet
<Object>a JSON formatted <key,value> set of options. Example:
{ "key1": value1, "key2": value2, ... }
- 1: the options are set
- -1: arguments error: there is no argument
- -2: arguments error: the argument is not an object
- -3: arguments error: the argument is null
- -10: usage error: calling
setOptions
whilegetPlayerState().valueOf()!==EMPTY
setOptions
( key, value
)
public
Sets/updates one "options".
Parameters:
-
key
<String>the option's name.
-
value
<?>the option's value.
- 1: the option is newly set
- 2: the option is updated (the key already exists, the value is updated)
- 0: nothing happened: trying to set the same value
- -1: arguments error: expected 1 argument at least
- -4: arguments error: the key is not a string or is an empty string
- -5: arguments error: the value is undefined
- -10: usage error: calling
setOptions
whilegetPlayerState().valueOf()!==EMPTY
setPlayerBuilderClassname
(
)
public
Description is coming soon.
see player
- 1 on successful affectation
- -1 when the argument is missing
- -2 when the argument is not a string
- -3 if the current experience already has a player, so when
getPlayerState().valueOf()==playerStates.EMPTY
setPlayerBuilderURL
(
)
public
Description is coming soon.
see player
- 1 on successful affectation
- -1 when the argument is missing
- -2 when the argument is not a string
- -3 if the current experience already has a player, so when
getPlayerState().valueOf()==playerStates.EMPTY
setPlayerClass
(
)
public
Player and delegate setters ("builder URLs" and "builder classnames") shortcut.
- 1 on success
- -1 when the argument is missing
- -2 if the argument is not an object
setPlayerParams
( key, value
)
public
Sets/updates one "player parameter".
Parameters:
-
key
<String>the parameter's name.
-
value
<?>the parameter's value.
- 1: the parameter is newly set
- 2: the parameter is updated (the key already exists, the value is updated)
- 0: nothing happened: trying to set the same value
- -1: arguments error: expected 1 argument at least
- -4: arguments error: the key is not a string or is an empty string
- -5: arguments error: the value is undefined
- -10: usage error: calling
setPlayerParams
whilegetPlayerState().valueOf()!==EMPTY
setPlayerParams
( paramsSet
)
public
Sets multiple "player parameters" at once.
Be careful: overrides all the already set "player parameters".
Parameters:
-
paramsSet
<Object>a JSON formatted <key,value> set of parameters. Example:
{ "key1": value1, "key2": value2, ... }
- 1: the parameters are set
- -1: arguments error: there is no argument
- -2: arguments error: the argument is not an object
- -3: arguments error: the argument is null
- -10: usage error: calling
setPlayerParams
whilegetPlayerState().valueOf()!==EMPTY
setPublicationID
(
)
public
Description is coming soon.
see scene
1 if success, 0 otherwise.
setPublicationJSON
(
)
public
Description is coming soon.
see scene
1 if success, 0 otherwise.
setSceneTimeReference
( setSceneTimeReference
)
public
Indicates whether the time reference for the interactivity is video time or scene time.
Parameters:
-
setSceneTimeReference
<Boolean>the scene time reference indicator, true for scene time, false for video time.
- 1: the parameter is newly set
- 0: nothing happened: trying to set the same value
- -1: arguments error: expected 1 argument at least
- -2: arguments error: the setSceneTimeReference is not a boolean
- -3: usage error: calling
setSceneTimeReference
whilegetSceneState().valueOf()!==EMPTY
unsetDelegateParams
( key
)
public
Removes one "delegate parameter".
Parameters:
-
key
<String>the parameter's name.
- 1: parameter unset success
- 0: nothing to delete: key not found
- -1: arguments error: there is no argument
- -2: arguments error: the key is not a string or is an empty string
- -10: usage error: calling
unsetDelegateParams
whilegetDelegateState().valueOf()!==EMPTY
unsetMediaParams
( key
)
public
Removes one "media parameter".
Parameters:
-
key
<String>the parameter's name.
- 1: parameter unset success
- 0: nothing to delete: key not found
- -1: arguments error: there is no argument
- -2: arguments error: the key is not a string or is an empty string
- -10: usage error: calling
unsetMediaParams
whilegetPlayerState().valueOf()!==EMPTY
unsetOptions
( key
)
public
Removes one "option".
Parameters:
-
key
<String>the option's name.
- 1: option unset success
- 0: nothing to delete: key not found
- -1: arguments error: there is no argument
- -2: arguments error: the key is not a string or is an empty string
- -10: usage error: calling
unsetOptions
whilegetPlayerState().valueOf()!==EMPTY
unsetPlayerParams
( key
)
public
Removes one "player parameter".
Parameters:
-
key
<String>the parameter's name.
- 1: parameter unset success
- 0: nothing to delete: key not found
- -1: arguments error: there is no argument
- -2: arguments error: the key is not a string or is an empty string
- -10: usage error: calling
unsetPlayerParams
whilegetPlayerState().valueOf()!==EMPTY