传入的视频流会附加在身体的底部。在我的HTML中,我有两个div:
<div id="myPublisherDiv" style="width:320px; height:240px; background-color:#ffffff"></div>
<div id="remoteVideo" style="width:320px; height:240px; background-color:#ffffff"></div>
这是我的javascript:
var remoteVideo = document.getElementById('remoteVideo');
var apiKey = "xxxx";
var sessionId = "xxxx";
var token = "xxxx";
var publisher = TB.initPublisher(apiKey, 'myPublisherDiv');
var session = TB.initSession(sessionId);
session.addEventListener('sessionConnected', function(e){
session.publish( publisher );
for (var i = 0; i < e.streams.length; i++) {
if (e.streams[i].connection.connectionId == session.connection.connectionId) {
return;
}
var div = document.createElement('div');
div.setAttribute('id', 'stream' + e.streams[i].streamId);
remoteVideo.appendChild(div);
session.subscribe(e.streams[i]);
}
});
session.addEventListener('streamCreated', function(e){
for (var i = 0; i < e.streams.length; i++) {
if (e.streams[i].connection.connectionId == session.connection.connectionId) {
return;
}
var div = document.createElement('div');
div.setAttribute('id', 'stream' + e.streams[i].streamId);
remoteVideo.appendChild(div);
session.subscribe(e.streams[i], div.id);
}
});
答案 0 :(得分:3)
在sessionConnected
事件处理程序中,您需要将div id传递给subscribe
函数。 (Documentation)
session.subscribe(e.streams[i], div.id);