open-easyrtc
Version:
Open-EasyRTC enables quick development of WebRTC
111 lines (88 loc) • 3.3 kB
JavaScript
var selfEasyrtcid = "";
var supportsRecording = easyrtc.supportsRecording();
function connect() {
if( !supportsRecording) {
window.alert("This browser does not support recording. Try chrome or firefox.");
} else {
document.getElementById("startRecording").disabled = false;
if( easyrtc.isRecordingTypeSupported("h264")) document.getElementById("useH264").disabled = false;
if( easyrtc.isRecordingTypeSupported("vp9")) document.getElementById("useVP9").disabled = false;
if( easyrtc.isRecordingTypeSupported("vp8")) document.getElementById("useVP8").disabled = false;
}
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 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) {
easyrtc.hangupAll();
var successCB = function() { };
var failureCB = function() {};
easyrtc.call(otherEasyrtcid, successCB, failureCB);
}
function loginSuccess(easyrtcid) {
selfEasyrtcid = easyrtcid;
document.getElementById("iam").innerHTML = "I am " + easyrtc.cleanId(easyrtcid);
}
function loginFailure(errorCode, message) {
easyrtc.showError(errorCode, message);
}
var selfRecorder = null;
var callerRecorder = null;
function startRecording() {
var selfLink = document.getElementById("selfDownloadLink");
selfLink.innerText = "";
selfRecorder = easyrtc.recordToFile( easyrtc.getLocalStream(),
selfLink, "selfVideo");
if( selfRecorder ) {
document.getElementById("startRecording").disabled = true;
document.getElementById("stopRecording").disabled = false;
}
else {
window.alert("failed to start recorder for self");
return;
}
var callerLink = document.getElementById("callerDownloadLink");
callerLink.innerText = "";
if( easyrtc.getIthCaller(0)) {
callerRecorder = easyrtc.recordToFile(
easyrtc.getRemoteStream(easyrtc.getIthCaller(0), null),
callerLink, "callerVideo");
if( !callerRecorder ) {
window.alert("failed to start recorder for caller");
}
}
else {
callerRecorder = null;
}
}
function endRecording() {
if( selfRecorder ) {
selfRecorder.stop();
}
if( callerRecorder ) {
callerRecorder.stop();
}
document.getElementById("startRecording").disabled = false;
document.getElementById("stopRecording").disabled = true;
}