Skip to main content
Version: 5.3

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.

const conferenceParams = {
myId: 'MY_ID',
myServiceId: 'MY_SERVICE_ID',
roomId: 'ROOM_ID',
roomServiceId: 'ROOM_SERVICE_ID',
accessToken: 'ACCESS_TOKEN',
mediaType: 'audio',
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) => {}
}
};

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.
});

Leave a group call

To leave a group call, call leaveConference().

planetKit.leaveConference();