4.1.3 • Published 23 days ago

@stormstreaming/stormplayer v4.1.3

Weekly downloads
-
License
SEE LICENCE IN LI...
Repository
github
Last release
23 days ago

Storm JavaScript Player

Storm Player is a fully customizable GUI wrapper project for Storm Library, which can act as ready-to use Web Video Player or work as a template for creating your own, customizable players. It is a part of Storm Streaming Suite and requires Storm Streaming Server instance or Cloud subscription to work.

If you wish to test the player, check its API, look code snippets please visit our demo page: https://www.stormstreaming.com/demo/index.html

To get started check our examples and documentation at https://www.stormstreaming.com/docs/v2

Requirements

  • Node 16.16.0+

Installation

  1. Using NPM:

npm install @stormstreaming/stormplayer

  1. Using Yarn:

yarn add @stormstreaming/stormplayer

  1. Manually - if you are clueless about NPM/Yarn or simply want to test it out, just grab/dist/iife/index.js file and embed it on your website.

Project compilation

Start with downloading and installing all dependencies.

npm install

Now you can build the project with:

npm run build

For development, you can use:

npm run dev

Sample setup

  1. IIFE (Immediately-Invoked Function Expression).
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Storm Player - IIFE Sample page</title>
    <meta charset="UTF-8">
    <script src="../dist/iife/index.js"></script>
</head>
<body>
    <div id="container"></div>
    <script>
        /**
         * Standard library configuration object
         */
        const streamConfig = {
            configurationType: "embedded",                   // "embedded" or "gateway", please check doc for more info
            stream: {
                serverList: [                                // list of streaming server, 2nd, 3rd etc. will be used as backup
                    {
                        host: "localhost",                   // host or ip to the streaming server
                        application: "live",                 // application name (can be configured in storm server settings)
                        port: 80,                            // server port
                        ssl: false                           // whenever SSL connection should be used or not
                    }
                ],
                sourceList: [
                    {
                        protocol: "storm",                   // either "storm" (stream was published to the server), or "rtmp". RTMP (external source)
                        streamKey: "test",                   // streamKey of the stream
                    },
                ]
            },
            settings: {
                autoStart: true,                              // if true, video will start playing automatically, but will be muted too
                debug: {
                    console: {                                // console output
                        enabled: true                         // if console output is activated
                    }
                }
            }
        };

        /**
         * Standard player configuration object
         */
        const playerConfig = {
            containerID: "container",                        // HTML container where player will be added
            aspectRatio: "16:9",                             // <video> element will scale to provided aspect-ratio. This parameter is optional and will overwrite "height" parameter as "width" will only be used for calculations
            width: "100%",                                   // <video> element width, can be either "px" or "%" (string), as (number) will always be "px" value. For % it'll auto-scale to parent container,
            title: "Title goes here",                        // title for the stream
            subtitle: "This is going to be epic!",           // subtitle for the stream
        };

        /**
         * Each player instance must be provided with both player (gui) and library configs
         */
        const storm = stormPlayer(playerConfig, streamConfig);

    </script>
</body>
</html>
  1. UMD (Universal Module Definition).
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Storm Player - UMD Sample page</title>
    <meta charset="UTF-8">
    <script src="../dist/umd/index.js"></script>
</head>
<body>
    <div id="container"></div>
    <script>
        /**
         * Standard library configuration object
         */
        const streamConfig = {
            configurationType: "embedded",                   // "embedded" or "gateway", please check doc for more info
            stream: {
                serverList: [                                // list of streaming server, 2nd, 3rd etc. will be used as backup
                    {
                        host: "localhost",                   // host or ip to the streaming server
                        application: "live",                 // application name (can be configured in storm server settings)
                        port: 80,                            // server port
                        ssl: false                           // whenever SSL connection should be used or not
                    }
                ],
                sourceList: [
                    {
                        protocol: "storm",                   // either "storm" (stream was published to the server), or "rtmp". RTMP (external source)
                        streamKey: "test",                   // streamKey of the stream
                    },
                ]
            },
            settings: {
                autoStart: true,                              // if true, video will start playing automatically, but will be muted too
                debug: {
                    console: {                                // console output
                        enabled: true                         // if console output is activated
                    }
                }
            }
        };

        /**
         * Standard player configuration object
         */
        const playerConfig = {
            containerID: "container",                        // HTML container where player will be added
            aspectRatio: "16:9",                             // <video> element will scale to provided aspect-ratio. This parameter is optional and will overwrite "height" parameter as "width" will only be used for calculations
            width: "100%",                                   // <video> element width, can be either "px" or "%" (string), as (number) will always be "px" value. For % it'll auto-scale to parent container,
            title: "Title goes here",                        // title for the stream
            subtitle: "This is going to be epic!",           // subtitle for the stream
        };
        
        /**
         * Creating an instance of the storm library
         */
        const storm = stormPlayer.create(playerConfig, libraryConfig);

    </script>
</body>
</html>
  1. ESM (Universal Module Definition).
import {StormPlayer} from "../dist/esm/index.js";

/**
 * Standard library configuration object
 */
const streamConfig = {
    configurationType: "embedded",                   // "embedded" or "gateway", please check doc for more info
    stream: {
        serverList: [                                // list of streaming server, 2nd, 3rd etc. will be used as backup
            {
                host: "localhost",                   // host or ip to the streaming server
                application: "live",                 // application name (can be configured in storm server settings)
                port: 80,                            // server port
                ssl: false                           // whenever SSL connection should be used or not
            }
        ],
        sourceList: [
            {
                protocol: "storm",                   // either "storm" (stream was published to the server), or "rtmp". RTMP (external source)
                streamKey: "test",                   // streamKey of the stream
            },
        ]
    },
    settings: {
        autoStart: true,                              // if true, video will start playing automatically, but will be muted too
        debug: {
            console: {                                // console output
                enabled: true                         // if console output is activated
            }
        }
    }
};

/**
 * Standard player configuration object
 */
const playerConfig = {
    containerID: "container",                        // HTML container where player will be added
    aspectRatio: "16:9",                             // <video> element will scale to provided aspect-ratio. This parameter is optional and will overwrite "height" parameter as "width" will only be used for calculations
    width: "100%",                                   // <video> element width, can be either "px" or "%" (string), as (number) will always be "px" value. For % it'll auto-scale to parent container,
    title: "Title goes here",                        // title for the stream
    subtitle: "This is going to be epic!",           // subtitle for the stream
};

/**
 * Each player instance must be provided with both player (gui) and library configs
 */
const storm = new StormPlayer(playerConfig, libraryConfig);
  1. AMD (Asynchronous Module Definition).
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Storm Player - AMD Sample page</title>
    <meta charset="UTF-8">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
</head>
<body>
    <div id="container"></div>
    <script>
         /**
         * Standard library configuration object
         */
        const streamConfig = {
            configurationType: "embedded",                   // "embedded" or "gateway", please check doc for more info
            stream: {
                serverList: [                                // list of streaming server, 2nd, 3rd etc. will be used as backup
                    {
                        host: "localhost",                   // host or ip to the streaming server
                        application: "live",                 // application name (can be configured in storm server settings)
                        port: 80,                            // server port
                        ssl: false                           // whenever SSL connection should be used or not
                    }
                ],
                sourceList: [
                    {
                        protocol: "storm",                   // either "storm" (stream was published to the server), or "rtmp". RTMP (external source)
                        streamKey: "test",                   // streamKey of the stream
                    },
                ]
            },
            settings: {
                autoStart: true,                              // if true, video will start playing automatically, but will be muted too
                debug: {
                    console: {                                // console output
                        enabled: true                         // if console output is activated
                    }
                }
            }
        };

        /**
         * Standard player configuration object
         */
        const playerConfig = {
            containerID: "container",                        // HTML container where player will be added
            aspectRatio: "16:9",                             // <video> element will scale to provided aspect-ratio. This parameter is optional and will overwrite "height" parameter as "width" will only be used for calculations
            width: "100%",                                   // <video> element width, can be either "px" or "%" (string), as (number) will always be "px" value. For % it'll auto-scale to parent container,
            title: "Title goes here",                        // title for the stream
            subtitle: "This is going to be epic!",           // subtitle for the stream
        };

        /**
         * Path to the AMD module
         */
        requirejs(['../dist/amd/index'], function (storm) {

            /**
             * Library instance
             */
            const player = new storm.create(playerConfig, libraryConfig);

        });

    </script>
</body>
</html>

Attaching and detaching events

/**
 * An event can be registered using addEventListener method (preferably before initialize() method is called)
 */
player.addEventListener("playerCoreReady", onLibraryReady);

/**
 * Inline functions are fine too...
 */
player.addEventListener("playerCoreReady", function(event){
    console.log("playerReady");
});

/**
 * An event can also be removed...
 */
player.removeEventListener("playerCoreReady", onLibraryReady);

/**
 * All event listeners of that type can be removed like this
 */
player.removeEventListener("playerCoreReady");

Sample event listeners

player.addEventListener("playerCoreReady", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} is ready for interaction!`);
})

player.addEventListener("serverConnectionInitiate", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Connection to: ${event.serverURL} has been initialized`);
})

player.addEventListener("serverConnect", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Successfully connected to: ${event.serverURL}`);
})

player.addEventListener("serverDisconnect", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Disconnected from: ${event.serverURL}`);
})

player.addEventListener("serverConnectionError", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Could not connect to server: ${event.serverURL}`);
})

player.addEventListener("allConnectionsFailed", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - All connections from server list failed`);
})

player.addEventListener("streamStateChange", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Stream: ${event.streamKey} has changed it state: ${event.state}.`);
})

player.addEventListener("streamNotFound", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - No stream for streamKey: ${event.streamKey}`);
})

player.addEventListener("interactionRequired", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - User interaction is required!`);
})

player.addEventListener("playbackInitiate", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Playback initiated for streamKey: ${event.streamKey}`);
})

player.addEventListener("playbackStart", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Playback started for streamKey: ${event.streamKey}`);
})

player.addEventListener("playbackPause", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Playback paused for streamKey: ${event.streamKey}`);
})

player.addEventListener("streamStop", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Stream has stopped`);
})

player.addEventListener("volumeChange", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Volumed changed, new value: ${event.volume}`);
    console.log(`-->: is muted: ${event.muted}`);
    console.log(`-->: invoked by: ${event.invokedBy}`);
})

player.addEventListener("playbackProgress", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Progress event`);
    console.log(`-->: playback duration: ${event.playbackDuration}`);
    console.log(`-->: playback start time: ${event.playbackStartTime}`);
    console.log(`-->: stream total duration: ${event.streamDuration}`);
    console.log(`-->: stream start time: ${event.streamStartTime}`);
    console.log(`-->: dvr cache size: ${event.dvrCacheSize}`);
})

player.addEventListener("metadataReceived", function(event){
    console.log(`Player ID: ${event.ref.getLibraryID()} - Metadata arrived`);
    console.log(`-->: video-codec: ${event.metadata.getVideoCodec()}`);
    console.log(`-->: audio-codec: ${event.metadata.getAudioCodec()}`);
    console.log(`-->: video width: ${event.metadata.getVideoWidth()}`);
    console.log(`-->: video height: ${event.metadata.getVideoHeight()}`);
    console.log(`-->: fps: ${event.metadata.getNominalFPS()}`);
    console.log(`-->: encoder: ${event.metadata.getEncoder()}`);
})

Player Event list

Event nameAdditional dataDescriptionCan be fired more than once
interfaceReadynoEvent fires when the player interface is ready. This action takes place before libraryCreated event.no
libraryCreatenoEvent fires when the player library is created. This action takes place after interfaceReady event.no
libraryInitializenoEvent fires when the Storm JavaScript Library is initialized.no
playClicknoEvent fires when user clicks any play button.yes
pauseClicknoEvent fires when user clicks the pause button.yes
videoClicknoEvent fires when user clicks the video screen.yes
muteClicknoEvent fires when user mutes the volume.yes
unmuteClicknoEvent fires when volume is unmuted.yes
qualitySwitchClicknoEvent fires when user clicks the quality switch button.yes
sourceChangenoEvent fires when a stream source is changed.yes
fullscreenEnternoEvent fires when user enters fullscreen mode.yes
fullscreenExitnoEvent fires when user exits fullscreen mode.yes
errorMessagenoEvent fires whenever an error message appears.yes
guiShownoEvent fires whenever player interface becomes visible (e.g. user mouse activity).yes
guiHidenoEvent fires whenever player interface becomes invisible (user mouse inactivity).yes
titleUpdatenoEvent fires whenever a stream title is added or updated.yes
subtitleUpdatenoEvent fires whenever a stream subtitle is added or updated.yes
seekStartnoEvent fires whenever a user grabs progress bar thumb (mouse button down).yes
seekEndnoEvent fires whenever a user releases progress bar thumb (mouse button up).yes
seekSetnoEvent fires everytime a user clicks on a progress bar or releases progress bar thumb in a new place.yes
cuePointAddnoEvent fires every time new CUE Point is added.yes
cuePointRemovenoEvent fires whenever an existing CUE Point is removed.yes
resizenewWidth & newHeightEvent fires whenever player size is changedyes

Library Event List (inherited after Storm Library component)

Event nameAdditional dataDescriptionCan be fired more than once
serverConnectionInitiateserverURL:stringThis event is fired when a library instance initiates a connection with a Storm Streaming Server/Cloud instance.yes (once per connection)
serverConnectserverURL:stringThis event is triggered when a library instance successfully establishes a connection with a Storm Streaming Server/Cloud instance.yes (once per connection)
serverDisconnectserverURL:stringThis event is called when a library instance is disconnected from the Storm Streaming Server/Cloud (after a connection was previously established), which may occur due to viewer networking issues or Storm Streaming Server/Cloud problems.yes (once per connection)
serverConnectionErrorserverURL:stringThis event is triggered when a library instance fails to establish a connection with a Storm Streaming Server/Cloud instance, possibly due to networking issues. If there are additional servers on the configuration list and the "restartOnError" parameter is set to true, the library will attempt to connect to a different server instead.yes (once per connection)
allConnectionsFailednoThis event is associated with serverConnectionError. If a library instance is unable to connect to any of the servers provided in the configuration list, this event indicates that no further action can be taken.no
playerCoreReadynoThis event is called when a library instance is prepared to accept API calls (using different methods). No playback-related methods should be invoked on the library before this event is registered.no
compatibilityErrornoThis event is triggered if a browser or device does not support any of the provided sources. Please note that the library will attempt all possible measures (switching between various modes) to ensure maximum compatibility with a given device. However, there may be instances where it is simply impossible to initiate a video.yes
interactionRequirednoCertain browsers and devices do not permit a video element to initiate on its own and necessitate direct user interaction, such as a mouse click or a touch gesture. This event signifies that such an engagement is required.no
SSLErrornoIf an SSL layer is required for specific sources and the browser does not provide it, this event will be triggered.no
videoElementCreateyes (videoObject)This event is triggered whenever a video element within a library instance is either created or recreated.no
streamSourceAddISourceItemThis event is activated whenever a new video source is added to the library (check addSourceItem in the API section).yes
authorizationErrornoThis event is fired when a library instance fails to authorize with a server application on Storm Streaming Server/Cloud instance (e.g. incorrect token)yes
authorizationCompletenoThis event is called when a library instance successfully authorizes with a server application on Storm Streaming Server/Cloud instance.yes
invalidLicensenoWhenever a Storm Streaming Server/Cloud license expires, a library instance will fire this event.no
streamConfigChangeStormStreamConfigThis event notifies that basic stream configuration has been updated.yes

Playback Event List (inherited after Storm Library component)

Event nameAdditional dataDescriptionCan be fired more than once
playbackInitiatenoThis event is fired whenever a playback of a stream is initiated (e.g. either due to autoStart set to true or user interaction).yes (once per video)
playbackStartnoThis event notifies that video playback has started (video is now playing)yes
playbackPausenoThis event notifies that video playback has been paused (due to end-user or system interaction)yes
playbackProgressplaybackStarTime:number, playbackDuration:number, streamStartTime:number, streamDuration:number, dvrCacheSize:numberEvent informs on video progress, stream/playback start-time, stream/playback duration and nDVR cache size.yes
streamStateChangestate: "AWAITING" / "NOT_PUBLISHED" / "UNPUBLISHED" / "PUBLISHED" / "CLOSED" / "UNKNOWN"This event notifies that stream state has changed.yes
streamStopnoEvent will be called when the stream is closed on the server side (usually it means that the broadcaster has stopped streaming, or stream was unpublished).yes
streamNotFoundnoThis event is called whenever a stream with a specific name was not found on the server (this includes hibernated streams or sub-streams).yes (once per video)
metadataReceivedStormMetaDataItemThis event informs of metadata arrival for current video. MetaData contains information about stream codecs, width, height, bitrate etc.yes
bufferingStartnoThis event indicates a video content is being readied for playback. The video buffer must fill in order for the video to start.yes
bufferingCompletenoThis event indicates that the buffer is full and playback is ready to start.yes
volumeChangevolume:number, muted:boolean, invokedBy: user/browserThis event notifies that video volume was changed (either its value was changed, or video was muted/un-muted).yes
playbackErrornoEvent indicates that there was a problem with the playback (it usually means that the browser was not able to play a source material due to malformed bitcode).yes (once per video)
fullScreenEnternoThis event is fired whenever a library instance enters browser fullscreen mode (either native or overlay type)yes
fullScreenExitnoThis event is fired whenever a library instance exits fullscreen mode (either native or overlay type)yes

API

MethodReturnsReturn typeDescription
initialize()-voidStarts the player. This method will be called automatically by the constructor unless wait parameter in the constructor has been set to false.
getInstanceID()Instance ID numbernumberThe method returns instance ID of the player.
getLibrary()StormLibrary ObjectnumberThe method returns main StormLibrary object used by this player.
setSize(width:number/string, height:number/s)-voidThe method sets a new width and height for the player. The values can be given as a number (in which case they are treated as the number of pixels), or as a string ending with "px" (this will also be the number of pixels) or "%", where the number is treated as a percentage of the parent container's value.
setWidth(width:number/string)-voidThe method sets a new width for the player. The value can be given as a number (in which case it is treated as the number of pixels), or as a string ending with "px" (this will also be the number of pixels) or "%", where the number is treated as a percentage of the parent container's value.
setHeight(height:number/string)-voidThe method sets a new height for the player. The value can be given as a number (in which case it is treated as the number of pixels), or as a string ending with "px" (this will also be the number of pixels) or "%", where the number is treated as a percentage of the parent container's value.
getWidth()Player widthnumberReturns player width in pixels.
getHeight()Player heightnumberReturns player height in pixels.
setTitle(title:string)-voidThe method allows to add/change the title displayed in the upper-right corner of the player.
setSubtitle(subtitle:string)-voidThe method allows to add/change the subtitle displayed in the upper-right corner of the player (below the title).
getPlayerConfig()Object containing player settingsObjectThis method returns an object containing all player preferences (related to its GUI).
setPlayerConfig()--This method pushes new player (GUI) config settings
addCuePoint(title:string, time:number)-voidThis method adds a CUE point to the player timeline with a given title.
removeCuePoint(time:number)-voidThis method removes a CUE point based on its time.
addEventListener(eventName:string, callback:function)-voidRegisters an event with the player object. Whenever a registered event occurs, player will call a predefined function provided
removeEventListener(eventName:string, callback:function)-voidRemoves event listener from the player.

Browser compatibility

  • Edge 12+
  • Chrome 31+
  • Firefox 42+
  • Safari 13+
  • Opera 15+

For legacy browsers, HLS mode is used instead.

Resources

4.1.3

23 days ago

4.1.2

29 days ago

4.1.0

1 month ago

4.1.1

1 month ago

4.0.6

1 month ago

4.0.5

2 months ago

4.0.4

2 months ago

4.0.3

2 months ago

4.0.2

3 months ago

4.0.1

3 months ago

4.0.0

3 months ago

4.0.0-rc.1

4 months ago

4.0.0-rc.0

4 months ago

4.0.0-beta.12

5 months ago

4.0.0-beta.11

5 months ago

4.0.0-beta.10

5 months ago

4.0.0-beta.9

5 months ago

4.0.0-beta.8

5 months ago

3.0.0-alpha.7

10 months ago

3.0.0-alpha.6

10 months ago

3.0.0-rc.22

9 months ago

3.0.0-rc.21

9 months ago

3.0.0-alpha.1

10 months ago

3.0.0-alpha.0

10 months ago

3.0.0-alpha.3

10 months ago

3.0.0-alpha.2

10 months ago

3.0.0-alpha.5

10 months ago

3.0.0-alpha.4

10 months ago

4.0.0-alpha.3

6 months ago

4.0.0-alpha.1

6 months ago

4.0.0-alpha.2

6 months ago

4.0.0-alpha.0

6 months ago

3.0.0-beta.1

10 months ago

3.0.0-beta.0

10 months ago

3.0.0-beta.3

10 months ago

3.0.0-beta.2

10 months ago

3.0.0-beta.5

10 months ago

3.0.0-beta.4

10 months ago

3.0.0-beta.7

10 months ago

3.0.0-beta.6

10 months ago

3.0.0-beta.9

9 months ago

3.0.0-beta.8

10 months ago

3.0.0-rc.13

9 months ago

3.0.0-rc.12

9 months ago

3.0.0-rc.15

9 months ago

3.0.0-rc.14

9 months ago

3.0.0-rc.17

9 months ago

3.0.0-rc.16

9 months ago

4.0.0-beta.2

5 months ago

3.0.0-rc.19

9 months ago

4.0.0-beta.1

5 months ago

3.0.0-rc.18

9 months ago

4.0.0-beta.0

5 months ago

3.0.0-rc.2

9 months ago

3.0.0-rc.1

9 months ago

3.0.0-rc.6

9 months ago

3.0.0-rc.5

9 months ago

3.0.0-rc.11

9 months ago

3.0.0-rc.4

9 months ago

3.0.0-rc.10

9 months ago

3.0.0-rc.3

9 months ago

3.0.0-rc.9

9 months ago

3.0.0-rc.8

9 months ago

3.0.0-rc.7

9 months ago

2.2.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.1-beta4

2 years ago

2.1.1-beta3

2 years ago

2.1.1-beta2

2 years ago

2.1.1-beta

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago