我已经使用 API 密钥、会话和令牌(用于发布者)为 OpenTok 设置了一个基本测试页面。以QuickStart为基础,添加了用于跟踪micLevelChanged事件的代码。页面代码可在此处获得。重要的几行是:
var apiKey = "API KEY HERE";
var sessionId = "SESSION ID HERE";
var token = "TOKEN HERE";
function sessionConnectedHandler(event) {
session.publish(publisher);
subscribeToStreams(event.streams);
}
function subscribeToStreams(streams) {
for (var i = 0; i < streams.length; i++) {
var stream = streams[i];
if (stream.connection.connectionId != session.connection.connectionId) {
session.subscribe(stream);
}
}
}
function streamCreatedHandler(event) {
subscribeToStreams(event.streams);
TB.log("test log stream created: " + event);
}
var pubProps = { reportMicLevels: true };
var publisher = TB.initPublisher(apiKey, null, pubProps);
var session = TB.initSession(sessionId);
session.publish(publisher);
session.addEventListener("sessionConnected", sessionConnectedHandler);
session.addEventListener("streamCreated", streamCreatedHandler);
session.addEventListener("microphoneLevelChanged", microphoneLevelChangedHandler);
session.connect(apiKey, token);
function microphoneLevelChangedHandler(event) {
TB.log("The microphone level for stream " + event.streamId + " is: " + event.volume);
}
我知道日志记录有效,因为日志从streamCreatedHandler
. 但是,我没有在microphoneLevelChangedHandler
函数中记录任何事件。我已经尝试过让一个和两个客户端加载页面(视频显示得很好)。
我需要做什么才能让microphoneLevelChanged
事件出现?