Mute sharing and control
Mute refers to disabling the transmission of audio captured by the microphone. You can mute or unmute local audio and share your application's mute status with peers. You can also request a specific peer or all peers to mute or unmute their audio.
Prior to PlanetKit 6.0, muting did not directly affect the operation of microphone. Starting with PlanetKit 6.0, however, the microphone is controlled by muting as follows:
- When you mute the local audio, PlanetKit turns off the microphone and disables audio transmission, making the microphone indicator turned off.
- When you unmute the local audio, PlanetKit turns on the microphone and enables audio transmission, making the microphone indicator turned on.
Control and share local audio mute
This section explains how to mute or unmute local audio by call type.
1-to-1 call
To mute or unmute local audio in 1-to-1 calls, use MuteMyAudio(). The changes in the mute status of local audio are sent to peers through OnPeerMicMuted or OnPeerMicUnmuted.
The following diagram shows the flow of muting and unmuting local audio in a 1-to-1 call.
Related sample code is as follows.
Muting or unmuting local audio
// bMute: true for mute, false for unmute
void MuteMyAudioExample(PlanetKit::PlanetKitCallPtr pCall, bool bMute)
{
std::wcout << L"MuteMyAudio(bMute=" << (bMute ? L"true" : L"false") << L")" << std::endl;
pCall->MuteMyAudio(bMute, nullptr, [](void*, bool bSuccess) {
std::wcout
<< L") result: " << (bSuccess ? L"true" : L"false")
<< std::endl;
});
}
Handling related events on the peer side
class CallEventListener : public PlanetKit::ICallEvent {
public:
...
void OnPeerMicMuted(PlanetKitCallPtr pPlanetKitCall) override {
// This is called when the peer changed their microphone status to be muted.
// Write your own code here.
}
void OnPeerMicUnmuted(PlanetKitCallPtr pPlanetKitCall) override {
// This is called when the peer changed their microphone status to be unmuted.
// Write your own code here.
}
}
Group call
To mute or unmute local audio in group calls, use MuteMyAudio(). The changes in the mute status of local audio are sent to peers through OnPeersMicMuted or OnPeersMicUnmuted.
The following diagram shows the flow of muting and unmuting local audio in a group call.
Related sample code is as follows.
Muting or unmuting local audio
// bMute: true for mute, false for unmute
void MuteMyAudioExample(PlanetKit::PlanetKitConferencePtr pConference, bool bMute)
{
std::wcout << L"MuteMyAudio(bMute=" << (bMute ? L"true" : L"false") << L")" << std::endl;
pConference->MuteMyAudio(bMute, nullptr, [](void*, bool bSuccess) {
std::wcout
<< L") result: " << (bSuccess ? L"true" : L"false")
<< std::endl;
});
}
Handling related events on the peer side
class ConferenceEventListener : public PlanetKit::IConferenceEvent {
public:
...
void OnPeersMicMuted(PlanetKitConferencePtr pPlanetKitConference, const PeerArray& peerArray) override {
// This is called when one or more peers changed their microphone status to be muted.
// Write your own code here.
}
void OnPeersMicUnmuted(PlanetKitConferencePtr pPlanetKitConference, const PeerArray& peerArray) override {
// This is called when one or more peers changed their microphone status to be unmuted.
// Write your own code here.
}
}
Request remote audio mute
This section explains how to request muting or unmuting of remote audio by call type.
Whether the peers need to mute or unmute their audio when they get a request is implementation-dependent.
The following examples assume that the peers will mute or unmute their audio according to the request.
1-to-1 call
To request a peer to mute or unmute in 1-to-1 calls, use RequestPeerMute(). This request is sent to the peer through OnReceivedMuteMyAudioRequest, and changes in the mute status of remote audio are sent to the local user through OnPeerMicMuted or OnPeerMicUnmuted.
The following diagram shows the flow of requesting to mute and unmute remote audio in a 1-to-1 call.
Related sample code is as follows.
Requesting to mute or unmute remote audio
// bMute: true for mute, false for unmute
void RequestPeerMuteExample(PlanetKit::PlanetKitCallPtr pCall, bool bMute)
{
std::wcout << L"RequestPeerMute(bMute=" << (bMute ? L"true" : L"false") << L")" << std::endl;
pCall->RequestPeerMute(bMute, nullptr, [](void*, bool bSuccess) {
std::wcout
<< L") result: " << (bSuccess ? L"true" : L"false")
<< std::endl;
});
}
Handling related events on the peer side
class CallEventListener : public PlanetKit::ICallEvent {
public:
...
// This is called when the peer requests the local user to mute or unmute the microphone.
void OnReceivedMuteMyAudioRequest(PlanetKitCallPtr pPlanetKitCall, bool bEnableMute) override {
std::wcout << L"MuteMyAudio(bMute=" << (bEnableMute ? L"true" : L"false") << L")" << std::endl;
pPlanetKitCall->MuteMyAudio(bEnableMute, nullptr, [](void*, bool bSuccess) {
std::wcout
<< L") result: " << (bSuccess ? L"true" : L"false")
<< std::endl;
});
}
}
Group call
In group calls, you can request a specific peer or all peers to mute or unmute their audio.
- To request a specific peer to mute or unmute one's own audio, use
RequestPeerMute(). - To request all peers to mute or unmute their audio, use
RequestPeersMute().
These requests are sent to peers through OnReceivedMuteMyAudioRequest and the changes in the mute status of remote audio are sent to the local user through OnPeersMicMuted or OnPeersMicUnmuted.
The following diagram shows the flow of requesting to mute and unmute remote audio in a group call.
Related sample code is as follows.
Requesting to mute or unmute remote audio
// Request mute for single peer
// bMute: true for mute, false for unmute
void RequestPeerMuteExample(PlanetKit::PlanetKitConferencePtr pConference, PlanetKit::UserIdPtr pPeerId, bool bMute)
{
std::wcout << L"RequestPeerMute(bMute=" << (bMute ? L"true" : L"false") << L")" << std::endl;
pConference->RequestPeerMute(pPeerId, bMute, nullptr, [](void*, bool bSuccess) {
std::wcout
<< L") result: " << (bSuccess ? L"true" : L"false")
<< std::endl;
});
}
// Request mute for all peers
// bMute: true for mute, false for unmute
void RequestPeersMuteExample(PlanetKit::PlanetKitConferencePtr pConference, bool bMute)
{
std::wcout << L"RequestPeersMute(bMute=" << (bMute ? L"true" : L"false") << L")" << std::endl;
pConference->RequestPeersMute(bMute, nullptr, [](void*, bool bSuccess) {
std::wcout
<< L") result: " << (bSuccess ? L"true" : L"false")
<< std::endl;
});
}
Handling related events on the peer side
class ConferenceEventListener : public PlanetKit::IConferenceEvent {
public:
...
// This is called when the peer requests the local user to mute or unmute the microphone.
void OnReceivedMuteMyAudioRequest(PlanetKitConferencePtr pPlanetKitConference, PeerPtr pPeer, bool bEnableMute) override {
std::wcout << L"MuteMyAudio(bMute=" << (bEnableMute ? L"true" : L"false") << L")" << std::endl;
pPlanetKitConference->MuteMyAudio(bEnableMute, nullptr, [](void*, bool bSuccess) {
std::wcout
<< L") result: " << (bSuccess ? L"true" : L"false")
<< std::endl;
});
}
}
Related API
APIs related to mute sharing and control are as follows.
1-to-1 call
Methods
Events
Group call
Methods
-
PlanetKitConference::MuteMyAudio() -
PlanetKitConference::RequestPeerMute() -
PlanetKitConference::RequestPeersMute()