具有多个对等PeerJS
Having multiple peers PeerJS?
以下是我与PeerJS的连接代码:
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的peerjs音频聊天。
相关文章:
- 如何使用offer/answer交换来自两个对等连接的流
- Npm未满足对等依赖关系
- PeerJS自动重新连接
- Webrtc和socket.io:createanswer()总是有一个错误.为什么?我的代码连接了两个对等体,但其中只
- 具有多个对等PeerJS
- webrtc 中的多对等连接
- 使用WebRTC对等连接进行两个以上参与者的视频会议是否可行
- 浏览器的对等库
- 如何使用peerJS对等连接接收数据
- Webrtc.使用PeerJs的对等连接
- 节点网络套接字:1006远程对等方在谷歌Chrome上丢弃的连接
- 可视化来自远程对等连接的媒体流
- 窗口未使用对等.js定义
- 费罗斯的简单对等什么是代码示例
- 将peerjs与Adobe InDesign一起使用
- 如何在 GraphQL 中获取对等字段
- 为什么我的 PeerJS 音频聊天应用程序不起作用
- 未满足的对等依赖生成器-karma@>=0.9.0
- PeerJS 对等方未接收数据
- PeerJS或WebRTC对等连接是否需要服务器或仅在客户端之间