API Methods - Storm JavaScript Library

Method nameReturnsReturn typeDescription
initialize()-voidActivates all scripts within a library instance. All event-listeners should be already attached to the library at this point.
isInitialized()true if this library instance was already initialized.booleanReturns true if this library instance has already been initialized.
isConnected()true if this library instance is connected with a server.booleanReturns true if this library instance is connected to a server. .
isAuthorized()true if this library instance is authorized with a server.booleanReturns true if this library instance is authorized with a server. .
getLibraryID()Library ID (first instance starts with 0, next one gets 1, etc.)numberThis method returns the instance ID of the library.
getVersion()Library version in xx.xx.xx format.stringThis method returns library version.
play()-voidThis method will initiate playback of a video stream. If a video was previously paused, you can use this method to resume playback. For this method to work, the library must be subscribed to a stream (check the streamKey field in the config and/or the subscribe method)
pause()-voidThis method pauses current playback.
stop()-voidThis method will stop the current playback and cease all operations. It'll also disconnect library from a server. To restore connection, use subscribe() method.
togglePlay()-voidThis method will work as a pause/play switch depending on the current object state.
isPlaying()true if playback is active.booleanReturns true/false depending on current library state. Please check “getPlaybackState()” for more detailed information.
getPlaybackState()"NOT_INITIALIZED", "INITIALIZED", "PLAYING", "PAUSED", "BUFFERING", "STOPPED", "UNKNOWN"stringReturns current library state.
getStreamState()"AWAITING", "NOT_PUBLISHED", "UNPUBLISHED", "PUBLISHED", "CLOSED", "UNKNOWN"stringReturns current stream state.
seek(time: number)-voidSeeks stream to a given time (stream source timestamp).
mute()-voidMutes the library’s video object. It’s not the same as setVolume(0), as both methods can be applied together.
unmute()-voidThe method unmutes the library’s video object.
toggleMute()-voidSwitches mute on/off.
isMute()true if the library is muted.booleanThis method can be used to check whether the library is muted.
setVolume(newVolume: number)-voidSets new volume for the library (0-100). Once the method is performed volumeChange event will be triggered.
getVolume()Current volume level 0-100numberReturns library volume (0-100).
setSize(width: number | string, height: number | string)-voidThe method sets a new width and height for the video element. 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 video element. 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()Video Object widthnumberReturns main Video Object width in pixels.
setHeight(height: number | string)-voidThe method sets a new height for the video element. 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.
getHeight()Video Object heightnumberReturns main Video Object height in pixels.
updateToSize()-voidThis method forces the library to recalculate its size based on parent internal dimensions.
setScalingMode(newMode: string)-voidChanges library scaling mode. For reference, please check scaling mode in the library config.
getScalingMode()Current scaling modestringReturns current library scaling mode. For reference, please check scaling mode in the library config.
setStreamConfig(config: StormStreamConfig)-voidSets stream config for the library (or overwrites an existing one).
getStreamConfig()Storm Streaming Configuration objectStormStreamingConfigReturns current config for the library.
destroy()-voidDestroys the library instance and removes it from the container.
addEventListener(eventName: string, callback: function, removable: boolean = true)-voidRegisters an event with a library instance. Whenever a registered event occurs, the library will call a provided function.
removeEventListener(eventName: string, callback: function)-voidRemoves event listener from the library. If callback is not provided all events of that type will be removed.
removeAllEventListeners()-voidRemoves all removable event listener from the library.
getSourceList()Array containing available sources.ISourceItem[]Returns an array of all available source items.
removeAllSources()-voidRemoves all SourceItems from a library instance. This method however will not stop current playback.
playSource(sourceItem: ISourceItem)-voidThis method will start a playback of a provided Stream Source Item.
getCurrentSourceItem()ISourceItem object or null.ISourceItem | nullReturns current source item. If no source was selected yet, null might be returned instead.
addSourceItem(sourceItem: SourceItem, addAndPlay: boolean)-voidAdd new stream object to the library. It can also start playing it automatically.
attachToContainer(container:ID | HTMLElement)true if attaching was successful.booleanAttaches the library to a new parent container using either a container ID (string) or a reference to an HTMLElement. If the instance is already attached it'll be moved to a new parent.
detachFromContainer()true if attaching was successful.booleanDetaches the library from the current parent element, if possible.
getContainer()Parent HTMLElement or null .HTMLElement | nullReturns the current parent element of the library, or null if none exists.
enterFullScreen()-voidEnters the FullScreen mode.
exitFullScreen()-voidExits the FullScreen mode.
isFullScreenMode()true if the library is in FullScreen mode.voidReturns true/false whenever a library instance is in the FullScreen mode.
getAbsoluteStreamTime()UnixtimenumberReturns current playback time.
getVideoElement()Reference to the main Video Element.HTMLVideoElementReturns Video Element used by this library instance.
Table 1. API methods table.
Support Needed?

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

On this page

API Methods