muaz-khan / WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
https://www.webrtc-experiment.com/
MIT License
11.72k stars 3.95k forks source link

Re-Join Broadcast Broke? #677

Open rayj00 opened 4 years ago

rayj00 commented 4 years ago

Scenario Scaleable Broadcasting using Chrome: Broadcaster, Viewer1, Viewer2, Viewer3. All viewers are seeing broadcast. Viewer1 leaves (close tab). Viewer2 and Viewer3 lose video.

Anyone else see this error?

xujingzhou commented 3 years ago

index.html: ` connection.onstream = function(event) { if (connection.isInitiator && event.type !== 'local') { return; }

if (!event.stream) {
    return;
}

connection.isUpperUserLeft = false;
videoPreview.srcObject = event.stream;
videoPreview.play();

videoPreview.userid = event.userid;

if (event.type === 'local') {
    videoPreview.muted = true;
}

if (connection.isInitiator == false && event.type === 'remote') {
    connection.dontCaptureUserMedia = true;
    connection.attachStreams = [event.stream];
    connection.sdpConstraints.mandatory = {
        OfferToReceiveAudio: false,
        OfferToReceiveVideo: false
    };

    connection.getSocket(function(socket) {
        socket.emit('can-relay-broadcast');

        connection.getAllParticipants().forEach(function(p) {
            if (p + '' != event.userid + '') {
                connection.replaceTrack(event.stream, p);
            }
        });
    });
}

}; `