Subscribing to a Stream - Storm JS Player Core
One of the core and most important features of the Storm JS Player Core is the ability to dynamically subscribe to any stream based on a provided streamKey. Once the player is subscribed to a given stream, it will start receiving notifications about its state changes or updates (e.g., the stream has been published or, conversely, has ended).
Subscribing to a Stream
There are two ways to subscribe to a stream. For example, we can configure the player by immediately providing the streamKey we're interested in:
const streamConfig = {
stream: {
serverList: [{
host: "yourdomain.com",
application: "live",
port: 443,
ssl: true
}],
streamKey: "test", // our streamKey goes here
},
settings: {
video: {
containerID: "videoHolder",
aspectRatio: "16:9",
width: "100%",
},
}
}
const storm = stormPlayerCore(streamConfig);
However, we can also omit the streamKey field and call the appropriate method instead:
const storm = stormPlayerCore(streamConfig);
storm.initialize();
storm.subscribe("test");
Once the player has been initialized via the initialize() method, we can freely switch between streams by calling this method again with a new key.
Unsubscribing from a Stream
Once subscribed, the player will continuously receive notifications about stream state changes. If we want the player object to stop monitoring a specific streamKey, we need to unsubscribe from it:
storm.unsubscribe();
If you have any questions or need assistance, please create a support ticket and our team will help you.