How to turn on and off video and audio

let cameraState = true;
let micState = true;

To turn on and off video, use the toggleVideo function.

function toggleVideo(){
	if(cameraState){
		WTSDK.Participant.disableVideo();
		cameraState = false;
		const video = document.getElementById('vide_control');
		video.classList.remove('vcam_on');
		video.classList.add('vcam_off');
	}else {
		WTSDK.Participant.enableVideo();
		cameraState = true;
		const video = document.getElementById('vide_control');
		video.classList.remove('vcam_off');
		video.classList.add('vcam_on');
	}
}

There is a similar function available for working with audio (toggleAudio).

function toggleAudio() {
	if(micState){
		WTSDK.Participant.disableAudio();
		micState = false;
		const video = document.getElementById('audio_control');
		video.classList.remove('mic_on');
		video.classList.add('mic_off');
	}else {
		WTSDK.Participant.enableAudio();
		micState = true;
		const video = document.getElementById('audio_control');
		video.classList.remove('mic_off');
		video.classList.add('mic_on');
	}
}

Last updated