# callDevice(Object req)

This interface is asynchronous and returns thePromiseobject.

Support needs to start with the plug-in version 2.4.0

Call Linux devices, RTOS devices from the Weixin Mini Program of the mobile home.After calling this interface, a VoIP room is created. Developers should push call reminders to the device themselves.Please refer to for details.

This interface can only be used in WeChat Guest, not in WMPF.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
sn string yes Receiver device SN
modelId string yes Receiver device modelId
chargeType string 'license' no The method of billing. Duration: duration billing; License: license billing
timeLimit number no Maximum call time, needs a number > 0
enableCallerCamera boolean true no Whether the caller turned on the camera
enableListenerCamera boolean true no Does the receiver turn on the camera?
nickName string no The WeChat user name displayed on the device side, recording only
deviceName string no Device name displayed on WeChat 2.4.1
isCloud boolean false no If calling an RTOS device, set to true to trigger a message callback
payload string no When calling the RTOS, you can bring payload to the callback message
encodeVideoFixedLength number 0 no Length margin values of the encoding, optional 320, 480, 640
encodeVideoRotation number 0 no The encoded video rotates in a direction. 1: Give out a positive flow. 2: Keep give out a rotating flow
encodeVideoRatio number 0 no Proportion of the video, Width / High * 100
encodeVideoMaxFPS number 0 no Maximum FPS for video, 8-15

# Return value

Failure to invoke this interface throws an exception .

# Object

When the interface is called successfully, it returns as follows:

attribute type Introductions Minimum version
roomId string The room number for this call

# sample code

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

try {
  const { roomId } = await wmpfVoip.callDevice({
    roomType: 'video',
    sn: '设备 SN',
    modelId: '设备 modelId',
    nickName: '设备端显示的微信用户名称',
  })

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