Skip to content

Instantly share code, notes, and snippets.

@alochym01
Created June 1, 2018 02:30
Show Gist options
  • Save alochym01/c1e1730d38c5525784a3dc46298ad769 to your computer and use it in GitHub Desktop.
Save alochym01/c1e1730d38c5525784a3dc46298ad769 to your computer and use it in GitHub Desktop.
verto phone sample script for freeswitch
// http://lists.freeswitch.org/pipermail/freeswitch-users/2016-July/121412.html
// var myverto = new $.verto({yada: yada});
// myverto.hangup(); // hangup all active calls
// myverto.purge(); // probably not necessary but doesn't hurt. Cleans out
// table internally.
// myverto.logout(); // Disconnect WebSocket
(function() {
var vertoHandle, vertoCallbacks, destinationNumber, currentCall, ext, passExt;
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
ext = getParameterByName("ext");
passExt = getParameterByName("pass");
$.verto.init({}, bootstrap);
function bootstrap(status) {
console.log("extension: " + ext)
vertoHandle = new jQuery.verto({
login: ext + '@conference2.cibersys.com',
passwd: passExt,
socketUrl: 'wss://conference2.cibersys.com:9061',
ringFile: 'sounds/bell_ring2.wav',
tag: 'video-container', // specifying video tag in our html
deviceParams: {
useCamera: true, // asking for camera permissions and devices
useMic: true,
useSpeak: true
},
iceServers: true
}, vertoCallbacks);
document.getElementById("make-call").addEventListener("click", makeCall);
document.getElementById("answer-call").addEventListener("click", answerCall);
document.getElementById("hang-up-call").addEventListener("click", hangupCall);
document.getElementById("mute-call").addEventListener("click", muteCall);
document.getElementById("unmute-call").addEventListener("click", unmuteCall);
document.getElementById("mute-unmute-call").addEventListener("click", muteUnmuteCall);
document.getElementById("hold-call").addEventListener("click", holdCall);
document.getElementById("unhold-call").addEventListener("click", unholdCall);
document.getElementById("transfer-call").addEventListener("click", transferCall);
document.getElementById("muteVideo-call").addEventListener("click", muteVideoCall);
document.getElementById("unmuteVideo-call").addEventListener("click", unmuteVideoCall);
};
function makeCall() {
destinationNumber = prompt("Insert destination number");
if(destinationNumber) {
currentCall = vertoHandle.newCall({
destination_number: destinationNumber,
caller_id_name: "Test Guy",
caller_id_number: destinationNumber,
outgoingBandwidth: "default",
incomingBandwidth: "default",
useVideo: true, // telling verto to make a call with video support
mirrorInput: true, // telling verto to mirror user's webcam
useStereo: true,
useMic: true,
useSpeak: true,
dedEnc: false,
userVariables: {
avatar: "",
email: "test at test.com"
}
});
}
};
function answerCall() {
currentCall.answer({
useStereo: true,
useCamera: true,
useVideo: true,
useMic: true,
callee_id_name: "answer ponit",
callee_id_number: ext
});
};
function hangupCall() {
currentCall.hangup();
};
function muteCall() {
currentCall.setMute("off");
};
function unmuteCall() {
currentCall.setMute("on");
};
function muteVideoCall() {
currentCall.setVideoMute("off");
};
function unmuteVideoCall() {
currentCall.setVideoMute("on");
};
function muteUnmuteCall() {
currentCall.mute("toggle");
};
function holdCall() {
currentCall.hold();
};
function unholdCall() {
currentCall.unhold();
};
function transferCall() {
destinationNumber = prompt("Insert transfer destination number");
if(destinationNumber) {
currentCall.transfer(destinationNumber);
}
};
vertoCallbacks = {
onWSLogin: onWSLogin,
onWSClose: onWSClose,
onDialogState: onDialogState
};
function onWSLogin(verto, success) {
console.log('onWSLogin', success, verto);
};
function onWSClose(verto, success) {
console.log('onWSClose', success);
};
function onDialogState(dialog) {
console.debug('onDialogState', dialog);
if(!currentCall) {
currentCall = dialog;
}
if (currentCall.state.name == 'ringing') {
console.warn('onDialogState ringing', currentCall);
}
if (currentCall.state.name == 'new') {
console.warn('Someone is calling you, new!');
}
if (currentCall.state.name == 'requesting') {
console.warn('Someone is calling you, requesting!');
}
if (currentCall.state.name == 'recovering') {
console.warn('Someone is calling you, recovering!');
}
if (currentCall.state.name == 'active') {
//$scope.offLocalVideo();
console.warn('Someone is calling you, active!');
}
if (currentCall.state.name == 'held') {
console.warn('Someone is calling you, held!');
}
if (currentCall.state.name == 'purge') {
console.warn('Someone is calling you, purge!');
}
if (currentCall.state.name == 'early') {
console.warn('Someone is calling you, early!');
}
if (currentCall.state.name == 'answering') {
console.warn('Someone is calling you, answering!');
}
if (currentCall.state.name == 'hangup') {
//$scope.resetCall();
console.warn('Someone is calling you, hangup!');
//$scope.resetCall();
//console.log("sreamLocalVideo.getVideoTracks()", sreamLocalVideo.getVideoTracks()[0].stop());
//sreamLocalVideo.src=null;
}
if (currentCall.state.name == 'destroy') {
console.warn('Someone is calling you, destroy!');
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment