# function onVoipEvent(function listener)
# Features Description
Listen to VoIP call-related events. Event binding needs to be completed before the call starts .
Note: Do not bind events within the lifecycle such as onLoad, onShow, etc. It may be repeated because the lifecycle calls are repeated.
# parameter
# function listener
Event listening function
# callback parameters
# Object event
| attribute | type | Introductions | Minimum version |
|---|---|---|---|
| eventName | string | The name of the event. Please refer to the description below. | |
| roomId | string | Call the room number.Except forbindContact,callPageOnShowevents | 2.4.0 |
| groupId | string | Same as roomId | |
| data | Object | Additional parameters for an event. The fields for different events are different, see below for description |
# Return value
function
Cancels the listening function, cancels the event after the function call. The function has no parameters and no return value.
# Description of the event
# 1. startVoip
The call began.
# 2. abortVoip
The call was abruptly interrupted.
data parameter
| attribute | type | Introductions |
|---|---|---|
| keepTime | number | Duration of the call |
| status | string | For exception explaination, see below for values |
| error | Object | Error object |
| error.errMsg | Object | Error message |
Value of status
| status | describe |
|---|---|
| abortByListener | The call was interrupted because of an exception at this end (triggered by the receiver) |
| abortByCaller | Call was abruptly interrupted by this end (triggered by the caller) |
| unknown | The call was interrupted due to an exceptional over-the-counter |
Common errMsg
Room status is abort: status = unknown, triggered when receiving an exception to the end of the call, need to determine the real reason for the exception according to the abortVoip event triggered by the roomId.listener waitOtherToJoin timeout:status=abortByListener,After the receiving party joins the room, the dialing party has not been successfully joined (may be due to slow network) or abnormally quit, the receiving party waits for 20s to trigger after timeout. At this point, it is recommended to analyze the receiver's situation to detect it.Call interrupted due to close passive float ball: After the user cuts Weixin Mini Program to the background, the Mini Program float window will be displayed, which is triggered when the user closes the Mini Program through the float window.In comming call: Weixin Mini Program Triggered when the call is interrupted by another caller.Call interrupted due to native reason: Generally due to a period of time during the call did not receive digital packet (usually network reasons), was kicked out of the room interrupted call.
# 3. hangOnVoip
The call is answered (triggered only by the receiver).
# 4. cancelVoip
The call was not connected and the caller canceled the call.
data parameter
| attribute | type | Introductions |
|---|---|---|
| status | string | The reasons for cancellation are explained, with value given below |
Value of status
| status | describe |
|---|---|
| manual | The user cancels the call by clicking the interface hang button. (Caller Only) |
| unloadCallPage | The plugin page was destroyed causing the call to be cancelled. (Caller Only) |
| forceFromApp | Weixin Mini Program CallforceHangUpVoipto cancel the call.(Caller Only) |
| other | The caller canceled the call. (receiver only) |
# 5. rejectVoip
The call went unanswered and the receiver refused to answer.
data parameter
| attribute | type | Introductions |
|---|---|---|
| status | string | For a reason for refusal, see below |
Value of status
| status | describe |
|---|---|
| manual | The user clicks the interface hang button to refuse the call (receiver only) |
| unloadCallPage | The plugin page was destroyed causing the call to be refused (only the receiver) |
| forceFromApp | Weixin Mini Program CallforceHangUpVoipReject calls (receivers only) |
| other | The receiver refuses to answer (only the caller) |
# 6. hangUpVoip
The call is connected and the caller / receiver hangs up.
data parameter
| attribute | type | Introductions |
|---|---|---|
| keepTime | number | Duration of the call |
| status | string | For a explaination of the hanging party, see below for value |
| origin | string | For a explaination of the reason for the hangup, see below |
Value of status
| status | describe |
|---|---|
| endByListener | The receiver hung up. |
| endByCaller | The caller hangs up |
Origin value
To maintain backward compatibility, the hangUpVoip event additionally uses the origin field to provide specific information about the reason for the hang up.
| origin | describe |
|---|---|
| manual | The user clicks the interface hang button to hang up the call (only the hanged party) |
| unloadCallPage | The plugin page was destroyed causing the call to be hung up (only the hung up party) |
| forceFromApp | Weixin Mini Program CallingforceHangUpVoipcauses hanging up call (hanging up party only) |
| other | The other person hung up the phone. |
| timeLimit | Exceeding the maximum call time |
# 7. endVoip
The call is over.
data parameter
| attribute | type | Introductions |
|---|---|---|
| keepTime | number | Duration of the call |
| callerName | string | Name of the caller |
| listenerName | string | Name of the receiver |
| roomType | string | Room Type |
| isCaller | boolean | Is it the caller? |
| businessType | number | Type of business |
# 8. busy
The call was not connected and the receiver occupied the line (triggered only by the caller).
# 9. calling
During the call, both parties trigger it every second.
data parameter
| attribute | type | Introductions |
|---|---|---|
| keepTime | number | Duration of the call |
# 10. timeout
The call went unanswered over time.
# 11. joinedRoomByCaller
The caller joined the room successfully (triggered only by the caller).
# 12. joinFailCaller
The caller failed to join the room (triggered only by the caller).
data parameter
| attribute | type | Introductions |
|---|---|---|
| errMsg | string | Error message |
| message | string | Data is an Error object in some cases due to backward compatibility |
# 13. joinFailListener
The receiver failed to join the room (triggered only by the receiver).
data parameter
| attribute | type | Introductions |
|---|---|---|
| errMsg | string | Error message |
| message | string | Data is an Error object in some cases due to backward compatibility |
# 14. finishVoip
The call was completed. Return the actual amount of time used in the settlement of this call.
It needs to be triggered after getting the final time from the background, and the trigger time is later than endVoip.
data parameter
| attribute | type | Introductions |
|---|---|---|
| keepTime | number | Settlement takes call time |
# 15. callPageOnShow
Plugin call page onShow.
# 16. showCustomBox
The user clicks the call page custom button to display the custom components.
data parameter
| attribute | type | Introductions |
|---|---|---|
| callerId | string | Dialing party ID |
| listenerId | string | Receiver Id |
# 17. hideCustomBox
The user hides the custom components.
data parameter
| attribute | type | Introductions |
|---|---|---|
| callerId | string | Dialing party ID |
| listenerId | string | Receiver Id |
# sample code
const wmpfVoip = requirePlugin('wmpf-voip').default
const offVoipEvent = wmpfVoip.onVoipEvent(event => {
console.info(`onVoipEvent`, event)
})
// Calls need to be invoked when listening is cancelled
offVoipEvent()