admin管理员组文章数量:1425669
Here is my code for connections with 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();
}
I borrrowed this code, and I was wondering it is possible to have multiple connections between peers, like a call group. My hypothesis is that all I would have to do is add a new audio object when the peer detects that a new person is calling, and then have it so the different users receive the ids of the other users and have audio objects added to their pages as well. Would this work? Is there a more efficient way to do it?
Here is my code for connections with 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();
}
I borrrowed this code, and I was wondering it is possible to have multiple connections between peers, like a call group. My hypothesis is that all I would have to do is add a new audio object when the peer detects that a new person is calling, and then have it so the different users receive the ids of the other users and have audio objects added to their pages as well. Would this work? Is there a more efficient way to do it?
Share Improve this question edited Mar 28, 2015 at 17:57 user3864563 asked Mar 23, 2015 at 19:22 user3864563user3864563 4051 gold badge9 silver badges22 bronze badges1 Answer
Reset to default 0A peer can maintain a list of out-ing streams. For example, when a peer connects to the system, then all the other peers will get informed, and save the id of this peer to their list. When a peer tries to start a call, it then will traverse all the peers in its list. One example you can check is the peerjs-audio-chat by Noah Burney.
本文标签: javascriptHaving multiple peers PeerJSStack Overflow
版权声明:本文标题:javascript - Having multiple peers PeerJS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745440118a2658408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论