Attaching and detaching events - Storm Library

Storm player utilizes event-lister model for direct communication. While actions can be executed using available methods (API), a feedback player is also necessary.

Attaching an event listener

Attaching an event lister is a straightforward task

let storm = new Storm(config);

storm.addEventListener("playerReady", function(event){

In this simple example, we have added a new event listener (called playerReady) to the player. Whenever the player becomes ready, an attached function will be called. The function can also be of an inline type.

storm.addEventListener("playerReady", onPlayerReady);

And more advanced variation is also possible (and suggested):

storm.addEventListener("playerReady", onPlayerReady, thisReference, 10);

The thisReference object allows you to pass a reference for this element within the onPlayerReady function, while eventData contains data related to the player. The last parameter indicates listener priority (0 is default).

function onPlayerReady(thisReference, eventData){

    console.log(eventData.getInfo().getDispatcher) // player
    console.log(eventData.getInfo().getEventName()) // playerReady
    console.log(eventData.getInfo().getData()) // additional data related to the event


Detaching an event listener

In order to detach (remove) an event listener just use:

storm.removeEventListener("playerReady", onPlayerReady);

For obvious reasons, inline functions cannot be removed, however, there is a way to remove all events from the player: