# initByCaller(Object req)
This interface is asynchronous and returns
Promise
Object.
Initiate a call and get the calling room number. When you call this interface, you create VoIP Room, and push an answer reminder to the receiving party.
It is recommended to read firstIntroduction to Interface。
# parameter
# Object req
attribute | type | Default value | Required | Introductions | Minimum version |
---|---|---|---|---|---|
roomType | string | yes | Call type. voice: Audio callvideo: Video call | ||
caller | Object | yes | Dialing party information | ||
caller.id | string | yes | Dialing party ID, reference businessType Dxplaination of the | ||
caller.name | string | no | The dialing party name displayed. Invalid when device initiated call | ||
caller.cameraStatus | number | 0 | no | Whether or not cameras are enabled. 0: open1: Stop | |
listener | Object | yes | Receiving Party Information | ||
listener.id | string | yes | Receiving party ID, reference businessType Dxplaination of the | ||
listener.name | string | no | The recipient name displayed. | ||
listener.cameraStatus | number | 0 | no | Whether or not cameras are enabled. 0: open1: Stop | |
businessType | number | 0 | no | Type of business. See also businessType Dxplaination of the | |
VoipToken | string | no | Call the ticket, required in some cases, refer to the businessType Dxplaination of the | ||
miniprogramState | string | formal | no | The type of Mini Program that opens when the recipient clicks the notification. Value: formal: Official version trial: Experience version developer: Development version. 2.1.8 From now on, the official version of the Mini Program can only be called to the official version, setting this field is invalid. | |
customQuery | string | no | When the recipient clicks on the notification to open the Mini Program, it will act as query After splicing into the plugin page path, the format is as a=1&b=2 Can be accessed within the listener Mini Program via the getPluginOnloadOptions or getPluginEnterOptions Interface gets to the | ||
timeLimit | number | no | The maximum length of the call is required. > 0 The number of | 2.3.8 |
# Return value
For historical reasons, a failed call to this interface may throw an exception (usually a parameter error), or it may return isSuccess: false
(Usually a backstage error).
After the interface has successfully returned, you still need to use the isSuccess
Field to determine whether the call was ultimately successful.
# Object
When the interface call succeeds, it returns the following
attribute | type | Introductions | Minimum version |
---|---|---|---|
isSuccess | boolean | Whether the call succeeded or not. At this point, the true | |
roomId | string | The room number for this call | 2.4.0 |
groupId | string | and roomId identical | |
chargeType | string | Billing method. Value: duration: Duration chargelicense: License Billing | 2.3.8 |
When the call fails, the interface returns the following:
attribute | type | Introductions | Minimum version |
---|---|---|---|
isSuccess | boolean | Whether the call succeeded or not. At this point, the false | |
error | object | Error object, deprecated. { err_code: string, errMsg: string } | |
errCode | number | Error code, value referenceError Code Document | |
errMsg | string | Error message | |
errObj | VoipError | Error object | 2.4.0 |
# about businessType
different businessType The corresponding part of the parameters have different meanings, please refer to the corresponding business documents for the specific way to obtain the parameters.
businessType | Type of business | caller.id | listener.id | VoipToken |
---|---|---|---|---|
1 | Hardware device call mobile phone WeChat | equipment SN | WeChat users openId | useEquipment certification SDKRegistered device incoming deviceToken. use WMPF Registered devicesCannot have this field (the plugin 2.3.0 Support) |
2 | Mobile phone WeChat call hardware equipment | WeChat users openId | equipment SN | Obtained from the device [pushToken ](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/push.html) |
- Before initiating a call, you need to make a call in advance openId The corresponding user is authorized in the Mini Program of the WeChat client, please seeAuthorization document
- to import id for equipment SN When, name That will force the use of user authorizationdeviceName+modelId Corresponding Equipment Model, does not use the developer's incoming name。
- This interface
businessType=2
Android only WMPF, Call Linux Equipment please use callDevice。 - This interface
businessType=2
Not support License Billing, phone WeChat call Android WMPF Suggested Use callWMPF。
# sample code
const wmpfVoip = requirePlugin('wmpf-voip' ).default
try {
const { isSuccess } = await wmpfVoip.initByCaller({
caller: {
id: 'Dialing party Id',
name: "Calling party name,"
},
listener: {
id: 'the receiver Id',
name: The name of the receiver,
},
roomType: 'video',
businessType: 1,
voipToken: 'xxxx*****xxxx',
miniprogramState: 'developer', // The development phase recommends using the development version
})
if (isSuccess /* && Currently not in plugin page */) {
wx.redirectTo({
url: wmpfVoip.CALL_PAGE_PATH,
})
} else {
wx.showToast({
title: Call failure,
icon: 'error',
})
}
} catch (e) {
wx.showToast({
title: Call failure,
icon: 'error',
})
}