文档强调了:这个Echo测试演示只是盲目地发送给你回任何你发送给它。你基本上是附着在自己身上,所以你发送到网关的音频和视频就会回传给你。
onlocalstream: function(stream) {
Janus.debug(" ::: Got a local stream :::");
Janus.debug(JSON.stringify(stream));
if($('#myvideo').length === 0) {
$('#videos').removeClass('hide').show();
$('#videoleft').append('<video class="rounded centered" id="myvideo" width=320 height=240 autoplay muted="muted"/>');
}
Janus.attachMediaStream($('#myvideo').get(0), stream);
$("#myvideo").get(0).muted = "muted";
$("#videoleft").parent().block({
message: '<b>Publishing...</b>',
css: {
border: 'none',
backgroundColor: 'transparent',
color: 'white'
}
});
// No remote video yet
$('#videoright').append('<video class="rounded centered" id="waitingvideo" width=320 height=240 />');
if(spinner == null) {
var target = document.getElementById('videoright');
spinner = new Spinner({top:100}).spin(target);
} else {
spinner.spin();
}
var videoTracks = stream.getVideoTracks();
if(videoTracks === null || videoTracks === undefined || videoTracks.length === 0) {
// No webcam
$('#myvideo').hide();
$('#videoleft').append(
'<div class="no-video-container">' +
'<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
'<span class="no-video-text">No webcam available</span>' +
'</div>');
}
},
onremotestream: function(stream) {
Janus.debug(" ::: Got a remote stream :::");
Janus.debug(JSON.stringify(stream));
if($('#peervideo').length === 0) {
$('#videos').removeClass('hide').show();
$('#videoright').append('<video class="rounded centered hide" id="peervideo" width=320 height=240 autoplay/>');
// Show the video, hide the spinner and show the resolution when we get a playing event
$("#peervideo").bind("playing", function () {
$('#waitingvideo').remove();
$('#peervideo').removeClass('hide');
if(spinner !== null && spinner !== undefined)
spinner.stop();
spinner = null;
var width = this.videoWidth;
var height = this.videoHeight;
$('#curres').removeClass('hide').text(width+'x'+height).show();
if(adapter.browserDetails.browser === "firefox") {
// Firefox Stable has a bug: width and height are not immediately available after a playing
setTimeout(function() {
var width = $("#peervideo").get(0).videoWidth;
var height = $("#peervideo").get(0).videoHeight;
$('#curres').removeClass('hide').text(width+'x'+height).show();
}, 2000);
}
});
}
Janus.attachMediaStream($('#peervideo').get(0), stream);
var videoTracks = stream.getVideoTracks();
if(videoTracks === null || videoTracks === undefined || videoTracks.length === 0 || videoTracks[0].muted) {
// No remote video
$('#peervideo').hide();
$('#videoright').append(
'<div class="no-video-container">' +
'<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
'<span class="no-video-text">No remote video available</span>' +
'</div>');
}
// Enable audio/video buttons and bitrate limiter
audioenabled = true;
videoenabled = true;
$('#toggleaudio').click(
function() {
audioenabled = !audioenabled;
if(audioenabled)
$('#toggleaudio').html("Disable audio").removeClass("btn-success").addClass("btn-danger");
else
$('#toggleaudio').html("Enable audio").removeClass("btn-danger").addClass("btn-success");
echotest.send({"message": { "audio": audioenabled }});
});
$('#togglevideo').click(
function() {
videoenabled = !videoenabled;
if(videoenabled)
$('#togglevideo').html("Disable video").removeClass("btn-success").addClass("btn-danger");
else
$('#togglevideo').html("Enable video").removeClass("btn-danger").addClass("btn-success");
echotest.send({"message": { "video": videoenabled }});
});
$('#toggleaudio').parent().removeClass('hide').show();
$('#bitrate a').click(function() {
var id = $(this).attr("id");
var bitrate = parseInt(id)*1000;
if(bitrate === 0) {
Janus.log("Not limiting bandwidth via REMB");
} else {
Janus.log("Capping bandwidth to " + bitrate + " via REMB");
}
$('#bitrateset').html($(this).html()).parent().removeClass('open');
echotest.send({"message": { "bitrate": bitrate }});
return false;
});
if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox") {
$('#curbitrate').removeClass('hide').show();
bitrateTimer = setInterval(function() {
// Display updated bitrate, if supported
var bitrate = echotest.getBitrate();
//~ Janus.debug("Current bitrate is " + echotest.getBitrate());
$('#curbitrate').text(bitrate);
}, 1000);
}
},
找到了监听方法看源码没看懂是怎么调用的。想知道如果网关有这么一个转播服务,怎么将local和remote分开,提供服务的只现实local;接收服务怎么接收现实remote?这个一对多怎么实现?
不知道你解决了吗?!文档中有解决方案:
在
createOffer
或createAnswer
时候media
字段发送方设置接收方