How do i stream realtime audio from one client to possibly multiple clients with socket.io?
I got to the point where i can record audio and playback the audio in the same tab.
That's my current code for this:
$(document).ready(function () {
var socket = io("ws://127.0.0.1:4385");
if (navigator.mediaDevices) {
console.log('getUserMedia supported.');
var constraints = { audio: true };
navigator.mediaDevices.getUserMedia(constraints)
.then(function (stream) {
let ctx = new AudioContext();
let source = ctx.createMediaStreamSource(stream);
let destination = ctx.createMediaStreamDestination();
source.connect(ctx.destination);
})
.catch(function (err) {
console.log('The following error occurred: ' + err);
})
}
});
How do i send that audio stream to my socket.io server and then back to another client?
I heard about WebRTC, but i don't want a peer to peer solution as this would put load on the client, if there are multiple clients who want to listen to the audio.
Somehow there has to be a way to retrieve the raw audio data send it to my socket.io server which in turn sends it back to clients who want to listen to it.