# initByCaller(Object req)

This interface is asynchronous and returns thePromiseobject.

Start the call and get the call room number. When this interface is called, a VoIP room is created and an answer alert is pushed to the receiver.

It is recommended to read interface introduction first.

# parameter

# Object req

attribute type Default values Required to fill in Introductions Minimum version
roomType string yes The type of call. Voice: audio call;video: Video calling
caller Object yes Dialing party information
caller.id string yes Dialing party id, refer to the instructions for businessType
caller.name string no The name of the caller shown. When the device initiates a call, it is not valid
caller.cameraStatus number 0 no Enable the camera or not. 0: Open; 1: Close
listener Object yes Recipient Information
listener.id string yes Receiver id, refer to businessType
listener.name string no The name of the receiver shown.
listener.cameraStatus number 0 no Enable the camera or not. 0: Open; 1: Close
businessType number 0 no Type of business. See the explaination of businessType
voipToken string no Call the bill, required in some cases, refer to the explaination of businessType
miniprogramState string formal no 接听方点击通知时打开的小程序类型。

取值:formal: 正式版; trial: 体验版; developer: 开发版。

2.1.8 起,正式版小程序只能拨打给正式版,设置这一字段无效。
customQuery string no When the receiver clicks on the notification to open Weixin Mini Program, it will be spliced to the plug-in page path as a query, formatted as [[ TAG-0-START]] a=1&b=2。 Can be accessed within the Receiver Mini Program via thegetPluginOnloadOptionsorgetPluginEnterOptions`interface
timeLimit number no Maximum call time, needs a number > 0 2.3.8

# Return value

For historical reasons, a failed call to this interface may throw an exception (typically a parameter error) and may returnisSuccess: false(It's usually a background error.)

After the interface returns successfully, you still need to use theisSuccessfield to determine whether the call finally succeeded.

# Object

When the interface is called successfully, it returns as follows

attribute type Introductions Minimum version
isSuccess boolean Whether the call was successful, at this time true
roomId string The room number for this call 2.4.0
groupId string Same as roomId
chargeType string The method of billing. Value: duration: duration billing; License: license billing 2.3.8

When the call fails, the interface returns as follows:

attribute type Introductions Minimum version
isSuccess boolean Whether the call was successful, false
error object The wrong object has been abandoned.{ err_code: string, errMsg: string }
errCode number Error code, value reference error code documentation
errMsg string Error message
errObj VoipError Error object 2.4.0

# About businessType

Some of the parameters corresponding to different businessType have different meanings. Please refer to the corresponding business documentation for the specific way to obtain the parameters.

businessType Type of business caller.id listener.id voipToken
1 Hardware devices calling mobile phones WeChat Equipment SN WeChat User openId Use device authentication SDK registered devices enter deviceToken.

Use WMPF registered devices cannot have this field (Plugin 2.3.0 supports)
2 Mobile WeChat Calling hardware devices WeChat User openId Equipment SN pushToken acquired from the device
  • Before initiating a call, the user corresponding to the openId need to be authorized in the WeChat client's Weixin Mini Program in advance. See the authorization document ;
  • When passing in the id as the device SN, name forces the "deviceName" + "modelId corresponding to the device model" used for user authorization, not the name passed in by the developer.
  • This interfacebusinessType = 2supports Android WMPF only, call Linux devices please use callDevice .
  • This interfacebusinessType = 2does not support license billing, mobile WeChat calling Android WMPF is recommended callWMPF

# sample code

const wmpfVoip = requirePlugin('wmpf-voip').default

try {
  const { isSuccess } = await wmpfVoip.initByCaller({
    caller: {
      id: '拨打方 Id',
      name: '拨打方名字',
    },
    listener: {
      id: '接听方 Id',
      name: '接听方名字',
    },
    roomType: 'video',
    businessType: 1,
    voipToken: 'xxxx*****xxxx',
    miniprogramState: 'developer', // 开发阶段建议使用开发版
  })

  if (isSuccess /* && 当前不在插件页面 */) {
    wx.redirectTo({
      url: wmpfVoip.CALL_PAGE_PATH,
    })
  } else {
    wx.showToast({
      title: '呼叫失败',
      icon: 'error',
    })
  }
} catch (e) {
  wx.showToast({
    title: '呼叫失败',
    icon: 'error',
  })
}