Skip to main content
Version: 6.0

Group audio call

This page provides a code example for implementing a group audio call.

Prerequisites

Before you begin, you must do the following:

Implement an audio element

Prepare an audio element to play group audio in a group audio call.

<html>
<div>
<audio id="room-audio" autoplay></audio>
</div>
</html>

<script>
const roomAudioElement = document.getElementById('room-audio');
</script>

Join a group call

Create a ConferenceParams object for creating and setting up the group call.

  • The local user's initial audio state can be set with micOn of ConferenceParams.
    • The default value of micOn is true.
    • If micOn is set to false, the microphone is not activated and audio is not transmitted at the start of the call. The local user's audio can be transmitted by calling muteMyAudio(false) after the call is connected.
const conferenceParams = {
myId: 'MY_ID',
myServiceId: 'MY_SERVICE_ID',
roomId: 'ROOM_ID',
roomServiceId: 'ROOM_SERVICE_ID',
accessToken: 'ACCESS_TOKEN',
mediaType: 'audio',
micOn: false,
mediaHtmlElement: {
roomAudio: roomAudioElement
},
delegate: {
// For each of the following, add your own implementation or assign an event handler that matches the signature
evtConnected: () => {},
evtDisconnected: (disconnectedParam) => {},
evtMyAudioMuted: () => {},
evtMyAudioUnmuted: () => {}
}
};

Call joinConference() with the ConferenceParams object. If the call to joinConference() fails, you can determine the cause of failure in the following two cases.

  • If the call connection attempt fails
    • You can determine the cause of failure by checking START_FAIL_REASON in JoinConferenceError returned by Promise.reject().
  • If the call fails after connection
    • After the call is connected, you can determine the cause of failure through the evtDisconnected event of ConferenceParams.delegate. For more information about the reason for the call disconnection, see Disconnect reason.
planetKit.joinConference(conferenceParams)
.then(() => {
// Successfully joined a conference
})
.catch((joinConferenceError) => {
// Failed to join a conference
// joinConferenceError.reason: START_FAIL_REASON
// joinConferenceError.message: A descriptive message about the failure.
});

Check the local user's media status (Optional)

The evtMyAudioMuted and evtMyAudioUnmuted callbacks registered in the delegate are called when the local user's audio is muted or unmuted. You can use these events for UI updates and similar purposes.

Calling getMyMediaStatus() returns the current media status of the local user immediately (returns undefined if the call is not connected).

const status = planetKit.getMyMediaStatus();
if (status) {
// status.isMyAudioMuted: Whether the local user's audio is muted
}

Leave a group call

To leave a group call, call leaveConference().

planetKit.leaveConference();