Group audio call
This page provides a code example for implementing a group audio call.
Prerequisites
Before you begin, you must do the following:
- Initialize WebPlanetKit.
- Get a proper access token.
- Check the overall API usage flow in Group call flow.
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
micOnofConferenceParams.- The default value of
micOnistrue. - If
micOnis set tofalse, 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 callingmuteMyAudio(false)after the call is connected.
- The default value of
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_REASONinJoinConferenceErrorreturned byPromise.reject().
- You can determine the cause of failure by checking
- If the call fails after connection
- After the call is connected, you can determine the cause of failure through the
evtDisconnectedevent ofConferenceParams.delegate. For more information about the reason for the call disconnection, see Disconnect reason.
- After the call is connected, you can determine the cause of failure through the
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();