# Mobile phone WeChat call device(Android)
Users can initiate audio and video calls to the device, and the device requires the developer to pull up the designated page of the Mini Program to let the user answer the call after receiving the message.
If you want to get various events during a call, you can use the plug-in's
onVoipEvent
Interface.
# 1. Mobile phone WeChat terminal to initiate a call
Before initiating a call, the user generally needs to select the device and the type of call in the Mini Program (audio/Video).
When initiating a call, the developer needs to first get the backend [pushToken
](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/push.html), and call the plug-in's callWMPF
Interface, and then jump to the plug-in's Initiate Call page.
const wmpfVoip = requirePlugin('wmpf-voip' ).default
const roomType = 'video'
try {
const { roomId, isSuccess } = await wmpfVoip.callWMPF({
roomType: 'video', // Room type. voice: Audio Roomvideo: Video Room
sn: 'equipment SN',
modelId: 'equipment modelId',
pushToken: 'obtained from the device pushToken',
nickName: "WeChat user name displayed on the device end,"
deviceName: My learning machine,
envVersion: 'release', // Specifies the version of the Mini Program used by the recipient, and the development process can use develop
})
if (/* Currently not in plugin page */) {
// Jump to the plugin's call page
wx.redirectTo({
url: wmpfVoip.CALL_PAGE_PATH,
// plug-in 2.3.9 Start support CALL_PAGE_PATH, Lower version please. 'plugin-private://wxf830863afde621eb/pages/call-page-plugin/call-page-plugin',
})
}
} catch (e) {
console.error('callWMPF failed:', e)
// The case of an incorrect parameter will be thrown by an exception
wx.showToast({
title: Call failure,
icon: 'error',
})
}
Be careful
- It is recommended that developers maintain on the server side sn and pushToken Of the association, in advance at the device side[Obtain pushToken ](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/push.html)Coexist to the backstage, and in the pushToken Refresh before expiration.
- When initiating a call, you need to ensure that the deviceActivated and connected online。
- The message pushed to the device will be directly issued by the WeChat background after calling the call interface, and the developer does not need to call the interface of the server to issue the message.
- plug-in 2.4.0 The following versions are required.initByCallerInterface Call Device, Incoming
businessType: 2
The use of initByCaller Interface-initiated calls that require the user to make additionalTo grant authorization。
# 2. Device-side answering calls (Android)
After the call is initiated on the WeChat side of the mobile phone, the device side will receive a message [WMPF Push Messages for](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/push.html)Requires the developer to handle the notification and pull up the Mini Program to show the call interface:
# 2.1 Binding message listening
Developers need to be WMPF Call in [registerPushMsgEventListener](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/device/registerPushMsgEventListener.html) Sign up for message listening.Note that this step must take place before the call is initiated.
# 2.2 Display Call Notification/Reminder (optional)
After receiving the message, the developer can display the call notification according to the product needs (the style can be customized), and can also directly pull up the Mini Program for the user to answer.
# 2.3 Open the Mini Program to answer
The push message is JSON Character string, parsed as follows
{
"path": "plugin-private://wxf830863afde621eb/pages/call-page-plugin/call-page-plugin?RoomType = roomType & groupId = groupId & listenerId = device sn & callerName = caller name & customQuery character string ", // Mini Program startup path
"appType": 0, // 0: Official version 1: Development version 2: Experience version
"appid": "wx********" // Mini Program appid
}
The developer needs to use the above parameters, call the WMPF [launchMiniProgram
](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/miniprogram/launchMiniProgram.html) Interface Opens the listening interface of the Mini Program.
Be careful
- **If the developer shows a custom caller notification after receiving the message, you can start the Mini Program's path After adding
&isClickedHangOnBtn = 1
**At this time, the user will directly answer the call when entering the Mini Program, and does not need to click the plug-in call page again.to answer the phoneButton. - Suggested in Android APP Used in [
WMPFLifeCycleManager
](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/lifecycle/addWMPFLifecycleListener.html) to monitor WMPF Exit the event, and restart and activate the WMPF in order to prevent WMPF Message is lost after the exception exits. - To speed up receiving calls, it is recommended that you call the[
prefetchDeviceToken
](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/miniprogramdevices /prefetchDeviceToken.html) Prepull equipment voucher. - On the device, app When you pull up an Mini Program or receive a call slowly, refer to thePerformance and Experience Optimization Guide。
# 3. End of call handled by device
After the end of the device call, the developer needs to handle the page jump or close the Mini Program on his own. There are generally the following ways:
- Jump to other pages after the end: Developers need to go through the plugin
setVoipEndPagePath
Interface sets the page where the call ends. The developer stays on the call log page when it is not set. - After the end of the Mini Program cut the background: the developer can listenplug-in endVoip or finishVoip event, Through WMPF Provided[Communication channel(Invoke Channel)](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/invoke-channel.html)Notify the mobile app, use the[closeWxaApp](https://developers.weixin.qq.com/doc/oplatform /Miniprogram_Frame/api/cli/miniprogram/closeWxaApp.html) (keepRunning=true) The Mini Program cut background.
- Close the Mini Program when it is over: the developer can listenplug-in endVoip or finishVoip event, Call [wx.exitMiniProgram ]((wx.exitMiniProgram )) Close the Mini Program.