API Version: 6.5
<!doctype html>
<html>
<head>
<title>IPC Dialer</title>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<script src="https://pabx.hostname/api/wrapper_kphone.whtm"></script>
<style>
body {
font-family: 'Montserrat', sans-serif;
font-size: 12px;
}
video {
display: none;
}
</style>
</head>
<body>
<video id="phone" autoplay></video>
<input type="text" id="number" size="20" placeholder="Number to dial"></input>
<button type="button" id="call">Call</button>
<button type="button" id="hangup">Hangup</button>
<script src="calling.js"></script>
</body>
</html>
/api/wrapper_kphone.whtm
which automatically loads 3 libraries needed to use keevio phone. Also the use of a <video>
tag; The video tag is in fact a media tag and handles only audio streams in this example, so is hidden using a display: none;
CSS rule.login()
and startFeed()
calls have been run and this code is not included below (see Common sample code).document.getElementById()
to grab references to the various DOM elements that we need to use. This step can be done in numerous ways, using libraries such as jQuery, but the native browser methods are shown here./* Grab references to DOM elements */
var videoTag = document.getElementById('phone');
var numberTag = document.getElementById('number');
var callTag = document.getElementById('call');
var hangupTag = document.getElementById('hangup');
IPCortex.PBX.owned
array is our keevio phone line, and will call Device.enableRTC()
on that line to cause it to register and be able to make/take calls.<video>
tag. For the purposes of keeping this simple, we are ignoring all Call objects except the first one. This is done by providing a callback to run whenever the state of the Device changes (or is 'updated'). We must then filter the updates with an if
statement to determine when a mediaStream
is available and then try to attach it to the video tag using the attachMediaStream
function from our modified version of adapter.js
./* Grab the first owned device for the logged in user */
var myPhone = IPCortex.PBX.owned[0];
/* Assume the phone is a keevio phone and enable it for WebRTC */
myPhone.enableRTC();
/* Wait for new call events to arrive */
myPhone.addListener('update', function (device) {
/* If there are multiple calls, ignore all except the first */
if (device.calls.length > 0) {
/* If the call is up and has media, attach it to the video tag */
if (device.calls[0].remoteMedia && device.calls[0].state !== 'dead')
attachMediaStream(videoTag, device.calls[0].remoteMedia[0]);
}
});
hangup
button sends a hangup request to whatever appears to be the first call on the list. These methods use Device.dial()
and Call.hangup()
- Note that a call is started by dialing on a device, but that the call itself is used to hang-up.numberTag.addEventListener('keyup', function(e) {
/* Clean up input box content */
if ( numberTag.value.search(/[^0-9\*\#]/) != -1 )
numberTag.value = numberTag.value.replace(/[^0-9\*\#]/, '');
});
callTag.addEventListener('click', function(e) {
if ( !numberTag.value )
return;
myPhone.dial(numberTag.value);
numberTag.value = '';
e.preventDefault();
});
hangupTag.addEventListener('click', function(e) {
/* The hangup button hangs up the first call if it exists */
if (myPhone.calls.length > 0)
myPhone.calls[0].hangup();
});