If you configure callbacks for the real-time stream status, you can receive callback notifications about successful or interrupted stream ingests.
How it works
ApsaraVideo Live sends an HTTP GET request to your server to notify you of the successful stream ingest or stream interruption in real time. The server then responds with the HTTP status code 200, which indicates that the callback is successful.
A callback URL requires no identifier but must be accessible. The URL response complies with the following requirements:
If no response is returned from the URL in a specific period, ApsaraVideo Live retries to access the URL. If no response is returned in 5 seconds, ApsaraVideo Live retries to access the URL for a maximum of five times at intervals of 1 second.
Callback logic for live stream ingest status
Note We recommend that you deliver the streaming URL only after you determine that the stream ingest or pulling is successful based on callback notifications and the list of online streams.
- During stream ingest over Real-Time Messaging Protocol (RTMP), ApsaraVideo Live checks whether the stream ingest client closes the connection within 2 seconds after ApsaraVideo Live receives an OnPublish message. If the stream ingest client does not close the connection, ApsaraVideo Live sends a callback notification about the successful stream ingest. You may require ApsaraVideo Live to send this callback notification only when ApsaraVideo Live receives live streaming data after the connection is established. In this case, submit a ticket.
- For example, you have Ingest Domain A and Streaming Domain B, and you use the stream pulling feature for live streaming under Streaming Domain B. You can configure ApsaraVideo Live to pull a stream at the specified point in time, or enable ApsaraVideo Live to automatically pull a stream when the origin server starts live streaming. If you want to receive a callback notification about the stream pulling status, configure stream ingest callbacks for Ingest Domain A. After the configuration, ApsaraVideo Live uses the same callback logic as that for stream ingest status to send callback notifications about the stream pulling status under Streaming Domain B. By default, ApsaraVideo Live sends a callback notification about successful stream pulling if the stream pulling client does not close the connection within 2 seconds after the connection is established. If you require ApsaraVideo Live to send this callback notification only when live streaming data is received, submit a ticket.
- Callback authentication logic
The callback authentication is disabled by default. You can enable it while configuring the callback URL. The authentication logic is as follows:
- ApsaraVideo Live includes the
ALI-LIVE-SIGNATUREfields in the HTTP(S) request header when sending callback information to the callback URL. The value of
ALI-LIVE-SIGNATUREis calculated using the following formula:
MD5CONTENT=Stream pushing domain name|Value of ALI-LIVE-TIMESTAMP|Cryptographic keyNote The Stream pushing domain name refers to the domain to which the callback URL is configured. The Cryptographic key refers to the authentication key for the callback URL.
- The server that hosts the callback URL generates an MD5 hash from a concatenated string
of the stream pushing domain name, the value of
ALI-LIVE-TIMESTAMP, and the cryptographic key. It then compares the MD5 hash with the value of
ALI-LIVE-SIGNATUREin the HTTP(S) request header. If the MD5 hash is not consistent with the value of
ALI-LIVE-SIGNATURE, the request is considered invalid.
- ApsaraVideo Live includes the
The following table describes the parameters in the sample callback URL:
|time||String||The UNIX timestamp. Unit: seconds.|
|usrargs||String||The custom parameters that are used to ingest the stream.|
|action||String||The operation that you want to perform. A value of publish indicates stream ingest. A value of publish_done indicates stream interruption.|
|app||String||The domain name. The default value is a custom ingest domain. If no ingest domain is bound, a streaming domain is used.|
|appname||String||The name of the application.|
|id||String||The name of the live stream.|
|ip||String||The IP address of the client that ingests the stream.|
|node||String||The name of the Alibaba Cloud CDN node or the host that receives the stream.|
|height||String||The height of the resolution. Unit: pixel.
Note The height and width of the resolution are returned only when the callback is invoked for the first time.
|width||String||The width of the resolution. Unit: pixel.|