Browser's autoplay policy.

RoomClient.js inside _joinRoom function. There’s a comment that reads:

			// NOTE: Stuff to play remote audios due to browsers' new autoplay policy.
			//
			// Just get access to the mic and DO NOT close the mic track for a while.
			// Super hack!
			{
				const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
				const audioTrack = stream.getAudioTracks()[0];

				audioTrack.enabled = false;

				setTimeout(() => audioTrack.stop(), 120000);
			}

If someone knows what the comment means that would be really great. Because as far as I know, the browser won’t let you play any audio unless the audio happens in response to a user gesture, that is basically what the autoplay policy is. I would be interested in knowing what part does getting user’s microphone play.

Thanks.

That’s not playing any audio but just requesting mic permission, so after that, audio elements (for remote peers) are allowed to play sound.

1 Like

Alright. Does that mean removing this will mute all remote audio and we won’t be able to hear the PeerViews of participants?

I mean including the new ones that are created when someone joins.

Thanks @ibc. I just found this: https://webrtchacks.com/autoplay-restrictions-and-webrtc/ it has what you say. :+1:

1 Like