UNPKG

open-easyrtc

Version:

Open-EasyRTC enables quick development of WebRTC

92 lines (76 loc) 3.36 kB
// //Copyright (c) 2016, Skedans Systems, Inc. //All rights reserved. // //Redistribution and use in source and binary forms, with or without //modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE //IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE //ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE //LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR //CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF //SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN //CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //POSSIBILITY OF SUCH DAMAGE. // var selfEasyrtcid = ""; function connect() { easyrtc.setVideoDims(1280,720); easyrtc.enableDebug(false); easyrtc.setRoomOccupantListener(convertListToButtons); easyrtc.easyApp("easyrtc.videoChatHd", "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); button.className = "callbutton"; otherClientDiv.appendChild(button); } } function performCall(otherEasyrtcid) { easyrtc.hangupAll(); var acceptedCB = function(accepted, caller) { if( !accepted ) { easyrtc.showError("CALL-REJECTED", "Sorry, your call to " + easyrtc.idToName(caller) + " was rejected"); } }; var successCB = function() {}; var failureCB = function() {}; easyrtc.call(otherEasyrtcid, successCB, failureCB, acceptedCB); } function loginSuccess(easyrtcid) { selfEasyrtcid = easyrtcid; document.getElementById("iam").innerHTML = "I am " + easyrtc.cleanId(easyrtcid); } function loginFailure(errorCode, message) { easyrtc.showError(errorCode, message); } // Sets calls so they are automatically accepted (this is default behaviour) easyrtc.setAcceptChecker(function(caller, cb) { cb(true); } );