# Real-time Voice Chat

This service is used to implement multi-player real-time voice chat in a game room.

# Applying for Activation

This service is limited to Mini Games with over 1000 total registered users. Developers must go to MP Admin Console > Settings > Game Settings to apply for the access to this API.

# Calling Process

All calls are completed via frontend APIs. Developers only need to provide the unique room ID to establish a specified voice chat room, and users who pass the same ID will enter this room. To ensure the groupId passed in the frontend is reliable, the wx.joinVoIPChat API requires that a signature be passed. For details, see Signature Algorithm.

# Frontend APIs

# Signature Algorithm

To generate a signature, the Mini Program must provide four parameters:

Parameter Description
appId The Mini Game's appId
groupId The unique identifier of the game room (uniqueness is ensured by the game)
nonceStr A random string with up to 128 characters
timeStamp Unix timestamp for generating the random string (in seconds)

The signature algorithm is:

signature = hmac_sha256([appId, groupId, nonceStr, timeStamp].sort().join(''), sessionKey)

Specifically, this algorithm involves the following steps:

  1. Represent the values appId, groupId, nonceStr, and timeStamp as strings sorted in lexicographical order
  2. Concatenate the four sorted strings
  3. Calculate the resulting string in step 2 using the hmac_sha256 algorithm with the session_key as the key to get the signature

# Using Cloud Base to Complete Signature

In Cloud Base, you cannot get the session_key, but the function cloud.getVoIPSign is provided for signature calculation.

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
}

# User Limit

A room can contain up to 10 users at a time.

# Frequency Limit

Up to 100,000 voice chat rooms can be created per Mini Game each day. When all members exit a room, the room is deleted. In this case, the room that is entered again with the groupId used previously will be counted as a new room.

点击咨询小助手