...
Code Block | ||
---|---|---|
| ||
location ~* ^.+.(ts)$ { proxy_pass https://localhost:8445; proxy_http_version 1.1; proxy_set_header Host $server_name:$server_port; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_cache proxy_cache; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 2m; } location ~* ^.+.(m3u8)$ { proxy_pass https://localhost:8445; proxy_http_version 1.1; proxy_set_header Host $server_name:$server_port; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_cache off; expires -1; } |
Returning of static HTML pages on HLS port
Another way to workaround cross domain requests restrictions in browser is to return a static content, player page for example, on the same port that returns HLS content. To enable this feature, the following parameter should be set in flashphoner.properties file
Code Block | ||
---|---|---|
| ||
hls_static_enabled=true |
...
Passing a custom parameters when requesting a playlist
A custom parameters should be passed when requesting a playlist if reverse proxy authentication is set up:
Code Block | ||
---|---|---|
| ||
hls_static_dir=client2/examples/demo/streaming/hls_static |
...
https://wcs:8445/test/test.m3u8?key1=value1&key2=value2 |
The feature is supported since build 5.2.1959. The parameters passed will be returned in every playlist for every segment, this allows to authorize a viewer correctly on proxy server.
There will be an additional parameter sessionId
in playlists, for example
Code Block | ||
---|---|---|
| ||
hlsav_statictest_dir=/var/www/html/hls_static |
If static content returning is enabled, browser will display the HLS player page by URL https://host:8445/hls-player.html. If this feature is disabled, server will return 404 Not found error by such URL.
Preloader for HLS stream playback
...
o/av_test_o.m3u8?sessionId=11&key1=value1&key2=value2 |
This is the internal WCS parameter to identify the subscriber for statistical purposes.
Returning of static HTML pages on HLS port
Another way to workaround cross domain requests restrictions in browser is to return a static content, player page for example, on the same port that returns HLS content. To enable this feature, the following parameter should be set in flashphoner.properties file
Code Block | ||
---|---|---|
| ||
hls_static_enabled=true |
The player page should be in directory defined by the following parameter
Code Block | ||
---|---|---|
| ||
hls_static_dir=client2/examples/demo/streaming/hls_static |
In this case (by default) the path to the player page files is set relative to WCS installation directory. A full path may also be set, for example
Code Block | ||
---|---|---|
| ||
hls_static_dir=/var/www/html/hls_static |
If static content returning is enabled, browser will display the HLS player page by URL https://host:8445/hls-player.html. If this feature is disabled, server will return 404 Not found error by such URL.
Preloader for HLS stream playback
When first HLS subscribes connects to a stream on WCS server, especilally to CDN stream, it may take a time to split a stream to HLS segmets and to form a playlist. As a result, Safari browser on iOS devices may not be able to play HLS stream on the first attempt. To successfully play HLS stream in this case, the HLS preloader was added since build 5.2.371. The default preloader looks like this:
...
REST query | Body example | Response example | Response state | Desctiption | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
/hls/startup |
| 200 - OK 404 - Stream not found 500 - Internal error | Start HLS agent for the stream | |||||||||||||||
/hls/find_all |
|
| 200 – OK 404 – Not found | Find all streams having HLS agents | ||||||||||||||
/hls/terminate |
| 200 – OK 404 – Not found | Stop or restart HLS agent for the stream | |||||||||||||||
/hls/profiles |
|
| 200 – OK 400 – Bad request 404 – Not found | Get HLS profile statistics | ||||||||||||||
/hls/subscribers |
|
| 200 – OK 400 – Bad request 404 – Not found | Get HLS subscribers statistics | ||||||||||||||
/hls/enableRecordingconnections |
|
| 200 – OK 400 – Bad request 404 – Not found 500 - Internal server error | Get a list of HLS clients connected to the server | ||||||||||||||
/hls/enableRecording |
| 200 – OK 400 – Bad request 404 – Not found 409 - Conflict 500 - Internal server error | Enable HLS stream debug segments recording | |||||||||||||||
/hls/disableRecording |
| 200 – OK 400 – Bad request 404 – Not found | Disable HLS stream debug segments recording |
...
In the response to the /hls/find_all
, /hls/profiles
, /hls/subscribers
queries a current HLS subscribers count and information are returned as per browser tabs. But HLS network connections count displaying at WCS statistics pagenetwork connections count displaying at WCS statistics page
Code Block | ||||
---|---|---|---|---|
| ||||
curl -s http://localhost:8081/?action=stat¶ms=connections_hls |
may differ from HLS subscribers count. In the most cases, HLS subscribers use HTTP 2 protocol to connect and download a segments, then all the browser tabs receiving HLS streams from the same WCS server will use the same network connection.
In this case connections count displayed by connections_hls
parameter is usually equal to HLS port connections count displayed by netstat
command:
Code Block | ||||
---|---|---|---|---|
| ||||
sudo netstat -np | grep ESTABLISHED | grep java | grep 8445 |
Where 8445 is HTTPS HLS port of WCS server
Displaying a list of HLS clients connected to the server
Since build 5.2.1968 it is possible to display a list of HLS clients connected to the server. The list is returned in response to the /hls/connections
query:
Code Block | ||||
---|---|---|---|---|
| ||||
[
{
"ip": "192.168.0.83",
"port": 51708,
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
}
] |
Where:
- ip - client address
- port - client source port
- userAgent -
User-Agent
header sent by the client
For HTTPS clients all the tabs of the same browser window on the same PC will be displayed at one position because HTTP/2 uses the same TCP connection for all HTTPS connections.
A clients count in the list will be the same as the statistics page value
Code Block | ||||
---|---|---|---|---|
| ||||
curl -s 'http://localhostwcs:8081/?action=stat¶ms=connections_hls |
may differ from HLS subscribers count. In the most cases, HLS subscribers use HTTP 2 protocol to connect and download a segments, then all the browser tabs receiving HLS streams from the same WCS server will use the same network connection.
In this case connections count displayed by connections_hls
parameter is usually equal to HLS port connections count displayed by netstat
command:
Code Block | ||||
---|---|---|---|---|
| ||||
sudo netstat -np | grep ESTABLISHED | grep java | grep 8445 |
...
' |
HLS stream segments recording to disk for debugging purposes
...