Exported HTML5 works on localhost but not on remote server

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DouweRavers


I’m encountering a very strange bug concerning the web export.
I created a little audio visualization program which uses the microphone as audio input. The problem is when building the project and testing it on a local-host server it works as it should. But once I upload it to my little server in the basement and I open the program from there, I get an error when I start recording.

The error:

Uncaught TypeError: navigator.mediaDevices is undefined

Project build
For recording I simply use a AudioStreamPlayer with an AudioStreamMicrophone connected to a second bus which feeds back to the Master bus and has an SpectrumAnalyser effect.

The recording button has following code:

func _on_StartRecording_pressed():
	if recorder.playing:
		AudioServer.set_bus_mute(0, false)
		$UpperMenu/StartRecording.text = "Start Recording"
		AudioServer.set_bus_mute(0, true)
		$UpperMenu/StartRecording.text = "Stop Recording"

The working way (in ubuntu terminal):

douwe@Douwe-Laptop:~/Documents/Messing_with_code/godot_audiovisualizer/WebBuild$ python3 -m http.server

Serving HTTP on port 8000 ( ...

Then surfing to localhost:8000/ and everything works fine.

The not working way (also ubuntu terminal):
First zipping the folder in AudioVisualizer.zip

douwe@Douwe-Laptop:~/Documents/Messing_with_code/godot_audiovisualizer$ scp AudioVisualizer.zip douwe@douwco.com:~

douwe@Douwe-Laptop:~/Documents/Messing_with_code/godot_audiovisualizer$ ssh douwe@douwco.com

douwe@douwe-server:~$ unzip AudioVisualizer.zip 
Archive:  AudioVisualizer.zip
   creating: WebBuild/
  inflating: WebBuild/AudioVisualizer.html  
  inflating: WebBuild/AudioVisualizer.js  
  inflating: WebBuild/AudioVisualizer.pck  
  inflating: WebBuild/AudioVisualizer.png  
  inflating: WebBuild/AudioVisualizer.wasm  
 extracting: WebBuild/favicon.png 

douwe@douwe-server:~$ mv WebBuild/ AudioVisualizer

douwe@douwe-server:~$ sudo mv AudioVisualizer /var/www/html/

If I then go to www.douwco.com (domain to my little server) the site opens correctly until I press the record button which is when the error occurs.

If you have any suggestions towards finding a solution or know what is wrong, I will appreciate your help.

:bust_in_silhouette: Reply From: klaas

i think its a security issue with the browser. Most browser dont allow media support on unsecure http connections. You need to serve the files via https.
This restriction does not apply to localhost because localhost is allways trated as secure.

Ahhh that makes sense. Thank you. I will look into it.

DouweRavers | 2020-07-26 19:33