The gateway is an additional internal application within the Storm server. It was created for two reasons. The first one is enabling load-balancing functionality (so the gateway decides which server viewer will be connected to) and second - storing stream groups consisting of multiple streams (usually different stream qualities converted by a transcoder).
A gateway should be enabled on all edge servers in a given cluster. All viewers will be creating an initial request to a gateway, and the gateway will provide them with a list of available streaming servers (within such a cluster) along with stream data. For a gateway to work properly, a Cluster must be configured first. Please check Clusters & load-balancing section to learn how to do it.
In the next step, a viewer's player will initiate the right streaming connection accordingly to previously received information from a gateway. You can learn more on how to configure The gateway connection for JavaScript and Android in the following sections:
For a cluster to work, all videos (as separate streams) must be published to an Origin server (or a single Edge server if there is no Origin server within a cluster). Let's assume that we have a single 1080p stream. First, we have to come up with their names e.g.:
Now we need to create a new streamGroup object (JSON). The object is very similar to the sourceList from the Embedded configuration.
streamGroup: [
{streamName: "test_stream_1080p", application: "live", streamInfo: {label:"1080p", width: 1920, height: 1080, fps:30, bitrate: 2500}},
{streamName: "test_stream_720p", application: "live", streamInfo: {label:"720p", width: 1280, height: 720, fps:30, bitrate: 2500}},
{streamName: "test_stream_360p", application: "live", streamInfo: {label:"360p", width: 640, height: 360, fps:30, bitrate: 2500}}
]
Parameter name | Parameter type | Required | Default | Description |
---|---|---|---|---|
application | string | yes | - | The name of an application within a server |
streamName | string | yes | - | The name of a stream. |
host | string | no | - | If the source is hosted on another server (RTMP server for example) you can add its host name. Server then will connect to that host to grab the stream. |
streamInfo | Object | no | - | An object containing stream data like quality label, bitrate and resolution. |
Parameter name | Parameter type | Required | Default | Description |
---|---|---|---|---|
label | string | yes | - | It can be called according to its resolution or quality, e.g., "360", "720p" or something simpler like "high", "medium. |
width | number | no | - | Width (in pixels) of a video stream |
height | number | no | - | Height (in pixels) of a video stream |
fps | number | no | - | Number of frames per second (fps) |
bitrate | number | no | - | Video bitrate in kbps (bits per second). The library will look at this value and treat sources with identical bitrate as backups. |
In order to register a new group within storm server, a POST request containing stream data must be executed. Please make sure to check our REST API section to learn more details on how to configure Storm server for REST API.
Automated request example with PHP:
//The url you wish to send the POST request to
$url = "https://yourdomain.com/rest-api/register-group";
// array containing our stream data
$streamData = [
['streamName' => "test_stream_1080p", 'application' => 'live', 'streamInfo' => ['label' => '1080p', 'width' => 1920, 'height' => 1080, 'fps' => 30, 'bitrate' => 2500]],
['streamName' => "test_stream_720p", 'application' => 'live', 'streamInfo' => ['label' => '720p', 'width' => 1280, 'height' => 720, 'fps' => 30, 'bitrate' => 5000]],
['streamName' => "test_stream_360p", 'application' => 'live', 'streamInfo' => ['label' => '360p', 'width' => 640, 'height' => 360, 'fps' => 30, 'bitrate' => 7000]],
];
//The data you want to send via POST
$fields = [
'command' => "registerStreamGroup",
'groupName' => "test",
'data' => json_encode($streamData);
];
//url-ify the data for the POST
$fields_string = http_build_query($fields);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
echo $result;