Skip to main content

Media Gateway event type

After enabling the Notifications service, the Agora server will send a channel event notification callback to your server using the HTTPS POST request method. When the value of the product_id parameter in the callback request body is 10, it means that the Media Gateway event is returned.

This page introduces the types and descriptions for all events returned in the channel event callback.

1 live_stream_connected

The gateway has received the RTMP or SRT stream and successfully entered the channel.

Payload example:


_24
{
_24
"sid": "55df7402-8778-11ee-92ed-07ec2e86c928",
_24
"region": "na",
_24
"domain": "rtls-ingress-prod-na.agoramdn.com",
_24
"streamKey": "7B***Qbs",
_24
"rtcInfo": {
_24
"channel": "123",
_24
"uid": "1234"
_24
},
_24
"transcoding": {
_24
"audio": {
_24
"enabled": true,
_24
"profile": 5
_24
},
_24
"video": {
_24
"enabled":true,
_24
"bitrate":3800,
_24
"fps":30,
_24
"height":1080,
_24
"width":1920
_24
}
_24
},
_24
"beginAt": "2023-11-21T02:27:31Z"
_24
}

The payload contains the following fields:

FieldData typeDescription
sidStringThe unique ID of each streaming session.
regionStringThe server area that has received the pushed stream.
streamKeyStringThe used streaming key.
rtcInfoObjectRTC information:
  • channel: The channel name. When the channel bound to the stream key is "", this field stores the specific random value used for this stream.
  • uid: The host UID. Supports integer and string data types. When the uid bound to the stream key is "" or "0", this field stores the specific random value used for this stream.
transcodingObjectTranscoding configuration information used for streaming. For specific field information, refer to the description of the transcoding field in the Create or reset template.
beginAtStringThe start time of the streaming in the RFC3339 format.

This event is followed by a corresponding live_stream_disconnected event.

2 live_stream_disconnected

The gateway has actively or passively disconnected and left the channel.

Payload example:


_18
{
_18
"sid": "55df7402-8778-11ee-92ed-07ec2e86c928",
_18
"region": "na",
_18
"streamKey": "7B***Qbs",
_18
"domain": "rtls-ingress-prod-na.agoramdn.com:1935",
_18
"rtcInfo": {
_18
"channel": "123",
_18
"uid": "1234"
_18
},
_18
"streamStats": {
_18
"inputAudioBytes": 281799,
_18
"inputVideoBytes": 9244544,
_18
"outputAudioBytes": 130000,
_18
"outputVideoBytes": 6656704
_18
},
_18
"beginAt": "2023-11-21T02:27:31Z",
_18
"endAt": "2023-11-21T03:27:31Z"
_18
}

The payload contains the following fields:

FieldData typeDescription
sidStringThe unique ID of each streaming session.
regionStringThe server area that has received the pushed stream.
streamKeyStringThe used streaming key.
rtcInfoObjectRTC information:
  • channel: The channel name. When the channel bound to the stream key is "", this field stores the specific random value used for this stream.
  • uid: The host UID. Supports integer and string data types. When the uid bound to the stream key is "" or "0", this field stores the specific random value used for this stream.
streamStatsObjectStatistics for this stream, including:
  • inputAudioBytes: Total bytes of audio stream input from the source stream.
  • inputVideoBytes: Total bytes of video stream input from the source stream.
  • outputAudioBytes: Total bytes of audio stream pushed to the RTC channel.
  • outputVideoBytes: Total bytes of video stream pushed to the RTC channel.
beginAtStringThe start time of the streaming in the RFC3339 format.
endAtStringThe end time of the streaming in the RFC3339 format.

3 live_stream_aborted

The gateway has received an RTMP or SRT stream but terminated it for some reason. This event may be sent individually or between live_stream_connected and live_stream_disconnected events.

Payload example:


_13
{
_13
"sid": "55df7402-8778-11ee-92ed-07ec2e86c928",
_13
"region": "na",
_13
"domain": "rtls-ingress-prod-na.agoramdn.com",
_13
"streamKey": "7B***Qbs",
_13
"rtcInfo": {
_13
"channel": "123",
_13
"uid": "1234"
_13
},
_13
"beginAt": "2023-11-21T02:27:31Z",
_13
"errorCode": 100,
_13
"reason": "invalid"
_13
}

The payload contains the following fields:

FieldData typeDescription
sidStringThe unique ID of each streaming session.
regionStringThe server area that has received the pushed stream.
domainStringThe domain used for streaming.
streamKeyStringThe used streaming key.
rtcInfoObjectRTC information:
  • channel: The channel name. When the channel bound to the stream key is "", this field stores the specific random value used for this stream.
  • uid: The host UID. Supports integer and string data types. When the uid bound to the stream key is "" or "0", this field stores the specific random value used for this stream.
beginAtStringThe start time of the streaming in the RFC3339 format.
errorCodeNumberThe stream termination error code.
reasonStringThe error message.

The possible values for the errorCode are:

ValueDescriptionRecommended actions
1Illegal streamKey. For example, channelName is empty or contains illegal characters.Check the streamKey format, especially for locally generated ones.
2Invalid streamKey (expired or deleted)Create a new streamKey and try again.
3No permission to use this streamKey. For example, the customer-defined domain name and streamKey under the associated app ID do not match.Check whether the streamKey matches the domain name used for the push.
4Number of concurrent streams exceeds the limit.Wait and retry.
5Conflict detected, for example, pushing to the same channel and at the same.If the streams are not being pushed at the same time, try again 5-10 seconds later.
6The stream attribute exceeds the limit (currently applies to bitrate only).Check the streaming software configuration and lower the target bitrate.
7Streaming without any audio or video data for more than 10 secondsCheck whether the last push exited abnormally, and then try again.
8Failed to join channelThe reason field will provide the specific error reason, for example: "connect to rtc failed, reason:$N". Refer to the API documentation for details.
9Disconnected from the main network. Specific reasons need to be investigated by contacting technical support.Try again several times. If you still have problems, contact technical support to confirm whether the app certificate provided during activation is valid.
10Unknown internal service error. Specific reasons need to be investigated by contacting technical support.Try again a few times. If you still have problems, contact technical support.

4 live_profile_updated

Stream properties have been updated. For example, the first audio or video frame has been received or the audio or video profile has changed.

Payload example:


_21
{
_21
"sid": "55df7402-8778-11ee-92ed-07ec2e86c928",
_21
"region": "na",
_21
"domain": "rtls-ingress-prod-na.agoramdn.com",
_21
"streamKey": "7B***Qbs",
_21
"rtcInfo": {
_21
"channel": "123",
_21
"uid": "1234"
_21
},
_21
"videoProfile": {
_21
"codec": "H.264",
_21
"width": 1920,
_21
"height": 1080,
_21
"gop": 2000
_21
},
_21
"audioProfile": {
_21
"sampleRate": 48000,
_21
"channels": 2
_21
},
_21
"beginAt": "2023-11-21T02:27:31Z"
_21
}

The payload contains the following fields:

FieldData typeDescription
sidStringThe unique ID of each streaming session.
regionStringThe server area that has received the pushed stream.
streamKeyStringThe used streaming key.
rtcInfoObjectRTC information:
  • channel: The channel name. When the channel bound to the stream key is "", this field stores the specific random value used for this stream.
  • uid: The host UID. Supports integer and string data types. When the uid bound to the stream key is "" or "0", this field stores the specific random value used for this stream.
videoProfileObjectVideo properties. Not applicable for audio-only streams.
  • codec: Video codec format, such as "H.264", "H.265", "VP8", "VP9", "AV1", and so on.
  • width: Video width.
  • height: Video height.
  • gop: GOP length in ms, Number type. To prevent frequent callbacks, GOP is calculated as an average value once per minute and rounded to 1000 ms. For example, when the actual calculated value is in the range of 1500-2499, it is rounded to 2000 ms. The minimum value is 1000 ms.
audioProfileObjectAudio properties:
  • sampleRate: The sampling rate in Hz.
  • channels: The number of channels.
beginAtStringThe start time of the streaming in the RFC3339 format.