Enhance HTTP Streaming, HTTP Callback, HTTP API for HTTP-FLV, HTTPS, HLS etc.
winlinvip opened this issue · comments
SRS supports several applications over HTTP.
- HTTP-API: Listens on port 1985 and provides API services.
Issue: No support for authentication. Authentication is required before proxying to HTTP-API. Callback authentication can also be supported. #1640
Issue: No support for HTTPS. Nginx support for HTTPS is required to proxy to SRS. It would be more convenient if SRS supports HTTPS. #1533 - HTTP-FLV: Listens on port 8080 and provides FLV streaming services.
Issue: No support for HTTPS. Nginx support for HTTPS is required to proxy to SRS. It would be more convenient if SRS supports HTTPS. #1533
- HLS: Listens on port 8080 or shares slices with Nginx to provide HLS streaming services.
Issue: No statistics for HLS clients, unlike RTMP/FLV. It would be more convenient if SRS supports this. #1655
Issue: No authentication for HLS, unlike RTMP/FLV. It would be more convenient if SRS supports this. #1487
Issue: No support for HTTPS. Nginx support for HTTPS is required to proxy to SRS. It would be more convenient if SRS supports HTTPS. #1533 - Using Nginx or Caddy as a proxy to provide unified HTTP/HTTPS services. Refer to #2881.
If SRS4 or SRS5 enhance the capabilities of HTTP streaming services, it would be more convenient to use and provide stronger consistency.
TRANS_BY_GPT3
There is a work-around:
Use nginx or go-oryx/httpx-static to convert HTTP to HTTPS, or HTTPS Live Streaming and HTTPS-FLV in practice.
Whatever, SRS will support HTTPS client and server inside.
TRANS_BY_GPT3
HTTPS Client protocol:
HTTP callback support HTTPS server, for example, conf/https.hooks.callback.conf:
vhost __defaultVhost__ {
http_hooks {
enabled on;
on_connect https://127.0.0.1:443/api/v1/clients;
}
}
The log of SRS, for https-client:
[2020-11-03 15:47:58.645][Trace][4715][h6r1ehdh] RTMP client ip=127.0.0.1:61658, fd=10
[2020-11-03 15:52:35.021][Trace][5547][2m457139] https: connected to https://127.0.0.1:443, cost=6ms
[2020-11-03 15:47:58.658][Trace][4715][h6r1ehdh] http: on_connect ok, client_id=h6r1ehdh,
url=https://127.0.0.1:443/api/v1/clients, request={"action":"on_connect",
"client_id":"h6r1ehdh","ip":"127.0.0.1","vhost":"__defaultVhost__","app":"live",
"tcUrl":"rtmp://127.0.0.1:1935/live","pageUrl":""},
response={"code": 0, "data": null}
Note: The wireshark capture file for HTTPS client: https-client.pcapng.zip
Note: Refer to OpenSSL example using memory BIO with non-blocking socket IO.
HTTPS API server protocol:
- Wiki: SRS Supports HTTPS API.
Config for HTTPS API, for example, conf/https.rtc.conf:
http_api {
enabled on;
listen 1985;
# For https_api or HTTPS API.
https {
# Whether enable HTTPS API.
# default: off
enabled on;
# The listen endpoint for HTTPS API.
# default: 1990
listen 1990;
# The SSL private key file, generated by:
# openssl genrsa -out server.key 2048
# default: ./conf/server.key
key ./conf/server.key;
# The SSL public cert file, generated by:
# openssl req -new -x509 -key server.key -out server.crt -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net"
# default: ./conf/server.crt
cert ./conf/server.crt;
}
}
Open in Chrome:
The SRS logs:
[2020-11-06 17:14:10.700][Trace][21509][551p56t8] https: api server done, use key
./conf/server.key and cert ./conf/server.crt, cost=5ms
[2020-11-06 17:14:10.700][Trace][21509][551p56t8] HTTP #0 127.0.0.1:62381 GET
https://127.0.0.1:1990/api/v1/versions, content-length=-1
# For self-sign certificate, there is always a error:
[2020-11-06 17:17:35.939][Error][21509][551p56t8][0] serve error code=4042 : start : handshake : handshake r0=-1, r1=1
thread [21509][551p56t8]: do_cycle() [src/app/srs_app_http_conn.cpp:170][errno=0]
thread [21509][551p56t8]: on_start() [src/app/srs_app_http_api.cpp:1710][errno=0]
thread [21509][551p56t8]: handshake() [src/app/srs_app_conn.cpp:624][errno=0]
Note: Capture files https-server-port-1443.pcapng.zip, https-server.pcapng.zip
Note: Refer to OpenSSL example using memory BIO with non-blocking socket IO.
Use Nginx or Caddy as a proxy to provide unified HTTP/HTTPS services, refer to #2881.
HTTPS Stream server protocol:
- Wiki: SRS Supports HTTPS FLV.
Config for HTTPS Streaming Server, for example, conf/https.flv.live.conf or conf/https.hls.conf:
http_server {
enabled on;
listen 1985;
# For https_api or HTTPS API.
https {
# Whether enable HTTPS API.
# default: off
enabled on;
# The listen endpoint for HTTPS API.
# default: 1986
listen 1986;
# The SSL private key file, generated by:
# openssl genrsa -out server.key 2048
# default: ./conf/server.key
key ./conf/server.key;
# The SSL public cert file, generated by:
# openssl req -new -x509 -key server.key -out server.crt -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net"
# default: ./conf/server.crt
cert ./conf/server.crt;
}
}
Open in Chrome:
The SRS logs:
[2020-11-06 17:15:39.794][Trace][21509][9hyiw0e6] https: stream server done, use key
./conf/server.key and cert ./conf/server.crt, cost=5ms
[2020-11-06 17:15:39.794][Trace][21509][9hyiw0e6] HTTP #0 127.0.0.1:62821 GET
https://ossrs.net:8088/live/livestream.flv, content-length=-1
# For self-sign certificate, there is always an error:
[2020-11-06 17:15:39.788][Error][21509][9hyiw0e6][0] serve error code=4042 : start : handshake : handshake r0=-1, r1=1
thread [21509][9hyiw0e6]: do_cycle() [src/app/srs_app_http_conn.cpp:170][errno=0]
thread [21509][9hyiw0e6]: on_start() [src/app/srs_app_http_conn.cpp:380][errno=0]
thread [21509][9hyiw0e6]: handshake() [src/app/srs_app_conn.cpp:624][errno=0]
TRANS_BY_GPT3
It is worth doing well and mastering the basics of HTTP.
TRANS_BY_GPT3
All HTTP-API related issues should be consolidated and updated in this issue. Please ensure that the markdown structure is maintained.
- HTTP API does not count the number of WebRTC distributed streams (i.e., the number of clients) - Issue #2290
- Abnormal result of HTTP interface in SRS 4.0 version - Issue #2231
- How to obtain WebRTC client information when streaming with SRS RTMP and watching with WebRTC - only able to obtain streaming information in the console - Issue #2149
- HTTP API in version 2.0.243 does not count HLS clients - Issue #996
- APPLICATION: When using HTTP-FLV playback, traffic statistics are incorrect when using SRS HTTP API, although the client connection count is correct - Issue #863
Please ensure that the markdown structure is maintained.
TRANS_BY_GPT3
Looking forward to SRS4 supporting HLS client statistics and HLS on_play/on_stop callbacks.
TRANS_BY_GPT3
Fixed in SRS 4