Callback services cannot guarantee complete reliability. Please carefully consider the risks of using callback solutions to build core business processes.
To receive a task status event immediately upon a status change, you need to provide a callback URL when enabling the Cloud Recording service.
During recording, an HTTP request will be initiated to the callback URL using the POST method and the request message body is in JSON format.
Parameter | Type | Description |
---|---|---|
app_id | Int64 | Unique AppID assigned by ZEGOCLOUD. |
task_id | String | Task ID. The value is a 16-byte character string. |
room_id | String | Room ID. |
event_type | Int | Event type.
|
message | String | Event description. |
nonce | String | Random number, which is used to generate a signature. |
timestamp | String | Unix timestamp when a callback is triggered, which is used to generate a signature. |
signature | String | Signature used to verify the identity of the callback sender. |
sequence | Int | Message sequence number, which starts from 0. |
detail | JSON Object | Detailed event information. The member parameters vary depending on the value of event_type . |
detail
member parameters when event_type
is 1
.Parameter | Type | Description |
---|---|---|
upload_status | int | Overall upload status of recording files.
|
file_info | Array of Object | File information list. An empty list indicates that no recording file has been generated (no streaming in the room). |
Listed below are file_info
member parameters.
Parameter | Type | Description |
---|---|---|
user_id | String | ID of the user who initiates streaming. In mixed-stream recording mode, the value is the same as that of mix_output_stream_id . |
user_name | String | Nickname of the user who initiates streaming. In mixed-stream recording mode, the value is the same as that of MixOutputStreamId . |
stream_id | String | ID of the recorded stream. In mixed-stream recording mode, the value is the same as that of MixOutputStreamId . |
file_id | String | File name. For details, see the OutputFileRule parameter in Start recording. |
video_id | String | Video ID received after a recording file is successfully uploaded to Alibaba Cloud VOD or Tencent Cloud VOD platform. For Alibaba Cloud VOD, the value maps VideoId . For Tencent Cloud VOD, the value maps FileId . |
file_url | String | File access URL. This parameter is not returned when the third-party cloud storage platform of Qiniu Cloud or Alibaba Cloud VOD is used. |
output_file_format | String | Format of the output recording file. The options are mp4 , flv , hls , jpg , and aac . |
file_size | Int64 | File size, in bytes. |
duration | Int | Recording duration, in ms. |
resolution_width | Int | Resolution width of a video, in pixels. |
resolution_height | Int | Resolution height of a video, in pixels. |
media_track_type | Int | Media type of a recording file.
|
begin_timestamp | Int64 | Unix timestamp when a new stream signal is received in a room, in ms. |
custom_begin_timestamp | Int64 | Customized timestamp. This timestamp is carried in the stream SEI information, and is extracted from SEI through the specified protocol. |
status | Int | File status.
|
detail
member parameters when event_type
is 2
.Parameter | Type | Description |
---|---|---|
quit_reason | int | Reason why the recording service exits abnormally.
|
detail
member parameters when event_type
is 3
.Parameter | Type | Description |
---|---|---|
image_type | int | Type of the image that failed to be downloaded. The value maps the image type set in Start recording.
|
image_url | String | URL of the image that failed to be downloaded. |
The detail
parameter is left empty when event_type
is 4
or 5
.
Listed below is the detail
member parameter when event_type
is 6
.
Parameter | Type | Description |
---|---|---|
stream_id | String | Stream ID. |
detail
member parameters when event_type
is 102
.Parameter | Type | Description |
---|---|---|
stream_id | String | Strem ID. |
file_id | String | File name. |
file_url | String | File URL。 |
media_track_type | Int | Media type.
|
detail
parameter is left empty when event_type
is 201
or 202
.ZEGOCLOUD will update parameters (for example, add parameters or values) in the recording status callback method in future iterations. Therefore, avoid performing hard coding upon integration. Otherwise, incompatibility may occur after a version iteration.
The following is a request example of the recording status callback method:
{
"app_id": 1234567890,
"detail": {
"file_info": [
{
"begin_timestamp": 1637753762084,
"duration": 170039,
"file_id": "YZ4joOE4IwmFAAAT_6677_800221_800221_VA_20211124113602084.mp4",
"file_size": 25349026,
"file_url": “file_url”,
"media_track_type": 3,
"output_file_format": "mp4",
"resolution_height": 720,
"resolution_width": 1280,
"status": 3,
"stream_id": "800221",
"user_id": "800221",
"user_name": "play_800221",
"video_id": ""
}
],
"upload_status": 1
},
"event_type": 1,
"message": "",
"nonce": "100480",
"room_id": "6677",
"sequence": 1,
"signature": "12345678987654321",
"task_id": "YZ4joOE4IwmFAAAT",
"timestamp": "1637753949"
}
Checks whether a callback request is initiated from the Cloud Recording service.
Check whether the calculated signature is the same as that carried in the callback request. The following figure shows how to calculate a signature.
nonce
: parameter in the callback requesttimestamp
: parameter in the callback requestcallbacksecret
: generated during project registration on the ZEGOCLOUD Admin Console. Sample code in PHP:
$signature = $_POST["signature"];
$timestamp = $_POST["timestamp"];
$nonce = $_POST["nonce"];
$secret = callbacksecret;// Callback secret obtained in the background.
$tmpArr = array($secret, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
} else {
return false;
}
Sample code in Java:
// Obtain the values of signature, timestamp, and nonce from the request.
String signature = request.getParameter("signature");
long timestamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
// Back end obtains callbacksecret
String secret = callbacksecret;
String[] tempArr = {secret, ""+timestamp, nonce};
Arrays.sort(tempArr);
String tmpStr = "";
for (int i = 0; i < tempArr.length; i++) {
tmpStr += tempArr[i];
}
tmpStr = org.apache.commons.codec.digest.DigestUtils.sha1Hex(tmpStr);
return tmpStr.equals(signature);
$timestamp = 1470820198;
$nonce = 123412;
$secret = 'secret';
Original string requiring encryption after ranking splice:1234121470820198secret
The result of encryption will be:5bd59fd62953a8059fb7eaba95720f66d19e4517
HTTP status code 2XX (such as 200) indicates success and all other return codes indicate failure.