Skip to content

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 command channel.

Connected (cmdw=0x2000) ​

After 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.

c
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) ​

When 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.

c
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.

c
// 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 ​

ValueMeaning when receivedMeaning when sent
0UnknownUnknown
1WeChat user manually hangs upDevice actively hangs up
2Ended by a system phone call- (not recommended)
3Ended by another appEnded by another app
4Capture / playback device failed to startCapture / playback device failed to start
5Busy- (not recommended)
6Timeout, no answer- (not recommended)
7Rejected before entering the call- (not recommended)
8Session ended abnormallySession ended abnormally
Other valuesReserved for future extensionReserved for future extension

WeChat VoIP calling