May 18, 2021 WeChat Mini Program Development Document
The ability to implement multiplayer audio and video conversations in small programs.
Small program management background, "development" - "interface settings" in the self-service to open the component permissions. Related interface wx.joinVoIPChat and component voip-room.
Developers only need to provide a unique identification of the room to join the designated room. I ncoming users with the same unique identity will enter the same room. T o ensure that the front-end incoming groupId is trusted, the wx.joinVoIPChat interface requires an incoming signature. S ee the signature algorithm below. When you join a video room, you can display a member screen in conjunction with the voip-room component.
There are four parameters that need to be passed in to generate a signature:
The name of the argument | Description |
---|---|
appId | AppId for games |
groupId | The unique logo of the game room is guaranteed by the game itself |
nonceStr | Random string, length should be less than 128 |
timeStamp | Generate this random string UNIX timestamp (accurate to second) |
The signature algorithm is:
signature = hmac_sha256([appId, groupId, nonceStr, timeStamp].sort().join(''), sessionKey)
Specifically, this algorithm is divided into several steps:
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'
In cloud development, you can't get session_key, but a separate 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
}
A maximum of 10 people can be added to each room at the same time.
For each small program, up to 100,000 rooms per day are allowed to be created. W hen everyone exits the room, the room is destroyed. At this point, if you rejoin the room with a previously used groupId, it will be calculated as opening a new room.