Skip to content

Instantly share code, notes, and snippets.

@EricDavies
Created August 1, 2013 16:08
Show Gist options
  • Save EricDavies/6132815 to your computer and use it in GitHub Desktop.
Save EricDavies/6132815 to your computer and use it in GitHub Desktop.
Demonstration of using idToName
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/easyrtc/easyrtc.js"></script>
</head>
<body>
Your name: <input type="text" id="userName" />
<button id="connectButton" onclick="connect()">Connect to server</button><br>
Immediate list
<div id="otherUsersSpace">
</div>
Delayed list
<div id="otherUsersSpace2">
</div>
<script>
function connect() {
var userName = document.getElementById('userName').value;
if (!easyRTC.isNameValid(userName)) {
easyRTC.showError("BAD-USER-NAME", "illegal user name");
return;
}
easyRTC.setUserName(userName);
easyRTC.enableAudio(false);
easyRTC.enableVideo(false);
easyRTC.setLoggedInListener(showUsers);
easyRTC.connect("demo", function() {
console.log("connect successful");
}, function() {
easyRTC.showError("could not connect to server");
});
}
function showUsers(data) {
var displayedList = "";
for (easyrtcid in data) {
var name = easyRTC.idToName(easyrtcid);
displayedList = displayedList + " <button>" + name + "</button>";
}
document.getElementById("otherUsersSpace").innerHTML = displayedList;
// demonstrate we don't need to be inside the loggedInListeners for idToName to work.
setTimeout(function() {
var displayedList = "";
for (easyrtcid in data) {
var name = easyRTC.idToName(easyrtcid);
displayedList = displayedList + " <button>" + name + "</button>";
}
document.getElementById("otherUsersSpace2").innerHTML = displayedList;
}, 2000);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment