Skip to content

Instantly share code, notes, and snippets.

@EricDavies
Created July 30, 2015 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricDavies/fe9e15d8b81bfa8479f9 to your computer and use it in GitHub Desktop.
Save EricDavies/fe9e15d8b81bfa8479f9 to your computer and use it in GitHub Desktop.
This demonstrates using api fields in place of user names.
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