Documentation
Cloud_Recording Cloud Recording
Documentation
Demo APP
SDK Center
API Center
FAQ
Code Market
Console
Sign Up
Log In
中文站 English
  • Documentation
  • Cloud Recording
  • API Documents
  • Recording End Callback

Callback of the recording status

Last updated:2025-04-07 16:03

Callback services cannot guarantee complete reliability. Please carefully consider the risks of using callback solutions to build core business processes.

Description

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.

Callback parameters

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.
  • 1: The upload status of a recording file changes. For details, see the detail parameter.
  • 2: A recording task ends abnormally. For details, see the detail parameter.
  • 3: The customized background or watermark image failed to be downloaded. For details, see the detail parameter.
  • 4: The number of streams in the room where recording is performed is zero.
    This event will be triggered within 30 seconds after the number of streams in the room becomes zero. After the first-time event trigger, if the room remains in the no-stream state, this event will be triggered once again every 30 seconds until a stream is detected or the task times out.
  • 5: The recording is completed.
  • 6: The stream to be recorded does not exist. For details, see the detail parameter.
  • 7: Uploading recorded file.
  • 102: When uploading video segments in real-time, notify the M3U8 file address.
  • 201: Recording paused successfully.
  • 202: Recording resumed successfully.
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.
  • Listed below are detail member parameters when event_type is 1.
Parameter Type Description
upload_status int Overall upload status of recording files.
  • 1: All files are uploaded successfully.
  • 2: Some files are uploaded successfully. That is, at the value of status of at least one file in the file information list is not 3.
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.
  • 1: audio only
  • 2: video only
  • 3: audio and video
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.
  • 1: being recorded
  • 2: being uploaded to the specified cloud storage platform
  • 3: successfully uploaded to the specified cloud storage platform
  • 4: failed to be uploaded to the specified cloud storage platform but successfully uploaded to ZEGOCLOUD's backup cloud storage platform
  • 5: failed to be uploaded either to the specified cloud storage platform or ZEGOCLOUD's backup cloud storage platform
  • Listed below are detail member parameters when event_type is 2.
Parameter Type Description
quit_reason int Reason why the recording service exits abnormally.
  • 1: Failed to start the recording service. In this case, initiate a recording request again.
  • 2: Failed to log in to the specified room. In this case, check the room and ensure that it can be logged in.
  • 3: The recording task automatically ends because the duration with no stream or whiteboard in the room exceeds the maximum specified by MaxIdleTime (which is 30 seconds by default) in Start recording.
  • 4: The recording task automatically ends because the recording duration reaches the maximum specified by MaxRecordTime (which is 24 hours by default) in Start recording.
  • 5: Failed to start the recording engine. In this case, initiate a record request again.
  • 6: The recording service is disconnected. In this case, initiate a record request again.
  • 1001: Unknown recording error. In this case, initiate a record request again.
  • 1002: The recording file name is too long. For details, see OutputFileRule.
  • 1003: Failed to open the recording file. In this case, initiate a record request again.
  • 1004: The storage space available to the recording service is insufficient. In this case, initiate a record request again.
  • 1005: Failed to initiate the recording engine. In this case, initiate a record request again.
  • 1006: Failed to write the file header during the recording. In this case, initiate a record request again.
  • 1007: Error EBADF occurred during recording file writing. In this case, initiate a record request again.
  • 1008: Error EIO occurred during recording file writing. In this case, initiate a record request again.
  • 1009: An internal channel error occurred during the recording. In this case, initiate a record request again.
  • 1010: The recording file format is not supported. For details, see OutputFileFormat.
  • 1011: Illegal recording status. In this case, initiate a record request again.
  • Listed below are 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.
  • 1: video canvas background image, which is specified by MixOutputBackgroundImage
  • 2: watermark image, which is specified by MixOutputWatermarkImage
  • 3: default background image of the streaming screen, which is specified by DefaultMixStreamBackgroundImage
  • 4: background image of the stream screen on a customized layout, which is specified by BackgroundImage.
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.
  • Listed below are 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.
  • 1: Only audio.
  • 2: Only video.
  • 3:Audio and video.
  • The 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.

Sample request

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

Source verification

Checks whether a callback request is initiated from the Cloud Recording service.

Verification method

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 request
  • timestamp: parameter in the callback request
  • callbacksecret: generated during project registration on the ZEGOCLOUD Admin Console.

Sample code

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);

Sample response

$timestamp = 1470820198;
$nonce = 123412;
$secret = 'secret';

Original string requiring encryption after ranking splice:1234121470820198secret
The result of encryption will be:5bd59fd62953a8059fb7eaba95720f66d19e4517

Return code

HTTP status code 2XX (such as 200) indicates success and all other return codes indicate failure.

Page Directory
  • Free trial
  • 提交工单
    咨询集成、功能及报价等问题
    电话咨询
    400 1006 604
    Get Consulting
    Scan Wechat QR code