WeChat VoIP Calling Commands
In WeChat VoIP calling scenarios, the device and Tange Cloud exchange the following command words over the established TiRTC connection through the
Connected (cmdw=0x2000 )
cmdw=0x2000After the WeChat VoIP calling session between the device and the WeChat Mini Program is established, Tange Cloud sends a connected command with cmdw=0x2000 and data=NULL through the command channel. After receiving it, the device can use the TiRTC connection hconn for bidirectional audio and video stream transmission.
static void on_command(tirtc_conn_t hconn, uint32_t cmdw, const void *data, uint32_t len) {
if (cmdw == 0x2000) {
// Start receiving and sending audio/video streams on hconn asynchronously here.
// Note: Do not perform time-consuming operations inside this callback.
}
}Hang Up (cmdw=0x2001 )
cmdw=0x2001When the peer hangs up the session, Tange Cloud sends a notification with command word cmdw=0x2001 through the command channel, and data carries the hang-up reason data. After receiving it, the device should close the corresponding connection and release related resources.
Note that there may be multiple hang-up reasons, including rejecting the call (hanging up before entering the call). For details, see Hang-up reasons below.
static void on_command(tirtc_conn_t hconn, uint32_t cmdw, const void *data, uint32_t len) {
if (cmdw == 0x2001) {
// Close the corresponding connection and release related resources asynchronously here.
// data is a JSON string in the format {"reason":<int>}.
// If data parsing fails, it is recommended to ignore it directly.
// Note: Do not perform time-consuming operations inside this callback.
}
}When the device needs to actively hang up the session, it can send a notification with command word cmdw=0x2001 to Tange Cloud through the command channel and include the hang-up reason in data.
// Local active hang-up
// data is a JSON string in the format {"reason":<int>}.
static int wxvoip_send_hangup(tirtc_conn_t hconn, int reason)
{
char data[16];
uint32_t n = snprintf(data, sizeof(data), "{\"reason\":%d}", reason);
return TiRtcSendCommand(hconn, 0x2001, data, n);
}Hang-up Reasons
| Value | Meaning when received | Meaning when sent |
|---|---|---|
0 | Unknown | Unknown |
1 | WeChat user manually hangs up | Device actively hangs up |
2 | Ended by a system phone call | - (not recommended) |
3 | Ended by another app | Ended by another app |
4 | Capture / playback device failed to start | Capture / playback device failed to start |
5 | Busy | - (not recommended) |
6 | Timeout, no answer | - (not recommended) |
7 | Rejected before entering the call | - (not recommended) |
8 | Session ended abnormally | Session ended abnormally |
| Other values | Reserved for future extension | Reserved for future extension |