这是我的opentok connect代码。如何知道其他用户何时连接或断开会话?所以我可以填充我的在线朋友列表,如社交网站。然后我可以和他们聊聊。
function connect() {
OT.on("exception", exceptionHandler);
// Un-comment the following to set automatic logging:
OT.setLogLevel(OT.DEBUG);
if (!(OT.checkSystemRequirements())) {
alert("You don't have the minimum requirements to run this application.");
} else {
session = OT.initSession(sessionId); // Initialize session
session.connect(apiKey, token);
// Add event listeners to the session
session.on('sessionConnected', sessionConnectedHandler);
session.on('sessionDisconnected', sessionDisconnectedHandler);
session.on('connectionCreated', connectionCreatedHandler);
session.on('connectionDestroyed', connectionDestroyedHandler);
session.on('streamCreated', streamCreatedHandler);
session.on('streamDestroyed', streamDestroyedHandler);
session.on("signal", signalEventHandler);
}
}
function sessionConnectedHandler(event) {
// i am connected .... do something after connected
document.getElementById("User_name").innerHTML = user_name;
document.getElementById("disconnectLink").style.display = 'block';
//startPublishing();
}
答案 0 :(得分:4)
每次用户连接时都会调用函数connectionCreatedHandler
,每次用户断开连接时都会调用connectionDestroyedHandler
。
对于具有“好友列表”功能的示例应用,请参阅Presence Kit。演示:http://presencekit-php.herokuapp.com/