1

传入的视频流被附加在身体的底部。在我的 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);
   }
});
4

1 回答 1

3

在您的sessionConnected事件处理程序中,您需要将 div id 传递给subscribe函数。(文档

session.subscribe(e.streams[i], div.id);
于 2013-07-11T22:54:21.050 回答