Real-time Audio
A service used to implement multi-person real-time voice chat in game rooms.
Application for Activation
Developers must apply for interface usage permissions in the MP Console under Game Capability Map > Real-time Voice.
Call Flow
All calls are completed via frontend interfaces. Developers only need to provide a unique room identifier to join a specified room. Users passing the same unique identifier will enter the same voice room. To ensure the reliability of the groupId passed from the frontend, the wx.joinVoIPChat interface requires a signature. See Signature Algorithm for details.
Front-end APIs
- Create/join a room: wx.joinVoIPChat
- Leave a room: wx.exitVoIPChat
- Update room microphone/earphone mute settings: wx.updateVoIPChatMuteConfig
- Monitor room member changes: wx.onVoIPChatMembersChanged
- Monitor room member call status changes: wx.onVoIPChatSpeakersChanged
- Monitor call interruptions: wx.onVoIPChatInterrupted
Signature Algorithm
Generating the signature requires the Mini Game to pass in four parameters:
| Parameter Name | Description |
|---|---|
| appId | The appId of the Mini Game |
| groupId | The unique identifier of the game room, guaranteed to be unique by the game |
| nonceStr | A random string, whose length should be less than 128 |
| timeStamp | The UNIX timestamp (in seconds) used to generate the random string |
The signature algorithm is:
signature = hmac_sha256([appId, groupId, nonceStr, timeStamp].sort().join(''), sessionKey)
Specifically, this algorithm consists of the following steps:
- Convert the four values
appId,groupId,nonceStr, andtimeStampinto strings and sort them in lexicographical order; - Concatenate the sorted four strings together;
- Use
session_keyas thekeyand apply thehmac_sha256algorithm to the result string from step 2; the resulting output is thesignature
Example:
appId = 'wx20afc706a711eefc'
groupId = '1559129713_672975982'
nonceStr = '8AP6DT9ybtniUJfb'
timeStamp = '1559129714'
session_key = 'gDyVgzwa0mFz9uUP7M6GQQ=='
str = [appId, groupId, nonceStr, timeStamp].sort().join('') = '1559129713_67297598215591297148AP6DT9ybtniUJfbwx20afc706a711eefc'
signature = hmac_sha256('1559129713_67297598215591297148AP6DT9ybtniUJfbwx20afc706a711eefc', sessionKey) = 'b002b824688dd8593a6079e11d8c5e8734fbcb39a6d5906eb347bfbcad79c617'
Signing with Cloud Development
In Cloud Development, session_key cannot be obtained; however, a dedicated function cloud.getVoIPSign is provided to calculate the signature.
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
const signature = cloud.getVoIPSign({
groupId: 'xxx',
timestamp: 123,
nonce: 'yyy'
})
return signature
}
Participant Limit
A maximum of 10 people can join each room simultaneously.
Rate Limiting
For each Mini Game, a maximum of 100,000 voice rooms can be created per day. A room is destroyed when all members have exited it. If the groupId that was previously used is passed to rejoin a room, it will be counted as creating a new room.