It is August 2020 and I am new to WebRTC. I have followed the instructions found here and have successfully made both video and audio only calls with some additions to the code.
What I am having trouble about is modifying this code to make one-to-many or even many-to-many calls - video and audio only.
What I have started with so far is to replace [0] with [i]:
function handleTrackEvent(event) {
document.getElementById("received_video").srcObject = event.streams[0];
document.getElementById("hangup-button").disabled = false;
}
function handleTrackEvent(event, i) {
document.getElementById("received_video").srcObject = event.streams[i];
document.getElementById("hangup-button").disabled = false;
}
and initiate i at:
function handleUserlistMsg(msg) {
var i = 0;
var listElem = document.querySelector(".userlistbox");
while (listElem.firstChild) {
listElem.removeChild(listElem.firstChild);
}
msg.users.forEach(function(username) {
var item = document.createElement("li");
item.appendChild(document.createTextNode(username));
item.addEventListener("click", invite(event, i), false);
listElem.appendChild(item);
i++;
});
}
The problem I am running into in the console log is:
[10:00:17 AM] Error InvalidStateError: Failed to execute 'setRemoteDescription'
on 'RTCPeerConnection': Failed to set remote answer sdp: Called in wrong state: kStable
which to me says that I already have a connection to a peer
So, how do I make multiple connections one caller initiating many participants?