'use strict';
var cur_call = null;
var confMan = null;
var $display = $("#display");
var verto;
var ringing = false;
function display(msg) {
$("#calltitle").html(msg);
}
function clearConfMan() {
if (confMan) {
confMan.destroy();
confMan = 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":
clearConfMan();
break;
case "conference-liveArray-join":
clearConfMan();
confMan = new $.verto.confMan(verto, {
tableID: "#conf_list",
statusID: "#conf_count",
mainModID: "#conf_mod",
displayID: "#conf_display",
dialog: dialog,
hasVid: check_vid(),
laData: data.pvtData
});
$("#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.early: case $.verto.enum.state.active: display("Talking to: " + d.cidString()); goto_page("incall"); break; case $.verto.enum.state.hangup: case $.verto.enum.state.destroy: clearConfMan(); 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.