The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.
The event callback service supports notifying your server of events under the TRTC business in the form of HTTP/HTTPS requests. The event callback service has integrated the Room Event Group and the Media Event Group. You can provide tencent cloud with related configuration information to enable this service.
Configuration Information
Tencent Real-Time Communication (TRTC) Console supports self-service configuration of callback information. After the configuration is complete, event callback notifications can be received. For detailed operation guide, please refer to Callback Configuration.
Note:
You need to prepare the following information in advance.
Required item: The HTTP/HTTPS server address for receiving callback notifications.
Optional: The key for calculated signature. Customize a key with a maximum of 32 characters, consisting of uppercase and lowercase letters and numbers.
Timeout Retry
If the event callback server does not receive a response from your server within 5 seconds after sending a message notification, the notification is considered failed. After the first notification failure, it will retry immediately. Subsequent failures will continue to retry at intervals of 10 seconds until the message retention time exceeds 1 minute, after which no further retries will be made.
Event Callback Message Format
Event callback messages are sent to your server via an HTTP/HTTPS POST request, where:
Character Encoding Format: UTF-8.
Request: The body format is JSON.
Response: HTTP STATUS CODE = 200, the server ignores the specific content of the response packet. For protocol friendliness, it is recommended that customers include JSON in the response content: {"code":0}.
Note:
Your HTTP response packet length (header + body) needs to be controlled within 2000 bytes.
The JSON body of a POST request will not delete existing fields, but will add new fields based on business needs. When integrating callbacks, you need to adapt to these additional fields situation.
Parameter Description
Callback Message Parameters
The header of the event callback message contains the following fields:
Field Name
Value
Content-Type
application/json
Sign
Signature value
SdkAppId
sdk application id
The body of the event callback message contains the following fields:
Exiting a room will only trigger the 104 event, not the 202 and 204 events. The 104 event essentially encompasses the 202 and 204 events. Manually turning off video/audio will trigger the 202/204 events.
Event Callback Example
101
102
103
104
105
201
202
203
204
205
206
{"EventGroupId":1,
"EventType":101,
"CallbackTs":1687770730166,
"EventInfo":{
"RoomId":12345,
"EventTs":1687770730,
"EventMsTs":1687770730160,
"UserId":"test"
}
}
{
"EventGroupId":1,
"EventType":102,
"CallbackTs":1687771618531,
"EventInfo":{
"RoomId":"12345",
"EventTs":1687771618,
"EventMsTs":1687771618457
}
}
{
"EventGroupId":1,
"EventType":103,
"CallbackTs":1687770731932,
"EventInfo":{
"RoomId":12345,
"EventTs":1687770731,
"EventMsTs":1687770731831,
"UserId":"test",
"Role":21,
"TerminalType":2,
"UserType":3,
"Reason":1
}
}
{
"EventGroupId":1,
"EventType":104,
"CallbackTs":1687770731922,
"EventInfo":{
"RoomId":12345,
"EventTs":1687770731,
"EventMsTs":1687770731898,
"UserId":"test",
"Role":20,
"Reason":1
}
}
{
"EventGroupId":1,
"EventType":105,
"CallbackTs":1687772245596,
"EventInfo":{
"RoomId":12345,
"EventTs":1687772245,
"EventMsTs":1687772245537,
"UserId":"test",
"Role":21
}
}
{
"EventGroupId":2,
"EventType":201,
"CallbackTs":1687771803198,
"EventInfo":{
"RoomId":12345,
"EventTs":1687771803,
"EventMsTs":1687771803192,
"UserId":"test"
}
}
{
"EventGroupId":2,
"EventType":202,
"CallbackTs":1687771919458,
"EventInfo":{
"RoomId":12345,
"EventTs":1687771919,
"EventMsTs":1687771919447,
"UserId":"test",
"Reason":0
}
}
{
"EventGroupId":2,
"EventType":203,
"CallbackTs":1687771869377,
"EventInfo":{
"RoomId":12345,
"EventTs":1687771869,
"EventMsTs":1687771869365,
"UserId":"test"
}
}
{
"EventGroupId":2,
"EventType":204,
"CallbackTs":1687770732498,
"EventInfo":{
"RoomId":12345,
"EventTs":1687770732,
"EventMsTs":1687770732383,
"UserId":"test",
"Reason":0
}
}
{
"EventGroupId":2,
"EventType":205,
"CallbackTs":1687772013823,
"EventInfo":{
"RoomId":12345,
"EventTs":1687772013,
"EventMsTs":1687772013753,
"UserId":"test"
}
}
{
"EventGroupId":2,
"EventType":206,
"CallbackTs":1687772015054,
"EventInfo":{
"RoomId":12345,
"EventTs":1687772015,
"EventMsTs":1687772015032,
"UserId":"test",
"Reason":0
}
}
Event Information
Field Name
Type
Meaning
RoomId
String/Number
Room name (type consistent with the client room ID type)
EventTs
Number
Unix Timestamp of Event Occurrence, in seconds (compatible and reserved)
EventMsTs
Number
Unix Timestamp of Event Occurrence in milliseconds
UserId
String
User ID
UniqueId
Number
Unique identifier (carried by room event group, optional)
When the client exhibits some unusual behavior, such as switching networks, abnormal process exits and re-entries, etc., your callback server may receive multiple room entry and exit callbacks for the same user at this time. UniqueId can be used to identify the same user's room entry and exit at the same time.
Role
Number
<Role Type> (option: carrying during room entry/exit)
TerminalType
Number
Terminal type (option: carrying when entering a room)
Reason (option: carrying during room entry/exit, stopping media stream)
ClientIpv4
String
Client Ipv4 address (option: carried in event 103 when using Ipv4 to enter a room)
ClientIpv6
String
Client Ipv6 address (option: carried in event 103 when using Ipv6 to enter a room)
Note:
We have released the policy of "filtering repeated callbacks caused by client special behavior". If you are integrating the callback service after July 30, 2021, the new policy will be applied by default, and the Room Event Group will no longer carry the UniqueId (unique identifier).
Role Type
Field Name
Value
Meaning
MEMBER_TRTC_ANCHOR
20
Broadcaster
MEMBER_TRTC_VIEWER
21
Audience
Terminal Type
Field Name
Value
Meaning
TERMINAL_TYPE_WINDOWS
1
For Windows:
TERMINAL_TYPE_ANDROID
2
Android
TERMINAL_TYPE_IOS
3
iOS
TERMINAL_TYPE_LINUX
4
Linux end
TERMINAL_TYPE_OTHER
100
Others
Type of User
Field Name
Value
Meaning
USER_TYPE_WEBRTC
1
webrtc
USER_TYPE_APPLET
2
WeChat Mini Program
USER_TYPE_NATIVE_SDK
3
Native SDK
Specific Reasons
Field Name
Meaning
Enter room
1: Enter room normally
2: Switch network
3: Timeout and retry.
4: Enter room for cross-room mic-connection
Check out
1: Exit room normally
2: Timeout exit
3: Room user removed
4: Cancel mic connection and exit room
5: Force kill
Note: The Android system cannot capture the forced termination of a process. It can only wait for the backend to time out and exit. At this point, the callback reason is 2.
Stop media stream.
0: Stop normally.
1: Timeout stop.
Note: If the media stream fails to be received in the backend for 30 seconds (default), the callback to stop the media stream event will be triggered, carrying a Reason of 1, indicating a timeout stop.
Calculating Signature
The signature is calculated using the HMAC SHA256 encryption algorithm. After your event callback receiving server receives the callback message, it calculates the signature in the same way. If the signatures match, it indicates that the event callback of Tencent Cloud's Real-Time Communication is authentic and has not been tampered with. The signature calculation is as follows:
//Signature Sign. The key in the computational formula is the encryption key used for calculated signature Sign.
Sign = base64(hmacsha256(key, body))
Note:
The body is the original package body of the callback request you received. Do not perform any conversion. An example is as follows:
String body ="{\n"+"\t\"EventGroupId\":\t2,\n"+"\t\"EventType\":\t204,\n"+"\t\"CallbackTs\":\t1664209748188,\n"+"\t\"EventInfo\":\t{\n"+"\t\t\"RoomId\":\t8489,\n"+"\t\t\"EventTs\":\t1664209748,\n"+"\t\t\"EventMsTs\":\t1664209748180,\n"+"\t\t\"UserId\":\t\"user_85034614\",\n"+"\t\t\"Reason\":\t0\n"+"\t}\n"+"}";
body ="{\n"+"\t\"EventGroupId\":\t2,\n"+"\t\"EventType\":\t204,\n"+"\t\"CallbackTs\":\t1664209748188,\n"+"\t\"EventInfo\":\t{\n"+"\t\t\"RoomId\":\t8489,\n"+"\t\t\"EventTs\":\t1664209748,\n"+"\t\t\"EventMsTs\":\t1664209748180,\n"+"\t\t\"UserId\":\t\"user_85034614\",\n"+"\t\t\"Reason\":\t0\n"+"\t}\n"+"}"
var data ="{\n\t\"EventGroupId\":\t1,\n\t\"EventType\":\t101,\n\t\"CallbackTs\":\t1608086882372,\n\t\"EventInfo\":\t{\n\t\t\"RoomId\":\t20222,\n\t\t\"EventTs\":\t1608086882,\n\t\t\"UserId\":\t\"222222_phone\"\n\t}\n}"