Events & Listeners Basics - Storm JavaScript Player

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

Attaching an Event Listener

Attaching an event lister is a straightforward task:

                        
const player = stormPlayer(playerConfig, streamConfig);

player.addEventListener("interfaceReady", function(event){
    console.log("onPlayerReady",event);
});
                    

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

                        
player.addEventListener("interfaceReady", onGUIInitialized);
                    

Detaching an Event Listener

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

                        
player.removeEventListener("interfaceReady", onGUIInitialized);
                            

For obvious reasons, inline functions cannot be removed (unless stored as a variable), however, there is a way to remove all events from the player:

                        
player.removeAllEventListeners();
                    
Next Step

For the next step please check our Storm JavaScript Player Events where you’ll learn about available events for player behaviour.

Support Needed?

Create a free ticket and our support team will provide you necessary assistance.