即使似乎没有在DOM中插入音频元素,也会听到音频。
场景:
问题:
应该发生什么:
Code for replicating the scenario
// <body>
// <script src="https://cdn.webrtc-experiment.com/RTCMultiConnection.js"></script>
// <button id="start">Start!</button>
// </body>
$('#start').click(function() {
var NO_MEDIA_SESSION = {video: false, audio: false, oneway: true};
var caller = new RTCMultiConnection('lets-try');
caller.session = NO_MEDIA_SESSION;
caller.dontAttachStream = true;
caller.onstream = function() { console.log("Got stream but not attaching") };
var receiver = new RTCMultiConnection('lets-try');
receiver.session = NO_MEDIA_SESSION;
receiver.dontAttachStream = true;
receiver.onstream = function() { console.log("Got stream but not attaching") };
caller.open();
receiver.connect();
receiver.onconnected = function() {
console.log("Connected!");
caller.addStream({audio: true});
}
});
我很感兴趣如何在没有音频DOM元素的情况下听到MediaStream?
如果有任何RTCMultiConnection专家回答,那么也许给我指出如何避免音频流可听? (我想获取信息流,并稍后自己附加)。
最佳答案
RTCMultiConnection会即时创建mediaElement
,以确保仅在媒体流开始流动时才触发onstream
事件。
connection.onstream = function(event) {
event.mediaElement.pause(); // or volume=0
// or
event.mediaElement = null;
// or
delete event.mediaElement;
};
更新:
使用以下代码段:
var connection = new RTCMultiConnection();
connection.session = {
data: true
};
btnOpenRoom.onclick = function() {
connection.open('roomid');
};
btnJoinRoom.onclick = function() {
connection.join('roomid');
};
btnAddAudioStream.onclick = function() {
connection.addStream({
audio: true
});
};
btnAddAudioVideoStream.onclick = function() {
connection.addStream({
audio: true,
video: true
});
};
关于html - 不带<audio>元素而听到的WebRTC音频(RTCMultiConnection),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25863543/