The following is the entire JavaScript code used in our client application. This includes all the code to hook up the UI, connect to the signaling server, and initiate a WebRTC connection with another user:
var connection = new WebSocket('ws://localhost:8888'), name = ""; var loginPage = document.querySelector('#login-page'), usernameInput = document.querySelector('#username'), loginButton = document.querySelector('#login'), callPage = document.querySelector('#call-page'), theirUsernameInput = document.querySelector('#their- username'), callButton = document.querySelector('#call'), hangUpButton = document.querySelector('#hang-up'); callPage.style.display = "none"; // Login when the user clicks the button loginButton.addEventListener("click", function (event) { name = usernameInput.value; if (name.length > 0) { send({ type: "login", name: name }); } }); connection.onopen = function () { console.log("Connected...