Created
March 24, 2014 20:42
-
-
Save EricDavies/9748714 to your computer and use it in GitHub Desktop.
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.setRoomOccupantListener(convertListToButtons); | |
easyrtc.connect("easyrtc.audioVideo", 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 button = document.createElement('button'); | |
button.onclick = function(easyrtcid) { | |
return function() { | |
performCall(easyrtcid); | |
}; | |
}(easyrtcid); | |
var label = document.createTextNode(easyrtc.idToName(easyrtcid)); | |
button.appendChild(label); | |
otherClientDiv.appendChild(button); | |
} | |
} | |
function performCall(otherEasyrtcid) { | |
if (!easyrtc.getLocalStream()) { | |
easyrtc.initMediaSource(function() { | |
easyrtc.setVideoObjectSrc(document.getElementById("selfVideo"), easyrtc.getLocalStream()); | |
performCall(otherEasyrtcid); | |
}, failureCB); | |
} | |
else { | |
easyrtc.hangupAll(); | |
var successCB = function() { | |
}; | |
var failureCB = function() { | |
}; | |
easyrtc.call(otherEasyrtcid, successCB, failureCB); | |
} | |
} | |
function loginSuccess(easyrtcid) { | |
selfEasyrtcid = easyrtcid; | |
easyrtc.easyAppBody("selfVideo", ["callerVideo"]); | |
easyrtc.setAcceptChecker( | |
function(caller, helper) { | |
var i; | |
if (!easyrtc.getLocalStream()) { | |
easyrtc.initMediaSource( | |
function() { | |
easyrtc.setVideoObjectSrc(document.getElementById("selfVideo"), easyrtc.getLocalStream()); | |
helper(true); | |
}, | |
function() { | |
helper(false); | |
}); | |
} | |
else { | |
for (i = 0; i < numPEOPLE; i++) { | |
var video = getIthVideo(i); | |
if (videoIsFree(video)) { | |
helper(true); | |
return; | |
} | |
} | |
helper(false); | |
} | |
} | |
); | |
document.getElementById("iam").innerHTML = "I am " + easyrtc.cleanId(easyrtcid); | |
} | |
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