我正在尝试在我的应用程序中设置一个会议模块。所以我在两个用户之间找到并创建了一个流。
问题是其他人无法加入。
我一直在尝试阅读他们的文档,但是我似乎无法找到如何实现它。
这是我的代码:
// 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;
});
}
Run Code Online (Sandbox Code Playgroud)
谁能给我一个正确的方向推动?
根据您的描述和代码,我想说您正在尝试在同一个呼叫中连接两个以上的用户。
这对于 WebRTC 是不可能的,它只允许您为每个对等连接连接两端。您可以复制多会议行为的方法是为每对参与者创建不同的呼叫。
为此,您需要video为每个参与者提供不同的元素和一个用户列表,以便您知道需要在您加入的房间中呼叫的每个参与者的 ID。
PeerJS 不会给你一个机制来知道房间/电话中的其他 ID所以你需要找到一种机制来让新参与者知道。
我的github 中有一个 AngularJS/Socket.io WebRTC 通信工具的示例,请随时检查它并了解如何使用 WebRTC p2p 连接重现多会议呼叫。
编辑:假设您的用户有某种 ID 并且您的程序的行为方式如下makeCall('Alice'),假设当 Carol 呼叫 Alice 时 Alice 正在与 Bob 通话,并且您希望 Carol 与两者一起加入通话,您可以在没有新信令的情况下实现这一点层:
| 归档时间: |
|
| 查看次数: |
3461 次 |
| 最近记录: |