JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<script src="//code.bandwidth.com/bandwidth-stage-0.9.3.min.js"></script>
<audio id="remote-audio"></audio>
<div id="errorMessage">must set username/password</div>
<div id="wrapper">
<div id="incomingCall" style="display: none">
<div class="callInfo">
<h3>Incoming Call</h3>
<p id="incomingCallNumber">Unknown</p>
</div>
<div id="answer"> <i class="fa fa-phone"></i></div>
<div id="reject"> <i class="fa fa-phone"></i></div>
</div>
<div id="callStatus" style="display: none">
<div class="callInfo">
<h3 id="callInfoText">info text goes here</h3>
<p id="callInfoNumber">info number goes here</p>
</div>
<div id="hangUp"> <i class="fa fa-phone"></i>
</div>
<div id="answer" style="display: none"> <i class="fa fa-phone"></i>
</div>
<div id="reject" style="display: none"> <i class="fa fa-phone"></i>
</div>
</div>
<!---------TO FIELD---------------------------------------------------->
<!---------DIALPAD---------------------------------------------------->
<div id="inCallButtons" style="display: none">
<div id="dialPad">
<div class="dialpad-char" data-value="1" unselectable="on">1</div>
<div class="dialpad-char" data-value="2" unselectable="on">2</div>
<div class="dialpad-char" data-value="3" unselectable="on">3</div>
<div class="dialpad-char" data-value="4" unselectable="on">4</div>
<div class="dialpad-char" data-value="5" unselectable="on">5</div>
<div class="dialpad-char" data-value="6" unselectable="on">6</div>
<div class="dialpad-char" data-value="7" unselectable="on">7</div>
<div class="dialpad-char" data-value="8" unselectable="on">8</div>
<div class="dialpad-char"...
CSS
@charset"UTF-8";
/* CSS Document */
html, body {
margin: 0;
padding: 0;
font-family:'Open Sans', sans-serif;
color: #494949;
}
#wrapper {
width: 300px;
margin: 0 auto;
}
.callInfo {
width: 190px;
height: 70px;
float: left;
}
#connectedCall .callInfo {
width: 240px;
}
#dialPad div{
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
/*
Introduced in IE 10.
See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/
*/
-ms-user-select: none;
user-select: none;
}
.callInfo h3 {
color: #389400;
margin: 10px 0 10px 0;
}
.callInfo p {
margin: 0px 25px 0px 0px;
float: left;
}
#answer, #hangUp, #reject, #connectCall, #mute {
color: #FFF;
background-color: #389400;
width: 50px;
height: 50px;
float: right;
text-align: center;
font-size: 30px;
margin: 10px 0px 10px 0px;
border-radius: 25px 25px 25px 25px;
-moz-border-radius: 25px 25px 25px 25px;
-webkit-border-radius: 25px 25px 25px 25px;
cursor: pointer;
cursor: hand;
}
#mute:active, #connectCall:active, #reject:active, #hangUp:active, #answer:active {
background-color: #B6B6B6;
-webkit-box-shadow: 0px 1px 7px 2px rgba(0, 0, 0, 0.45);
-moz-box-shadow: 0px 1px 7px 2px rgba(0, 0, 0, 0.45);
box-shadow: 0px 1px 7px 2px rgba(0, 0, 0, 0.45);
border: none;
}
#hangUp, #reject {
-ms-transform: rotate(135deg);
/* IE 9 */
-webkit-transform: rotate(135deg);
/* Chrome, Safari, Opera */
transform: rotate(135deg);
}
#hangUp {
background-color: #A90002;
}
#reject {
background-color: #FFF;
color: #A90002;
margin-right: 10px;
}
#connectCall, #mute {
color: #FFF;
background-color: #389400;
width:260px;
height: 50px;
font-size: 30px;
text-align: center;
margin: 20px 20px 0px 20px;
border-radius: 5px 5px 5px 5px;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius:...
JavaScript
/*
* How To Use:
* 1. fill in valid credentials in the config below
* 2. run the JsFiddle and enjoy
*
* Known issues:
* - rejecting incoming call does not hang up remote phone
*/
var config = {
username: "",//TODO: set username
password: "",//TODO: set password
domain: "",//TODO: set domain
logLevel: "debug"
};
var phone;
if(config.username && config.password){
phone = BWClient.createPhone(config);
phone.register();
phone.on("incomingCall",function(incomingCall){
if(call){//hangup any existing call
call.hangup();
call=null;
}
call = incomingCall;
call.on("ended",function(){
call = null;
updateUI();
});
call.on("connected",updateUI);
updateUI();
});
}
var call;
updateUI();
$("#connectCall").click(function () {
var dest = $("#toField").val();
call = phone.call(dest);
call.setRemoteAudioElement(document.getElementById("remote-audio"));
call.on("connected", updateUI);
call.on("ended", function(){
call = null;
updateUI();
});
updateUI();
});
$('#answer').click(function(){
call.setRemoteAudioElement(document.getElementById("remote-audio"));
call.accept();
});
$('#reject').click(function(){
console.log("REJECT");
call.reject();
});
$("#hangUp").click(function(){
call.hangup();
call = null;
updateUI();
});
$("#mute").click(function(){
console.log("MUTE CLICKED");
if(call.getInfo().microphoneMuted){
call.unmute();
}else{
call.mute();
}
updateUI();
});
$("#toField").keypress(function(e){
if(e.which === 13){//enter
$("#connectCall").click();
}
});
$("#inCallButtons").on("click", ".dialpad-char", function (e) {
var $target = $(e.target);
var value = $target.data("value");
call.sendDtmf(value.toString());
});
function updateUI(){
if(config.username && config.password){
...