# Multiplayer Audio and Video Dialogue

It is used to realize the function of multi-person audio and video dialogue in the Mini Program.

# Application for opening

Mini Program management background,Development-Interface SettingsSelf - enable permissions for this component in. Related interface wx.joinVoIPChat And Components voip-room

# Call process

Developers only need to provide a unique identification of the room, you can join the designated room. Users who pass in the same unique identifier will enter the same room. In order to ensure that the front-end incoming groupId Credible,wx.joinVoIPChat The interface requires an incoming signature. See also [Signature algorithm](#Signature algorithm)When added to the video room, can be combined with voip-room Component displays the member screen.

# Front End Interface

# Signature algorithm

Four parameters are passed in to generate the signature:

Parameter name Introductions
appId Mini Program. appId
groupId Unique identification of the game room, guaranteed by the game itself unique
NonceStr Random character string, less than 128
timeStamp That's going to produce this random character string UNIX Time stamp (accurate to the second)

The signature algorithm is:

// hmac_Sha256 requires developers to introduce their own
signature = hmac_sha256([appId, groupId, nonceStr,  timeStamp].sort().join(''), sessionKey)

Specifically, this algorithm is divided into several steps:

  1. Yes appId groupId NonceStr timeStamp The four values are represented as character strings, lexicographically
  2. Splicing together the four character strings in sequence.
  3. use session_key Act as key, Use hmac_sha256 Algorithm pair 2 The result is a character string in the signature

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'

# Complete Signing with Cloud Development

In cloud development, there is no way to get session_key, but provides separate functions [cloud.getVoIPSign](https://developers.weixin.qq.com/miniprogram/dev/wxcloud /reference-sdk-api/open/Cloud.getVoIPSign.html) 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
}

# Number of Restrictions

Each room at the same time. 10 Individuals.

# Frequency limitation

For each Mini Program, the maximum allowed per day is to create 100000 One room. When everyone leaves the room, the room is destroyed. At this point, if you pass in the previously used groupId Rejoining a room is counted as a new room.