Javascript OpenTok视频聊天
我使用opentok创建了在线教育视频门户。 有多少学生应该看老师的视频。此外,老师还将观看所有联网学生的视频。 使用以下代码,我可以阻止自己订阅:-Javascript OpenTok视频聊天,javascript,opentok,Javascript,Opentok,我使用opentok创建了在线教育视频门户。 有多少学生应该看老师的视频。此外,老师还将观看所有联网学生的视频。 使用以下代码,我可以阻止自己订阅:- function subscribeToStreams(streams) { for (var i = 0; i < streams.length; i++) { // Make sure we don't subscribe to ourself i
function subscribeToStreams(streams) {
for (var i = 0; i < streams.length; i++) {
// Make sure we don't subscribe to ourself
if (streams[i].connection.connectionId == session.connection.connectionId) {
return;
}
//if (streams[i].connection.connectionId != session.connection.connectionId) {
// Create the div to put the subscriber element in to
var container = document.getElementById('videoContainer');
var div = document.createElement('div');
var id = 'stream' + streams[i].streamId;
div.setAttribute('id', id);
container.appendChild(div);
// Subscribe to the stream
session.subscribe(streams[i], div.id);
div.style.width = '20%';
div.style.height = '20%';
div.style.left = '80%';
//}
}
}
函数subscribeTostream(流){
对于(变量i=0;i
我想阻止学生观看其他学生视频。
学生只能看到老师的视频
非常感谢您的帮助。
谢谢最好的方法是使用代币。假设您正在为每个用户生成一个令牌(您应该这样做),则必须通过设置connection\u data属性将数据放入每个用户的令牌中。我会将字符串“student”或“teacher”设置到令牌的连接数据中 在streamCreated事件中,您可以在事件处理程序中查找与流关联的连接数据:
event.stream.connection.data
在学生端,您可以简单地检查连接数据,以便在获取streamCreated事件时仅订阅教师的流:
function(e){
if( e.stream.connection.data == "teacher" ){
// Create the div to put the subscriber element in to
var container = document.getElementById('videoContainer');
var div = document.createElement('div');
var id = 'stream' + streams[i].streamId;
div.setAttribute('id', id);
container.appendChild(div);
// Subscribe to the stream
session.subscribe(streams[i], div.id);
}
}
在教师方面,他可以简单地订阅每个传入流
希望有帮助
祝你好运 发布会话时如何设置
stream.connection.data
。@akshaykumar6生成令牌时,可以设置绑定到令牌本身的一些数据。