Gateway server - Storm Server

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:

  1. Storm JavaScript Library - Gateway configuration
  2. Storm Android Library - Basic explanation
  3. Storm iOS Library - Basic explanation

Preparing streams

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.:

  1. Original stream: test_stream_1080p
  2. Stream transcoded to 1280x720 resolution: test_stream_720p
  3. Stream transcoded to 640x360 resolution: test_stream_360p

JSON Group object

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}}
]
                        

JSON Group parameters

Parameter nameParameter typeRequiredDefaultDescription
applicationstringyes-The name of an application within a server
streamNamestringyes-The name of a stream.
hoststringno-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.
streamInfoObjectno-An object containing stream data like quality label, bitrate and resolution.
Table 1. JSON group parameters

streamInfo parameter

Parameter nameParameter typeRequiredDefaultDescription
labelstringyes-It can be called according to its resolution or quality, e.g., "360", "720p" or something simpler like "high", "medium.
widthnumberno-Width (in pixels) of a video stream
heightnumberno-Height (in pixels) of a video stream
fpsnumberno-Number of frames per second (fps)
bitratenumberno-Video bitrate in kbps (bits per second). The library will look at this value and treat sources with identical bitrate as backups.
Table 2. streamInfo

Registering streamGroup with a Strom server

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;