Component features

Updated at:

This topic describes component events and the features of the corresponding interfaces.

Audio and video call component

Component tag: rtc

Description: Use this component to access audio and video calls in Flex mode.

Component properties

Property name

Parameter type

Required

Default value

Description

config

Object

No

None

The Config object.

currentUserId

String

No

None

The user ID of the current user. Pass a user ID to this parameter to switch the content that is playing.

Component events

Event Name

Description

onPlayerChange

The event that is triggered when the user playback interface is switched.

onUserChange

A user change event.

onHangup

A hang-up event.

onError

A general error event.

Import the component

{
  "usingComponents": {
    "rtc": "plugin://rtc/flex"
  }
}

Use the component

<rtc
  config="{{ config }}"
  currentUserId="{{ currentUserId }}"
  onPlayerChange="handlePlayerChange"
  onUserChange="handleUserChange"
  onHangup="handleHangup"
  onError="handleError"
/>

Parameter descriptions

  • config For more information, see Key parameters.

  • currentUserId Pass a user ID to this parameter to switch the content that is currently playing.

  • onPlayerChange(userId: string, preUserId: string): void The event that is triggered when the playback switches to a different user.

  • onUserChange(state: UserState): void An event that is triggered when a user's state changes.

  • onError(error: Error): void An event that is triggered when a general error occurs.

  • onHangup(): void An event that is triggered when a user hangs up.

The UserState object

interface UserState {
  joined: string[]  // The list of users who have joined.
  exited: string[]  // The list of users who have left.
  users: string[]   // The list of users currently in the room.
  current?: string  // The user ID of the user whose content is playing.
}

For more information about the Config object, see Key parameters.

Interfaces

invite

Description: Invites a user to join the call. The input parameters are described in the following table.

Parameter

Parameter type

Required

Default value

Description

userId

String

No

None

The user ID.

Parameter name

Parameter type

Required

Default value

Description

inviteInfo

Object

No

None

The InviteInfo object.

The InviteInfo object is an optional parameter for the invite interface. This object describes the content that is displayed to the invited user.

interface InviteInfo {
  nickName?: string // The nickname of the inviter.
  page?: string // The landing page of the miniapp.
  inviteType?: InviteType // The type of the invited user. 0: web, 1: app. The default value is 1.
  roomType?: RoomType // The room type. 1: audio and video call, 2: audio-only call. The default value is 1.
  params?: Record<string, unknown> | null
}

join

Description: Joins a video call. The input parameters are described in the following table.

Parameter name

Parameter type

Required

Default value

Description

roomId

String

Yes

None

None

Parameter Name

Type

Required

Default value

Description

config

Object

No

None

The Config object. For more information, see Key parameters.

Response parameters

Parameter

Parameter type

Description

RoomInfo

Object

Promise

const { rtc } = requirePlugin('rtc')

// The user who joins the call invokes this API.
rtc.join(roomId, config) // The config parameter is required. For more information, see Key parameters.

Get RoomInfo

When a user initiates a video call, a RoomInfo object is returned. Other users can use this object to join the call. You can obtain the RoomInfo object in one of the following two ways.

  1. The join API returns a Promise<RoomInfo>.

    rtc.start(config).then(roomInfo => {
      const { roomId, token } = roomInfo
      // Obtain the created roomId and token for other users to join the call.
    })
  2. It is available in the ROOM_CREATED event.

    rtc.on(EventType.ROOM_CREATED, data => {
      // Obtain the roomId and token created by the initiator for other users to join the call.
      const { roomId, token } = data
    })

For more information about the Config object, see Key parameters.

on

Description: Listens for call events. The input parameters are described in the following table.

Parameter name

Parameter type

Required

Default value

Description

type

Object

No

None

The event type.

Parameter name

Parameter type

Required

Default value

Description

handler

Any

No

None

The callback function.

const { rtc, EventType } = requirePlugin('rtc')

rtc.on(EventType.ROOM_CREATED, data => {
  // Obtain the roomId and token created by the initiator for other users to join the call.
  const { roomId, token } = data
})

start

Description: Starts a video call. The input parameters are described in the following table.

Parameter name

Parameter type

Required

Default value

Description

config

Object

No

None

The Config object. For more information, see Key parameters.

Response parameters

Parameter name

Parameter type

Description

RoomInfo

Object

Promise

const { rtc } = requirePlugin('rtc')

// The initiator invokes this API.
rtc.start(config).then(roomInfo => {
  const { roomId, token } = roomInfo
  // Obtain the created roomId and token for other users to join the call.
})

For more information about the Config object, see Key parameters.