
var vertoHandle;
var currentCall;

options = {
    user: "999",
    domain: "10.22.83.159",
    password:"tP1fJ94Q6NC7FcZ",
    socketUrl:"wss://pbx.elster.formular/rtc",
    ringFile:"sounds/bell_ring2.wav",
    stunServers: true
};

makeCallOptions = {
    // Extension to dial.
    destination_number: '80',
    caller_id_name: 'Test Guy',
    caller_id_number: options.user,
    outgoingBandwidth: 'default',
    incomingBandwidth: 'default',
    useVideo:true,
    mirrorInput:true,
    // Enable stereo audio.
    useStereo: true,
    // You can pass any application/call specific variables here, and they will
    // be available as a dialplan variable, prefixed with 'verto_dvar_'.
    userVariables: {
        // Shows up as a 'verto_dvar_email' dialplan variable.
        email: 'test@test.com'
    },
    // Use a dedicated outbound encoder for this user's video.
    // NOTE: This is generally only needed if the user has some kind of
    // non-standard video setup, and is not recommended to use, as it
    // dramatically increases the CPU usage for the conference.
    dedEnc: false,
    // Example of setting the devices per-call.
    //useMic: 'any',
    //useSpeak: 'any',
};


makeCallVideoParams = {
    // Dimensions of the video feed to send.
    minWidth: 320,
    minHeight: 240,
    maxWidth: 640,
    maxHeight: 480,
    // The minimum frame rate of the client camera, Verto will fail if it's
    // less than this.
    minFrameRate: 15,
    // The maximum frame rate to send from the camera.
    vertoBestFrameRate: 30,
};




/*
<select id="camera"></select>
<select id="micro"></select>
<select id="speeker"></select>
*/

function getDevices()
{
    $("#camera").append(new Option("No Camera", "none"));
    $.each($.verto.videoDevices, function (i, device) {
        $("#camera").append(new Option(device.label, device.id));
    });
    
    
    $("#micro").append(new Option("Do Not Specify", "any"));
    $.each($.verto.audioInDevices, function (i, device) {
        $("#micro").append(new Option(device.label, device.id));
    });
    
    
    $("#speeker").append(new Option("Do Not Specify", "any"));
    $.each($.verto.audioOutDevices, function (i, device) {
        $("#speeker").append(new Option(device.label, device.id));
    });
}

(function () {


    function makeCall() {
                
        vertoHandle.videoParams(makeCallVideoParams);
                
        currentCall = vertoHandle.newCall(makeCallOptions);
    };

    function hangupCall() {
        currentCall.hangup();
    };

    function answerCall() {
        currentCall.answer();
    };
    
    function changeVideoDevice()
    {
        makeCallOptions.useCamera = $("#camera").find(":selected").val();
    }
    
    function changeAudioOutputDevice() 
    {
        makeCallOptions.useSpeak = $("#speeker").find(":selected").val();
    }
    
    function changeAudioInputDevice()
    {
        makeCallOptions.useMic = $("#micro").find(":selected").val();
    }
    
    

})();