'use strict';
var cur_call = null;
var la = null;
var $display = $("#display");
var verto;
var ringing = false;
function display(msg) {
$("#calltitle").html(msg);
}
function clearLa() {
if (la) {
la.destroy();
la = null;
}
$("#conf").hide();
}
function goto_dialog(where) {
$.mobile.changePage("#dialog-" + where, {
role: "dialog"
});
}
function goto_page(where) {
$.mobile.changePage("#page-" + where);
}
var first_login = false;
var online_visible = false;
function online(on) {
if (on) {
$("#online").show();
$("#offline").hide();
first_login = true;
} else {
if (first_login && online_visible) {
goto_dialog("logout");
}
$("#online").hide();
$("#offline").show();
}
online_visible = on;
}
function check_vid() {
var use_vid = $("#use_vid").is(':checked');
return use_vid;
}
var callbacks = {
onMessage: function(verto, dialog, msg, data) {
switch (msg) {
case $.verto.enum.message.pvtEvent:
console.error("pvtEvent", data.pvtData.action);
if (data.pvtData) {
switch (data.pvtData.action) {
case "conference-liveArray-part":
clearLa();
break;
case "conference-liveArray-join":
$(".jsDataTable").width(check_vid() ? "650px" : "550px");
la = new $.verto.liveTable(verto, data.pvtData.laChannel, data.pvtData.laName, $('#example'), {
subParams: {
callID: dialog.callID
},
"onChange": function(obj, args) {
//var len = obj.asArray().length;
$("#mcount").text("Conference Members: " + " (" + obj.arrayLen() + " Total)");
},
"aaData": [],
"aoColumns": [{
"sTitle": "ID"
},
{
"sTitle": "Number"
},
{
"sTitle": "Name"
},
{
"sTitle": "Codec"
},
{
"sTitle": "Status",
"sWidth": check_vid() ? "300px" : "150px"
}],
"bAutoWidth": true,
"bDestroy": true,
"bSort": false,
"bInfo": false,
"bFilter": false,
"bLengthChange": false,
"bPaginate": false,
"iDisplayLength": 1000,
"oLanguage": {
"sEmptyTable": "The Conference is Empty....."
}
});
$("#conf").show();
break;
}
}
break;
case $.verto.enum.message.info:
$("#text").html("Message from: " + data.from + ":
" + "
" + data.body + ""); break; case $.verto.enum.message.display: var party = dialog.params.remote_caller_id_name + "<" + dialog.params.remote_caller_id_number + ">"; display("Talking to: " + dialog.cidString()); break; default: break; } }, onDialogState: function(d) { cur_call = d; if (d.state == $.verto.enum.state.ringing) { ringing = true; } else { ringing = false; } switch (d.state) { case $.verto.enum.state.ringing: display("Call From: " + d.cidString()); $("#ansbtn").click(function() { cur_call.answer({ useStereo: $("#use_stereo").is(':checked') }); $('#dialog-incoming-call').dialog('close'); }); $("#declinebtn").click(function() { cur_call.hangup(); $('#dialog-incoming-call').dialog('close'); }); goto_dialog("incoming-call"); $("#dialog-incoming-call-txt").text("Incoming call from: " + d.cidString()); if (d.params.wantVideo) { $("#vansbtn").click(function() { $("#use_vid").prop("checked", true); cur_call.answer({ useVideo: true, useStereo: $("#use_stereo").is(':checked') }); }); // the buttons in this jquery mobile wont hide .. gotta wrap them in a div as a workaround $("#vansdiv").show(); } else { $("#vansdiv").hide(); } break; case $.verto.enum.state.active: display("Talking to: " + d.cidString()); goto_page("incall"); break; case $.verto.enum.state.hangup: case $.verto.enum.state.destroy: clearLa(); goto_page("main"); cur_call = null; break; case $.verto.enum.state.held: break; default: display(""); break; } }, onWSLogin: function(v, success) { display(""); cur_call = null; ringing = false; if (success) { online(true); verto.subscribe("presence", { handler: function(v, e) { console.error("PRESENCE:", e); } }); if (!window.location.hash) { goto_page("main"); } } else { goto_page("login"); goto_dialog("login-error"); } }, onWSClose: function(v, success) { if ($('#online').is(':visible')) { display(""); online(false); } var today = new Date(); $("#errordisplay").html("Connection Error.