Javascript 有多个对等点?

Javascript 有多个对等点?,javascript,audio,peerjs,Javascript,Audio,Peerjs,以下是我与PeerJ连接的代码: var peer = new Peer({ key: '[PeerJSID]', debug: 3}); peer.on('open', function(){ $('#my-id').text(peer.id); }); // Receiving a call peer.on('call', function(call){ // Answer the call automatically (instead of prompting user) for

以下是我与PeerJ连接的代码:

var peer = new Peer({ key: '[PeerJSID]', debug: 3});
peer.on('open', function(){
  $('#my-id').text(peer.id);
});
// Receiving a call
peer.on('call', function(call){
  // Answer the call automatically (instead of prompting user) for demo purposes
  call.answer(window.localStream);
  step3(call);
});
peer.on('error', function(err){
  alert(err.message);
  // Return to step 2 if error occurs
  step2();
});
// Click handlers setup
$(function(){
  $('#make-call').click(function(){
    // Initiate a call!
    var call = peer.call($('#callto-id').val(), window.localStream);
    step3(call);
  });
  $('#end-call').click(function(){
    window.existingCall.close();
    step2();
  });
  // Retry if getUserMedia fails
  $('#step1-retry').click(function(){
    $('#step1-error').hide();
    step1();
  });
  // Get things started
  step1();
});
function step1 () {
  // Get audio stream
  navigator.getUserMedia({audio: true, video: false}, function(stream){
    // Set your video displays
    $('#my-video').prop('src', URL.createObjectURL(stream));
    window.localStream = stream;
    step2();
  }, function(){ $('#step1-error').show(); });
}
function step2 () {
  $('#step1, #step3').hide();
  $('#step2').show();
}
function step3 (call) {
  // Wait for stream on the call, then set peer video display
  call.on('stream', function(stream){
    $('#their-video').prop('src', URL.createObjectURL(stream));
  });
  // UI stuff
  window.existingCall = call;
  $('#their-id').text(call.peer);
  call.on('close', step2);
  $('#step1, #step2').hide();
  $('#step3').show();
}

我读了这段代码,我想知道对等点之间是否可能有多个连接,比如呼叫组。我的假设是,我所要做的就是在对等方检测到一个新用户正在呼叫时添加一个新的音频对象,然后让它让不同的用户接收其他用户的ID,并将音频对象添加到他们的页面中。这样行吗?有更有效的方法吗?

对等方可以维护输出流的列表。例如,当一个对等方连接到系统时,所有其他对等方都会得到通知,并将该对等方的id保存到其列表中。当一个对等方尝试启动呼叫时,它将遍历其列表中的所有对等方。您可以查看的一个示例是Noah Burney的