你可以看到我想要做什么。
我想通过在 sessionId 下为他们提供单独的令牌来连接会话中的所有用户,以便他们可以查看彼此的流。但用户只能看到他们的 straming。我只需要在我的页面上为每个用户分配 div,并使用连接到任何特定 sessionId 的令牌。
这是用户只能看到他们的流媒体的代码
<script src="http://static.opentok.com/webrtc/v2.0/js/TB.min.js" ></script>
<script src="https://static.opentok.com/webrtc/v2.0/js/TB.min.js" ></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
var publisher;
var session;
var apiKey = "44686132";
var sessionId = "1_MX40NDY4NjEzMn4xMjcuMC4wLjF-V2VkIE1hciAxOSAyMDo1ODozNyBQRFQgMjAxNH4wLjAzMTA3MTAwN34";
var token = document.getElementById("<%= hdn1.ClientID %>").value;
publisher = TB.initPublisher(apiKey);
session = TB.initSession(sessionId);
session.connect(apiKey, token);
session.addEventListener("sessionConnected",
sessionConnectedHandler);
session.addEventListener("streamCreated",
streamCreatedHandler);
function sessionConnectedHandler(event) {
alert("sessionConnectedHandler");
subscribeToStreams(event.streams);
session.publish(publisher);
}
function subscribeToStreams(streams) {
if (stream.connection.connectionId
!= session.connection.connectionId) {
//var streams = event.streams;
for (var i = 0; i < streams.length; i++) {
var stream = streams[i];
var newDivId = "streams" + stream[i].streamId;
var newDiv = $('<div />', { id: newDivId });
$('body').append(newDiv);
if (stream.connection.connectionId
!= session.connection.connectionId) {
session.subscribe(stream[i], newDivId);
}
}
}
}
function streamCreatedHandler(event) {
subscribeToStreams(event.streams);
}
</script>