This repository has been archived on 2023-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
vn-softphone/static/js/event.js

189 lines
3.8 KiB
JavaScript

window.addEventListener('load', function() {
/**
* Make new call
*/
$('call').addEventListener('click', function(event) {
if (ua.sessionInstance && ua.sessionInstance.direction === 'incoming')
ua.sessionInstance.answer(options);
let number = $('callNumber').value;
$('callNumber').value = '';
if (number != '') {
Softphone.call(number);
} else {
notify('Introduce un destinatario para realizar la llamada');
}
event.preventDefault();
});
/**
* Reset call number field
*/
$('clear').addEventListener('click', function(event) {
$('callNumber').value = '';
audio.addTrack('reset');
audio.play();
event.preventDefault();
});
/**
* End a call
*/
$('callHangup').addEventListener('click', function(event) {
Softphone.hangup();
audio.addTrack('hangup');
audio.play();
event.preventDefault();
});
/* *
* Insert key on call field
*/
$('zero').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('one').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('two').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('three').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('four').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('five').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('six').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('seven').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('eight').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('nine').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('asterisk').addEventListener('click', padKey);
/**
* Insert key on call field
*/
$('pad').addEventListener('click', padKey);
/**
* Transfer current call
*/
$('callTransfer').addEventListener('click', function(event) {
let number = document.getElementById('callNumber').value;
if (number != '') {
Softphone.transfer(number);
}
event.preventDefault();
});
/**
* Hold current call
*/
$('callPause').addEventListener('click', function(event) {
if (Softphone.isOnHold()) {
Softphone.unhold();
} else {
Softphone.hold();
}
event.preventDefault();
});
/**
* Do not disturb
*/
$('doNotDisturb').addEventListener('click', function(event) {
event.preventDefault();
});
/**
* Call settings
*/
$('callConfig').addEventListener('click', function(event) {
event.preventDefault();
});
/**
* Change volume action
*/
$('volume').addEventListener('change', function(event) {
if (!ua.callInstance)
return;
ua.audioInstance.volume = this.value;
});
$('mic').addEventListener('click', function(event) {
if(Softphone.isMuted()) {
Softphone.unmute();
} else {
Softphone.mute();
}
event.preventDefault();
});
/**
* Pad keys
* @param {Object} event Event object
*/
function padKey(event) {
let key = event.target.innerHTML;
let keyName = event.target.id;
$('callNumber').value += key;
audio.addTrack(keyName);
audio.play();
event.preventDefault();
}
});
/**
* Prevent page reload without confirmation
*/
window.addEventListener("beforeunload", function (event) {
event.returnValue = "\o/";
});