Microphone Controls
rooomSpaces Viewer API microphone management for multiplayer virtual environments. Control voice chat, audio input, and communication features in 3D virtual spaces.
Manage microphone and voice communication features in multiplayer virtual spaces. These controls are essential for creating collaborative environments, virtual meetings, and social interactions within 3D spaces.
setMicrophoneMuteState
setMicrophoneMuteState(mute: boolean, [callback: Function])
Controls the mute state of the user's microphone for voice communication in the virtual space. This affects voice chat with other users in multiplayer environments.
Parameters:
mute: boolean-trueto mute the microphone,falseto unmute
// Mute the microphone
api.setMicrophoneMuteState(true, function(){
console.log('Microphone muted');
// Update UI to show muted state
updateMicrophoneButton(true);
});
// Unmute the microphone
api.setMicrophoneMuteState(false, function(){
console.log('Microphone unmuted');
// Update UI to show unmuted state
updateMicrophoneButton(false);
});isMicrophoneMuted
isMicrophoneMuted([callback: Function])
Returns the current mute state of the user's microphone. Use this to synchronize UI elements and check communication status.
api.isMicrophoneMuted(function(isMuted){
console.log('Microphone muted:', isMuted); // true/false
// Update UI based on current state
if (isMuted) {
showMicrophoneMutedIndicator();
} else {
showMicrophoneActiveIndicator();
}
});Voice Communication Examples
Toggle Microphone Control:
function toggleMicrophone() {
api.isMicrophoneMuted(function(currentlyMuted) {
// Toggle the current state
api.setMicrophoneMuteState(!currentlyMuted, function() {
console.log('Microphone toggled to:', !currentlyMuted ? 'muted' : 'unmuted');
updateMicrophoneUI(!currentlyMuted);
});
});
}
function updateMicrophoneUI(isMuted) {
const micButton = document.getElementById('mic-button');
micButton.textContent = isMuted ? '🔇 Unmute' : '🎤 Mute';
micButton.className = isMuted ? 'muted' : 'active';
}Meeting Controls Integration:
// Initialize microphone controls for a virtual meeting
function initializeMeetingControls() {
// Check initial microphone state
api.isMicrophoneMuted(function(isMuted) {
updateMeetingUI(isMuted);
});
// Set up microphone toggle button
document.getElementById('mic-toggle').addEventListener('click', toggleMicrophone);
}
function updateMeetingUI(isMuted) {
const statusIndicator = document.getElementById('mic-status');
statusIndicator.textContent = isMuted ? 'Microphone Off' : 'Microphone On';
statusIndicator.style.color = isMuted ? '#ff4444' : '#44ff44';
}Privacy and Permissions:
// Handle microphone permissions and privacy
function handleMicrophonePrivacy() {
// Always start with microphone muted for privacy
api.setMicrophoneMuteState(true, function() {
console.log('Microphone muted by default for privacy');
// Show user they can unmute when ready
showMicrophonePermissionPrompt();
});
}
function showMicrophonePermissionPrompt() {
const prompt = document.createElement('div');
prompt.innerHTML = `
<p>Click to enable your microphone for voice chat</p>
<button onclick="enableMicrophone()">Enable Microphone</button>
`;
document.body.appendChild(prompt);
}
function enableMicrophone() {
api.setMicrophoneMuteState(false, function() {
console.log('Microphone enabled by user');
hideMicrophonePermissionPrompt();
});
}Best Practices
Privacy First:
- Always start with microphone muted by default
- Provide clear visual indicators of microphone state
- Allow users to easily toggle microphone on/off
User Experience:
- Use clear visual and audio cues for microphone state
- Provide keyboard shortcuts for quick mute/unmute
- Consider push-to-talk functionality for better control
Multiplayer Considerations:
- Respect user privacy preferences
- Provide individual volume controls for other users
- Consider spatial audio for realistic voice positioning