[英]OpenTok video chat
我使用opentok創建了在線教育視頻門戶。 學生人數應看老師的視頻。 老師還將看到所有相關學生的視頻。 使用下面的代碼,我可以阻止自己訂閱:-
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%';
//}
}
}
我想防止學生觀看其他學生視頻。 學生只能看老師的視頻。
幫助將不勝感激。 謝謝
最好的方法是使用令牌。 假設您正在為每個用戶生成令牌(應該這樣做),則必須通過設置connection_data屬性將數據放入每個用戶的令牌中。 Ruby中的示例 。 我會將字符串“ student”或“ teacher”設置為令牌的connection_data。
在streamCreated事件上,您可以在事件處理程序中查找與流關聯的connection_data: 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);
}
}
在老師方面,他可以簡單地訂閱每個傳入的流。
希望能有所幫助,
祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.