0
votes

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?

1
i think you need to connect to a server and the service relays it to multiple clients - Daniel A. White
Yeah I hadn't thought of that - I am connecting to a server - but Ineed to make the server do the connecting, not the client. all the code I posted is client-side. Thanks @Daniel - richardwhitney

1 Answers

0
votes

my solution to this problem was solved by scrapping the raw webRTC and using https://jitsi.org This software is private, customizable and reliable on my own server.