I need to have a real time live audio stream from 1 client to a server to multiple listener clients.
Currently I have the recording from the client working and stream t
I'm a bit late to the party here but it looks like the web audio API will be your friend here, if you haven't already finished it. It allows you to play an audio stream directly to the output device without messing around with attaching it to an audio element.
I'm looking at doing the same thing and your question has answered my question - how to get data from client to server. The benefit of the web audio API is the ability to add streams together and apply audio effects to it on the server.
MDN Web Audio API
The io events should replace the data in an audio buffer object in the audio context. Audio processing can happen in the nodeJS web audio context before being emitted as a single stream to each client.
You could change audio
src
dynamically as follows (assuming mp3 type):
<audio id="audio" controls="controls">
<source id="mp3Source" type="audio/mp3"></source>
Your browser does not support the audio format.
</audio>
Call following function whenever, socket event is received :
function updateSource() {
var audio = document.getElementById('audio');
var source = document.getElementById('mp3Source');
source.src= <blob>;
audio.load(); //call this to just preload the audio without playing
audio.play(); //call this to play the song right away
}