# function onVoipEvent(function listener)

# Function description

to monitor VoIP Call related events.Event binding needs to be completed before the call starts

Note: Do not use the onLoad、onShow Such as binding events in the life cycle, may be repeated because of multiple calls in the life cycle.

# parameter

# function listener

Event listener function

# Callback parameter

# Object event
attribute type Introductions Minimum version
eventName string Event name. Please refer to the following description.
roomId string Call the room number. except bindContactcallPageOnShow Provided outside the event 2.4.0
groupId string and roomId identical
Data Object Additional parameters for an event. Different fields for different events, please refer to the following description

# Return value

function

Cancels the listening function, cancels the event after the function call. This function has no parameters and no return value.

# Description of events

# 1. startVoip

Call started.

# 2. AbortVoip

Unusual interruption.

Data parameter

attribute type Introductions
keepTime number Length of call
status string Exception explaination, value see later
error Object Error object
error.errMsg Object Error message

status Value

status describe
abortByListener The call was interrupted due to an abnormal local end (triggered by the receiver)
abortByCaller The call is abnormally interrupted at the local end (triggered by the dialing party)
unknown Call interrupted abnormally on the other end

common errMsg

  • room status is abort: status = unknown, triggered when receiving an exception to the end call, which needs to be based on roomId Associated pair triggered AbortVoip Event to determine the true cause of the anomaly.
  • listener waitOtherToJoin timeout: status = abortByListener, after the receiver joins the room, the caller has not been successfully joined (may be due to slow network and other reasons) or abnormal exit, the receiver waits 20s Triggered after a timeout. At this time, it is recommended to analyze the situation of the receiving party to investigate.
  • call interrupted due to close passive float ball: After the user cuts the Mini Program into the background, the Mini Program floating window will be displayed, and the user will trigger the Mini Program by closing the floating window.
  • in comming call: Triggered when the Mini Program call is interrupted by another call.
  • call interrupted due to native reason: Usually due to a period of time during the call did not receive a packet (usually for network reasons), was kicked out of the room to interrupt the call.

# 3. hangOnVoip

The call is answered (only the receiver fires).

# 4. cancelVoip

The call is not connected, the caller cancels the call.

Data parameter

attribute type Introductions
status string Cancel the reason for the explanation, see the value of the following

status Value

status describe
manual The user clicks the Hang Up button to cancel the call. (Call only)
unloadCallPage The plugin page was destroyed causing the call to be cancelled. (Call only)
forceFromApp Mini Program call forceHangUpVoip Cancel the call. (Call only)
other The caller cancels the call. (Recipient only)

# 5. rejectVoip

The call is not connected and the receiver refuses to answer.

Data parameter

attribute type Introductions
status string The reason for rejection is explained, and the value is shown below.

status Value

status describe
manual The user clicks the Hang Up button on the interface to reject the call (the receiver only)
unloadCallPage The plugin page is destroyed causing calls to be refused (only the recipient)
forceFromApp Mini Program call forceHangUpVoip Reject call (Receiver only)
other The receiver refuses to answer (only the caller)

# 6. HangUpVoip

The call is connected, the dialing party/The receiver hangs up.

Data parameter

attribute type Introductions
keepTime number Length of call
status string Hang up side explanation, value see the following text
origin string Hang up reason explanation, value see later

status Value

status describe
endByListener Receiver hangs up
endByCaller Dialing party hangs up

origin Value

To maintain backward compatibility, hangUpVoip Event Additional Use origin Field provides specific information about the reason for the hang up.

origin describe
manual The user clicks the Hang Up button on the interface to hang up the call (hang up only)
unloadCallPage The plug-in page is destroyed causing the call to hang up (hang up only)
forceFromApp Mini Program call forceHangUpVoip Cause a hang up call (hang up party only)
other The other party hangs up the phone
timeLimit Exceeding maximum call duration

# 7. endVoip

Over and out.

Data parameter

attribute type Introductions
keepTime number Length of call
caller string Dialing party name
listenerName string Receiving Name
roomType string Type of room
isCaller boolean Is the dialing party
businessType number Type of business

# 8. busy

The call is not connected, the receiving party is busy (only the dialing party is triggered).

# 9. calling

During the call, Both sides trigger once a second.

Data parameter

attribute type Introductions
keepTime number Length of call

# 10. timeout

The call timed out.

# 11. joinedRoomByCaller

The caller joined the room successfully (only the caller triggers).

# 12. joinFailCaller

The caller failed to join the room (only the caller triggers).

Data parameter

attribute type Introductions
errMsg string Error message
message string For backward compatibility reasons, in some cases Data Is a Error object

# 13. joinFailListener

The listener failed to join the room (only the listener fires).

Data parameter

attribute type Introductions
errMsg string Error message
message string For backward compatibility reasons, in some cases Data Is a Error object

# 14. finishVoip

Call complete. Returns the actual length of time used to settle this call.

Need to get the final time from the background to trigger, the trigger time is later than endVoip.

Data parameter

attribute type Introductions
keepTime number Call duration for settlement

# 15. callPageOnShow

Plugin Call Page onShow。

# 16. showCustomBox

Users click the call page custom button to display custom components.

Data parameter

attribute type Introductions
callerId string Dialing party Id
listenerId string Receiving party Id

# 17. hideCustomBox

Users hide custom components.

Data parameter

attribute type Introductions
callerId string Dialing party Id
listenerId string Receiving party Id

# sample code

const wmpfVoip = requirePlugin('wmpf-voip' ).default
const offVoipEvent = wmpfVoip.onVoipEvent(event => {
  console.info(`onVoipEvent`, event)
})

// Call when you need to unlisten
offVoipEvent()