Created
July 30, 2015 14:52
-
-
Save EricDavies/fe9e15d8b81bfa8479f9 to your computer and use it in GitHub Desktop.
This demonstrates using api fields in place of user names.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var selfEasyrtcid = ""; | |
function connect() { | |
easyrtc.setVideoDims(640,480); | |
easyrtc.setRoomOccupantListener(convertListToButtons); | |
easyrtc.easyApp("easyrtc.audioVideoSimple", "selfVideo", ["callerVideo"], loginSuccess, loginFailure); | |
} | |
function clearConnectList() { | |
var otherClientDiv = document.getElementById('otherClients'); | |
while (otherClientDiv.hasChildNodes()) { | |
otherClientDiv.removeChild(otherClientDiv.lastChild); | |
} | |
} | |
function convertListToButtons (roomName, data, isPrimary) { | |
clearConnectList(); | |
var otherClientDiv = document.getElementById('otherClients'); | |
for(var easyrtcid in data) { | |
var nameToUse = easyrtc.getRoomApiField("default", easyrtcid, "fakeUserName"); | |
if( !nameToUse ) continue; | |
var button = document.createElement('button'); | |
button.onclick = function(easyrtcid) { | |
return function() { | |
performCall(easyrtcid); | |
}; | |
}(easyrtcid); | |
var label = document.createTextNode(nameToUse); | |
button.appendChild(label); | |
otherClientDiv.appendChild(button); | |
} | |
} | |
function performCall(otherEasyrtcid) { | |
easyrtc.hangupAll(); | |
var successCB = function() {}; | |
var failureCB = function() {}; | |
easyrtc.call(otherEasyrtcid, successCB, failureCB); | |
} | |
var smurfNames = [ "dopey", "sneezy", "bashful", "grumpy", "doc", "happy", "sleepy"]; | |
function loginSuccess(easyrtcid) { | |
selfEasyrtcid = easyrtcid; | |
// timeout to simulate the delay in typing a name. | |
setTimeout(function() { | |
// pick a random name | |
var name = smurfNames[ (new Date()).getTime() % smurfNames.length]; | |
document.getElementById("iam").innerHTML = "I am " + name; | |
easyrtc.setRoomApiField("default", "fakeUserName", name); | |
}, 2000); | |
} | |
function loginFailure(errorCode, message) { | |
easyrtc.showError(errorCode, message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment