即使在DOM中似乎没有插入音频元素,也会听到音频。
设想情况:
问题:
应该发生什么:
复制场景的代码
// <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专家回答,那么也许可以告诉我如何避免音频流被听到?(我想弄到这条小溪,然后自己接上去)。
发布于 2014-09-16 08:22:26
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
});
};https://stackoverflow.com/questions/25863543
复制相似问题