admin管理员组文章数量:1296393
I am trying to setup a conference module up in my application. So i found and created a stream between two users.
The problem is that others are not able to join in.
Ive been trying to read up on their documentation however i cannot seem to find 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 anyone give me a push in the right direction?
I am trying to setup a conference module up in my application. So i found and created a stream between two users.
The problem is that others are not able to join in.
Ive been trying to read up on their documentation however i cannot seem to find 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 anyone give me a push in the right direction?
Share Improve this question asked Dec 4, 2015 at 13:48 Marc RasmussenMarc Rasmussen 20.6k83 gold badges223 silver badges383 bronze badges1 Answer
Reset to default 10 +50According with your description and your code, I would say you are trying to connect more than two users in the same call.
This is not possible with WebRTC, it only allows you to connect two ends for each peer connection. They way you can replicate the multiconference behaviour is creating a different call per each pair of participants.
In order to do this, you will need different video
elements per each participant and a user list so you know each participant's id you need to call in the room you are joining.
PeerJS won't give you a mechanism to know the other ID's in the room/call so you will need to find out a mechanism to let the new participant know.
I have an example in my github of an AngularJS/Socket.io WebRTC munication tool, feel free to inspect it and see how multiconference calls are reproduced using WebRTC p2p connections.
Edit: Assuming your users have some kind of ID and the way your program behave is like makeCall('Alice')
, assuming Alice is in a call with Bob when Carol calls Alice and you want Carol to join the call with both, you can implement this without a new signaling layer:
- Alice is in a call with Bob
- Carol calls Alice
- Alice accepts call
- Alice sends Bob's id to Carol using DataChannel
- Carol calls Bob
- Alice, Bob and Carol are talking to each other in a logical threeway call
本文标签: javascriptPeerjs multiple viewersStack Overflow
版权声明:本文标题:javascript - Peerjs multiple viewers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618654a2388677.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论