Peerjs 多个查看器
Peerjs multiple viewers
我正在尝试在我的应用程序中设置会议模块。所以我找到并创建了两个用户之间的流。
问题是其他人无法加入
我一直在努力阅读他们的文档,但我似乎无法找到如何实现它。
这是我的代码:
// 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;
});
}
任何人都可以在正确的方向上推动我吗?
根据你的描述和代码,我会说你正试图在同一个电话中连接两个以上的用户。
这对于 WebRTC 是不可能的,它只允许您为每个对等连接连接两端。他们可以复制多会议行为的方式是为每对参与者创建不同的呼叫。
为此,每个参与者需要不同的 video
元素和一个用户列表,以便您知道每个参与者的 ID,您需要在您要加入的房间中呼叫。
PeerJS won't give you a mechanism to know the other ID's in the room/call 所以你需要找到一种让新参与者知道的机制。
我的 github 中有一个 AngularJS/Socket.io WebRTC 通信工具 example,请随意检查它并查看如何使用 WebRTC p2p 连接重现多方会议呼叫。
编辑:假设您的用户有某种 ID 并且您的程序的行为方式类似于 makeCall('Alice')
,假设当 Carol 呼叫 Alice 时 Alice 正在与 Bob 通话并且您希望 Carol 加入通话两者,您都可以在没有新信令层的情况下实现它:
- Alice 正在与 Bob 通话
- 卡罗尔给爱丽丝打电话
- 爱丽丝接听电话
- Alice 使用 DataChannel
将 Bob 的 ID 发送给 Carol
- 卡罗尔打电话给鲍勃
- Alice、Bob 和 Carol 正在通过逻辑三方通话相互交谈
我正在尝试在我的应用程序中设置会议模块。所以我找到并创建了两个用户之间的流。
问题是其他人无法加入
我一直在努力阅读他们的文档,但我似乎无法找到如何实现它。
这是我的代码:
// 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;
});
}
任何人都可以在正确的方向上推动我吗?
根据你的描述和代码,我会说你正试图在同一个电话中连接两个以上的用户。
这对于 WebRTC 是不可能的,它只允许您为每个对等连接连接两端。他们可以复制多会议行为的方式是为每对参与者创建不同的呼叫。
为此,每个参与者需要不同的 video
元素和一个用户列表,以便您知道每个参与者的 ID,您需要在您要加入的房间中呼叫。
PeerJS won't give you a mechanism to know the other ID's in the room/call 所以你需要找到一种让新参与者知道的机制。
我的 github 中有一个 AngularJS/Socket.io WebRTC 通信工具 example,请随意检查它并查看如何使用 WebRTC p2p 连接重现多方会议呼叫。
编辑:假设您的用户有某种 ID 并且您的程序的行为方式类似于 makeCall('Alice')
,假设当 Carol 呼叫 Alice 时 Alice 正在与 Bob 通话并且您希望 Carol 加入通话两者,您都可以在没有新信令层的情况下实现它:
- Alice 正在与 Bob 通话
- 卡罗尔给爱丽丝打电话
- 爱丽丝接听电话
- Alice 使用 DataChannel 将 Bob 的 ID 发送给 Carol
- 卡罗尔打电话给鲍勃
- Alice、Bob 和 Carol 正在通过逻辑三方通话相互交谈