A few viewers of Peerjs

I am trying to configure a conference module in my application. So I found and created a stream between two users.

The problem is that others cannot join.

I tried to read the documentation, but I cannot figure out how to implement it.

Here is my code:

    // Compatibility shim
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;

navigator.getUserMedia({audio: true, video: true}, function (stream) {
    // Set your video displays
    $('#my-video').prop('src', URL.createObjectURL(stream));
    window.localStream = stream;
}, function () {
    $('#step1-error').show();
});

peerFactory.on('error', function (err) {
    alert(err.message);
});

peerFactory.on('connection', function (id) {
    alert('new logon' + id);
});



// Receiving a call
peerFactory.on('call', function (call) {
    // Answer the call automatically (instead of prompting user) for demo purposes
    var r = confirm('Ny kald fra ');
    if (r) {
        call.answer(window.localStream);
        $scope.currentCall = true;
        $scope.$apply();
        streamCall(call);
    }
    else
    {
        call.close();
        window.existingCall.close();
    }
});

$scope.makeCall = function (callId) {
    var call = peerFactory.call(callId, window.localStream);
    $scope.currentCall = true;
    streamCall(call);
};

$scope.hangUp = function()
{
    $scope.currentCall = false;
    window.existingCall.close();
};

function streamCall(call) {
    // Hang up on an existing call if present
    if (window.existingCall) {
        window.existingCall.close();
    }

    // Wait for stream on the call, then set peerFactory video display
    call.on('stream', function (stream) {
        $('#their-video').prop('src', URL.createObjectURL(stream));
    });
    // UI stuff
    window.existingCall = call;
    $('#their-id').text(call.peerFactory);
    call.on('error', function () {
        var i = 0;
    });
}

Can someone give me a push in the right direction?

+4
source share
1 answer

According to your description and your code, I would say that you are trying to connect more than two users to the same call.

WebRTC, . , , .

video , , , , .

PeerJS /, .

github AngularJS/Socket.io WebRTC, , p2p WebRTC.

: , - , makeCall('Alice'), , , , , , :

+3

Source: https://habr.com/ru/post/1618597/


All Articles