<script>
var verto = null;
var cur_call = null;
    
var callbacks = {

    onMessage: function(verto, dialog, msg, data) {
        console.log("onMessage");
    },

    onDialogState: function(d) {
        console.log("onDialogState");
    },
    onWSLogin: function(v, success) {
        console.log("onWSLogin");
    },
    onWSClose: function(v, success) {
        console.log("onWSClose");
    },

    onEvent: function(v, e) {
        console.log("onEvent");
    }
};

function docall(targetNumber) {
    if (cur_call) {
        return;
    }

    cur_call = verto.newCall({
        destination_number: targetNumber,
        caller_id_name: "FreeSWITCH User",
        caller_id_number: "23",
        useVideo: true,
        useStereo: true
    });
}

function init()
{
    
    var login = "<?php echo  $login; ?>" + "@" + "<?php echo  $hostname; ?>";
    var passwd = "<?php echo $password; ?>";
    var socketUrl = "<?php echo $socketUrl; ?>";
    
    verto = new $.verto({
        login: login,
        passwd: passwd,
        socketUrl: socketUrl,
        tag: "webcam",
        ringFile: "sounds/bell_ring2.wav",
        videoParams: {
            "minWidth": "1280",
            "minHeight": "720",
	    "minFrameRate": 30
        },
	iceServers: false
    },callbacks);
    verto.login();
}
        
$(document).ready(function() {
    init();
});
</script>

<div class="container">
    <h1>Verto - Demo Application</h1>
    <video id="webcam" autoplay="autoplay"></video>
</div>

<?php
    $this->renderPartial("_dialpad");
?>
<script>
    $(".dialPad li").on("click", function()
    {
        if ($(this).hasClass("action")) {
            
            if ($(this).hasClass("action-clear")) {
                var currVal = $(".number").val();
                var tempVal = currVal.substring(0, currVal.length - 1);
                $(".number").val(tempVal);
                
            } else if($(this).hasClass("action-delete")) {
                $(".number").val("");
            } else if ($(this).hasClass("action-call")){
                docall($(".number").val());
            }
        } else {
            var digit = $(this).find("strong").text();
            $(".number").val($(".number").val() + digit);
        }
    });
</script>