/* global webphone_api.$, common */
// Call page
webphone_api._call = (function ()
{
var calltype = '';
var callnumber = '';
var showcallfwd = false; // dislplay call forward option in menu: callforward csak bejovo hivas ring-nel
var showignore = false;
var hanguponchat = false; //-- bejovo hivasnal call ablakbol chat-et valaszt es ringing-ben van akkor hangup call
var callmode = 0; // callmode: 0=call-audio, 1=call-audiovideo, 2=call-screenshare
function onCreate (event) // called only once - bind events here
{
try{
if(webphone_api.common.CanLog(4)) { webphone_api.common.PutToDebugLog(4, "EVENT, _call: onCreate"); }
webphone_api.$('#call_menu_ul').on('click', 'li', function(event)
{
MenuItemSelected(webphone_api.$(this).attr('id'));
});
webphone_api.$("#btn_call_menu").on("click", function()
{
CreateOptionsMenu('#call_menu_ul');
});
webphone_api.$("#btn_call_menu").attr("title", webphone_api.stringres.get("hint_menu"));
webphone_api.$("#btn_hangup").on("click", function()
{
if(webphone_api.common.CanLog(4)) { webphone_api.common.PutToDebugLog(4, 'EVENT, _call Hangup onclick'); }
HangupCall();
});
webphone_api.$("#btn_accept").on("click", function()
{
if(webphone_api.common.CanLog(4)) { webphone_api.common.PutToDebugLog(4, 'EVENT, _call AcceptCall onclick'); }
AcceptCall(true);
});
webphone_api.$("#btn_reject").on("click", function()
{
webphone_api.common.PutToDebugLog(4, 'EVENT, _call RejectCall onclick');
RejectCall(true);
});
webphone_api.$("#btn_ml_accept").on("click", function()
{
webphone_api.common.PutToDebugLog(4, 'EVENT, _call multiline Accept onclick');
AcceptCall(true);
});
webphone_api.$("#btn_ml_reject").on("click", function()
{
webphone_api.common.PutToDebugLog(4, 'EVENT, _call RejectCallMultiline onclick');
RejectCallMultiline(true);
});
webphone_api.$("#btn_ml_more").on("click", function()
{
webphone_api.common.PutToDebugLog(4, 'EVENT, _call multiline more onclick');
webphone_api.$('#btn_call_menu').click();
});
webphone_api.$("#btn_hangup").attr("title", webphone_api.stringres.get("hint_hangup"));
webphone_api.$("#btn_accept").attr("title", webphone_api.stringres.get("hint_accept"));
webphone_api.$("#btn_reject").attr("title", webphone_api.stringres.get("hint_reject"));
webphone_api.$("#calledcaller").attr("title", webphone_api.stringres.get("hint_called"));
webphone_api.$("#status_call").attr("title", webphone_api.stringres.get("hint_callstatus"));
webphone_api.$("#call_duration").attr("title", webphone_api.stringres.get("hint_callduration"));
//-- webphone_api.$("#btn_accept_end").attr("title", webphone_api.stringres.get("hint_accept_end"));
//-- webphone_api.$("#btn_reject_ml").attr("title", webphone_api.stringres.get("hint_reject_new"));
//-- webphone_api.$("#btn_accept_hold").attr("title", webphone_api.stringres.get("hint_accept_hold"));
webphone_api.$("#btn_ml_accept").attr("title", webphone_api.stringres.get("hint_accept"));
webphone_api.$("#btn_reject_ml").attr("title", webphone_api.stringres.get("hint_reject_new"));
webphone_api.$("#btn_ml_more").attr("title", webphone_api.stringres.get("hint_more"));
webphone_api.$("#btn_audiodevice").on("click", function()
{
webphone_api.common.PutToDebugLog(4, 'EVENT, _call webphone_audiodevice onclick');
webphone_api.devicepopup();
});
//-- var idx = 0;
var timerid;
webphone_api.$( window ).resize(function() // window resize handling
{
if (webphone_api.$.mobile.activePage.attr('id') === 'page_call')
{
if ( !webphone_api.common.isNull(timerid) ) { clearTimeout(timerid); }
timerid = setTimeout(function ()
{
AddCallFunctions(false);
MeasureCall();
//-- idx++;
//-- webphone_api.common.PutToDebugLog(2, 'idx = ' + idx);
}, 100);
}
});
webphone_api.$("#numpad_btn_dp_1").on("click", function()
{
SendDtmf('1');
//-- webphone_api.play(1, 'sound/rtc_ringtone.wav', false, true);
//-- webphone_api.common.PrintCallSessions();
});
webphone_api.$("#numpad_btn_dp_2").on("click", function() { SendDtmf('2'); });
webphone_api.$("#numpad_btn_dp_3").on("click", function() { SendDtmf('3'); });
webphone_api.$("#numpad_btn_dp_4").on("click", function() { SendDtmf('4'); });
webphone_api.$("#numpad_btn_dp_5").on("click", function() { SendDtmf('5'); });
webphone_api.$("#numpad_btn_dp_6").on("click", function() { SendDtmf('6'); });
webphone_api.$("#numpad_btn_dp_7").on("click", function() { SendDtmf('7'); });
webphone_api.$("#numpad_btn_dp_8").on("click", function() { SendDtmf('8'); });
webphone_api.$("#numpad_btn_dp_9").on("click", function() { SendDtmf('9'); });
webphone_api.$("#numpad_btn_dp_0").on("click", function() { SendDtmf('0'); });
webphone_api.$("#numpad_btn_dp_ast").on("click", function() { SendDtmf('*'); });
webphone_api.$("#numpad_btn_dp_diez").on("click", function() { SendDtmf('#'); });
webphone_api.$( "#page_call" ).keypress(function( event )
{
HandleKeyPress(event);
});
webphone_api.$( "#page_call" ).keydown(function(event)
{
try{
var charCode = (event.keyCode) ? event.keyCode : event.which; // workaround for firefox
if (charCode == ctrlKey) { ctrlDown = true; return true; }
if (charCode == altKey) { altDown = true; return true; }
if (charCode == shiftKey) { shiftDown = true; return true; }
if (event.ctrlKey || event.metaKey || event.altKey) { specialKeyDown = true; return true; }
if (charCode === 13) // enter
{
var active_popups = webphone_api.$.mobile.activePage.find(".messagePopup");
if (!webphone_api.common.isNull(active_popups) && active_popups.length > 0)
{
webphone_api.$("#adialog_positive").click();
event.preventDefault();
}
else if (webphone_api.$('#acceptreject_layout').is(':visible')) // acceptreject_layout check is visible
{
webphone_api.$("#btn_accept").click();
event.preventDefault();
}
else if (webphone_api.$('#mline_layout').is(':visible')) // acceptreject_layout check is visible
{
webphone_api.$("#btn_ml_accept").click();
event.preventDefault();
}
}
else if (charCode === 27 || charCode === 8) // ESC or Backspace
{
var active_popups = webphone_api.$.mobile.activePage.find(".messagePopup");
if (!webphone_api.common.isNull(active_popups) && active_popups.length > 0)
{
if(charCode === 27)
{
webphone_api.$("#adialog_negative").click();
event.preventDefault();
}
}
else if (webphone_api.$('#acceptreject_layout').is(':visible')) // acceptreject_layout check is visible
{
webphone_api.$("#btn_reject").click();
event.preventDefault();
}
else if (webphone_api.$('#mline_layout').is(':visible')) // acceptreject_layout check is visible
{
webphone_api.$("#btn_ml_reject").click();
event.preventDefault();
}
else if (webphone_api.$('#hangup_layout').is(':visible')) // acceptreject_layout check is visible
{
webphone_api.$("#btn_hangup").click();
event.preventDefault();
}
}
else
{
return;
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: keydown", err); }
});
//-- webphone_api.$( "#volumein" ).slider({
//-- create: function( event, ui ) { alert('slidecreate1'); }
//-- });
//-- webphone_api.$( "#volumein" ).on( "slidecreate", function( event, ui )
//-- {
//-- var invalue = webphone_api.common.GetParameter('volumein');
//-- if (webphone_api.common.isNull(invalue) || invalue.length < 1 || !webphone_api.common.IsNumber(invalue))
//-- {
//-- invalue = '50';
//-- }
//-- this.value = invalue;
//-- });
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: onCreate", err); }
}
var ctrlDown = false;
var altDown = false;
var shiftDown = false;
var specialKeyDown = false;
var ctrlKey = 17, vKey = 86, cKey = 67, altKey = 18, shiftKey = 16;
// keypresses during call should send dtmf
function HandleKeyPress(event)
{
try{
//-- don't catch input if a popup is open, because popups can have input boxes, and we won't be able to write into them
if (webphone_api.$(".ui-page-active .ui-popup-active").length > 0)
{
return false;
}
var charCode = (event.keyCode) ? event.keyCode : event.which; // workaround for firefox
// listen for control key, so we don't catch ctrl+c, ctrl+v
if (ctrlDown || altDown || shiftDown || specialKeyDown || charCode === 8)
{
return false;
}
if ((charCode >= 48 && charCode <= 57) || charCode === 42 || charCode === 35)
{
SendDtmf(String.fromCharCode(charCode));
}
return false;
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: HandleKeyPress", err); }
}
function onStart(event)
{
try{
if(webphone_api.common.CanLog(4)) { webphone_api.common.PutToDebugLog(4, "EVENT, _call: onStart"); }
webphone_api.global.isCallStarted = true;
webphone_api.global.hangupPressedCount = 0;
MeasureCall(); // resolve window height size change
if (!webphone_api.common.isNull(document.getElementById("app_name_call"))
&& webphone_api.common.GetParameter('devicetype') !== webphone_api.common.DEVICE_WIN_SOFTPHONE())
{
document.getElementById("app_name_call").innerHTML = webphone_api.common.GetBrandName();
}
webphone_api.$(".separator_line_thick").css( 'background-color', webphone_api.common.HoverCalc(webphone_api.common.getBgColor('#call_header'), -30) );
webphone_api.$('#btn_hangup_img').attr('src', '' + webphone_api.common.GetElementSource() + 'images/btn_hangup_txt.png');
if (!webphone_api.common.isNull(document.getElementById('btn_audiodevice')))
{
document.getElementById('btn_audiodevice').innerHTML = webphone_api.stringres.get('btn_audio_device');
}
if (webphone_api.common.GetParameterBool('displayvolumecontrols', false) === true)
{
webphone_api.$('#volumecontrols').show();
}
if (webphone_api.common.GetParameterBool('displayaudiodevice', false) === true)
{
webphone_api.$('#audiodevice_container').show();
}
// set volume controls values
var invalue = webphone_api.common.GetParameter('volumein');
if (webphone_api.common.isNull(invalue) || invalue.length < 1 || !webphone_api.common.IsNumber(invalue))
{
invalue = '50';
}
webphone_api.$("#volumein").val(invalue);
webphone_api.$("#volumein").slider('refresh');
var outvalue = webphone_api.common.GetParameter('volumeout');
if (webphone_api.common.isNull(outvalue) || outvalue.length < 1 || !webphone_api.common.IsNumber(outvalue))
{
outvalue = '50';
}
webphone_api.$("#volumeout").val(outvalue);
webphone_api.$("#volumeout").slider('refresh');
// handle volume control on change
webphone_api.$( "#volumein" ).on( "slidestop", function( event, ui )
{
var setval = this.value;
if (webphone_api.common.isNull(setval) || setval.length < 1) { return; }
setval = webphone_api.common.Trim(setval);
webphone_api.common.SaveParameter('volumein', setval);
webphone_api.common.PutToDebugLog(5, 'EVENT, volumein slidestop: ' + this.value);
// -0 for the recording (microphone) audio device
// -1 for the playback (speaker) audio device
// -2 for the ringback (speaker) audio device
webphone_api.setvolume(0, setval);
});
webphone_api.$( "#volumeout" ).on( "slidestop", function( event, ui )
{
var setval = this.value;
if (webphone_api.common.isNull(setval) || setval.length < 1) { return; }
setval = webphone_api.common.Trim(setval);
webphone_api.common.SaveParameter('volumeout', setval);
webphone_api.common.PutToDebugLog(5, 'EVENT, volumeout slidestop: ' + this.value);
webphone_api.setvolume(1, setval);
});
calltype = webphone_api.common.GetIntentParam(webphone_api.global.intentcall, 'calltype');
var callmodestr = webphone_api.common.GetIntentParam(webphone_api.global.intentcall, 'callmode');
if (!webphone_api.common.isNull(callmodestr) && webphone_api.common.IsNumber(callmodestr)) { callmode = webphone_api.common.StrToInt(callmodestr); }
webphone_api.global.callName = ''; // reset webphone_api.global.callName
callnumber = webphone_api.common.GetIntentParam(webphone_api.global.intentcall, 'number');
webphone_api.global.callName = webphone_api.common.GetIntentParam(webphone_api.global.intentcall, 'name');
if (webphone_api.common.isNull(webphone_api.global.callName) || webphone_api.global.callName.length < 1)
{
webphone_api.global.callName = webphone_api.common.GetContactNameFromNumber(callnumber);
}
var telsearchurl = webphone_api.common.GetParameter2('telsearchurl');
if (webphone_api.common.isNull(telsearchurl) || telsearchurl.length < 3) { telsearchurl = webphone_api.parameters['telsearchurl']; }
if (!webphone_api.common.isNull(telsearchurl) && telsearchurl.length > 3 && (webphone_api.global.callName.length < 1 || webphone_api.global.callName === callnumber))
{
webphone_api.gettelsearchname(callnumber, function (recname)
{
if (webphone_api.common.isNull(recname) || recname.length < 2 || recname.length > 60) { return; }
webphone_api.global.telsearchname = recname;
webphone_api.global.callName = recname;
peerdetails = webphone_api.global.callName + '
' + callnumber;
if(webphone_api.$('#page_call_peer_details').html() != peerdetails)
{
webphone_api.common.PutToDebugLog(5, "EVENT, caller-id display A: " + peerdetails);
webphone_api.$('#page_call_peer_details').html(peerdetails);
}
peerdetails = webphone_api.global.callName + ' (' + callnumber + ') ';
webphone_api.$('#calledcaller').html(peerdetails);
});
}
// don't display username and name, if both are the same
var peerdetails = '';
if (webphone_api.global.callName !== callnumber)
{
peerdetails = webphone_api.global.callName + ' (' + callnumber + ') ';
webphone_api.$('#calledcaller').html(peerdetails);
}else
{
peerdetails = callnumber;
webphone_api.$('#calledcaller').html(peerdetails);
}
NormalizeDisplayDetails(peerdetails);
if (calltype === "incoming")
{
webphone_api.GetIncomingDisplay(function (disp)
{
if (!webphone_api.common.isNull(disp) && disp.length > 0 && peerdetails.indexOf(disp) < 0)
{
disp = disp.replace('\n', '');
peerdetails = disp + ' ' + peerdetails;
}
NormalizeDisplayDetails(peerdetails);
});
}
// handle hangup / acceptreject layouts (icoming / outgoing call)
if (calltype === "outgoing")
{
AddCallFunctions(false);
webphone_api.$('#acceptreject_layout').hide();
webphone_api.$('#hangup_layout').show();
webphone_api.$('#callfunctions_layout').show();
//-- if (!webphone_api.global.isdebugversion)
//-- {
//-- webphone_api.call(-1, callnumber);
setTimeout(function ()
{
var ratinguri = webphone_api.common.GetParameter('ratingrequest');
if (
//OPSSTART
webphone_api.common.Glbr() === true &&
//OPSEND
!webphone_api.common.isNull(ratinguri) && ratinguri.length > 2 && !webphone_api.common.isNull(callnumber) && callnumber.length > 0 &&
(webphone_api.common.isNull(webphone_api.global.rating) || (webphone_api.global.rating).length < 1) // means rating is not received from signaling
)
{
webphone_api.needratingrequest(function (val) // API_NeedRatingRequest
{
if (val === true)
{
webphone_api.common.UriParser(ratinguri, '', callnumber, '', '', 'getrating');
}
});
}
}, 4000);
//-- }
}
if (calltype === "incoming")
{
if (webphone_api.common.GetParameterBool('autoaccept', false) === true || webphone_api.common.GetParameterInt('enableautoaccept', 1) === 3)
{
webphone_api.$('#hangup_layout').show();
webphone_api.$('#callfunctions_layout').show();
webphone_api.$('#acceptreject_layout').hide();
}else
{
//-- normal call
AddCallFunctions(true);
showignore = true;
hanguponchat = true;
webphone_api.$('#hangup_layout').hide();
webphone_api.$('#callfunctions_layout').hide();
webphone_api.$('#acceptreject_layout').show();
}
}
if (callmode > 0 && webphone_api.common.CanIUseVideo() === true)
{
webphone_api.$('#contact_details').hide();
webphone_api.$('#video_container').show();
MeasureCall();
setTimeout(function () { MeasureCall(); }, 200);
if (webphone_api.common.GetParameterInt('softphonevideomode', 0) === 1) // hide Full Screeen button in windows softphone, because it's not working
{
webphone_api.$('#div_video_fullscreen_button').hide();
}
webphone_api.common.PutToDebugLog(2, 'EVENT, call onstart video container displayed');
}
if (webphone_api.global.isdebugversion === true)
{
webphone_api.$('#mline_layout').show();
}
MeasureCall();
setTimeout(function () { MeasureCall(); }, 200);
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: onStart", err); }
}
// display other party details
// search details and don't show the same string twice: for example caller or display name
function NormalizeDisplayDetails(det_in)
{
try{
if (webphone_api.common.isNull(det_in) || det_in.length < 1)
{
if(webphone_api.$('#page_call_peer_details').html().length > 0)
{
webphone_api.common.PutToDebugLog(5, "EVENT, caller-id display clear A");
webphone_api.$('#page_call_peer_details').html('');
}
return;
}
if (det_in.indexOf(' ') < 0)
{
if(webphone_api.$('#page_call_peer_details').html() != det_in)
{
webphone_api.common.PutToDebugLog(5, "EVENT, caller-id display B: " + det_in);
webphone_api.$('#page_call_peer_details').html(det_in);
}
return;
}
det_in = webphone_api.common.ReplaceAll(det_in, '-', ' ');
var det = '';
var darr = det_in.split(' ');
var idx = 0;// remove any empty/invalid entries
while (idx < darr.length)
{
if (webphone_api.common.isNull(darr[idx]) || webphone_api.common.Trim(darr[idx]).length < 1)
{
darr.splice(idx, 1);
}else
{
idx++;
}
}
// returns only unique elements
darr = webphone_api.common.UniqueArray(darr);
var middle = Math.ceil(darr.length / 2);
for (var i = 0; i < darr.length; i++)
{
if (webphone_api.common.isNull(darr[i]) || webphone_api.common.Trim(darr[i]).length < 1) { continue; }
if (det.indexOf(darr[i]) < 0)
{
if (det.length > 0)
{
if (i === middle)
{
det = det + '
';
}else
{
det = det + ' ';
}
}
det = det + darr[i];
}
}
if(webphone_api.$('#page_call_peer_details').html() != det)
{
webphone_api.common.PutToDebugLog(5, "EVENT, caller-id display C: " + det);
webphone_api.$('#page_call_peer_details').html(det);
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: NormalizeDisplayDetails", err); }
}
function OnNewIncomingCall()
{
try{
webphone_api.common.PutToDebugLog(5, 'EVENT, _call handle OnNewIncomingCall on line: ' + webphone_api.global.aline.toString());
var ep = webphone_api.common.GetEndpoint(1025,webphone_api.global.aline, '', '', '', false);
if (webphone_api.common.isNull(ep) || ep.length < 5)
{
webphone_api.common.PutToDebugLog(3, 'WARNING, _call OnNewIncomingCall: ep is NULL for line A: ' + webphone_api.global.aline.toString());
//handle bug / workaround
var curraline = webphone_api.common.GetFreeLine(); webphone_api.common.SetALineInternal(curraline,51);
ep = webphone_api.common.GetEndpoint(1026,webphone_api.global.aline, '', '', '', false);
if (webphone_api.common.isNull(ep) || ep.length < 5)
{
webphone_api.common.PutToDebugLog(2, 'ERROR, _call OnNewIncomingCall: ep is NULL for line B: ' + webphone_api.global.aline.toString());
webphone_api.common.LogLines();
return;
}
}
var innr = ep[webphone_api.common.EP_DESTNR];
webphone_api.$('#mline_layout').show();
if (webphone_api.$('#hangup_layout').is(':visible'))
{
webphone_api.$('#hangup_layout').hide();
}
if (webphone_api.$('#acceptreject_layout').is(':visible'))
{
webphone_api.$('#acceptreject_layout').hide();
}
webphone_api.common.RefreshInfo(1);
setTimeout(function () { MeasureCall(); }, 200);
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: OnNewIncomingCall", err); }
}
function RejectCallMultiline(callapi)
{
try{
showignore = false;
hanguponchat = false;
//webphone_api.common.PutToDebugLog(5, "EVENT,rrrrrr C1");
webphone_api.$('#mline_layout').hide();
webphone_api.$('#callfunctions_layout').show();
webphone_api.$('#hangup_layout').show();
setTimeout(function () { MeasureCall(); }, 200);
webphone_api.global.acceptReject = true;
//-- webphone_api.global.hangupPressedCount = 1;
//find last incoming call to reject; because maybe user changed line, but even then reject the incoming line
if (callapi)
{
var linetoreject = webphone_api.global.aline; // 1=outgoing, 2=incoming
var setuptime = 0;
/* NEM LOGIKUS !!!!
for (var i = 0; i < webphone_api.global.ep.length; i++)
{
if (webphone_api.common.isNull(webphone_api.global.ep[i]) || webphone_api.global.ep[i].length < 5) { continue; }
if (webphone_api.global.ep[i][webphone_api.common.EP_INCOMING] !== '2') { continue; }
var stime = webphone_api.common.StrToInt(webphone_api.global.ep[i][webphone_api.common.EP_SETUPTIME]);
if (!webphone_api.common.isNull(stime) && webphone_api.common.IsNumber(stime) && stime > setuptime)
{
setuptime = stime;
linetoreject = webphone_api.global.ep[i][webphone_api.common.EP_LINE];
}
}
*/
webphone_api.plhandler.Reject(linetoreject,14);
// update lines (remove line and set last active line)
for (var i = 0; i < webphone_api.global.ep.length; i++)
{
if (webphone_api.common.isNull(webphone_api.global.ep[i]) || webphone_api.global.ep[i].length < 5) { continue; }
var lntmp = webphone_api.global.ep[i][webphone_api.common.EP_LINE];
if (lntmp == webphone_api.global.aline)
{
webphone_api.global.ep[i][webphone_api.common.EP_FLAGDEL] = 'true';
break;
}
}
// find last active line
for (var i = webphone_api.global.ep.length - 1; i >= 0; i--)
{
if (webphone_api.common.isNull(webphone_api.global.ep[i]) || webphone_api.global.ep[i].length < 5) { continue; }
if (webphone_api.global.ep[i][webphone_api.common.EP_FLAGDEL] == 'false')
{
// found one active line, set it
webphone_api.common.PutToDebugLog(2, 'EVENT, SetLine called from RejectCallMultiline');
webphone_api.setline(webphone_api.common.StrToInt(webphone_api.global.ep[i][webphone_api.common.EP_LINE]));
break;
}
}
//-- UpdateLineUI();
setTimeout(function ()
{
webphone_api.common.RefreshInfo(2);
}, 400);
}
callmode = 0;
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: RejectCallMultiline", err); }
}
function AcceptHold(callapi)
{
try{
webphone_api.global.acceptReject = true;
AddCallFunctions(false);
showignore = false;
hanguponchat = false;
//webphone_api.common.PutToDebugLog(5, "EVENT,rrrrrr C2");
webphone_api.$('#mline_layout').hide();
webphone_api.$('#hangup_layout').show();
webphone_api.$('#callfunctions_layout').show();
setTimeout(function () { MeasureCall(); }, 200);
if (callapi)
{
// find previous active line to put that call on hold
var prevline = -10;
var setuptimeTmp = 0;
if (!webphone_api.common.isNull(webphone_api.global.ep))
{
for (var i = 0; i < webphone_api.global.ep.length; i++)
{
var eptmp = webphone_api.global.ep[i];
if (webphone_api.common.isNull(eptmp) || eptmp.length < 1) { continue; }
if (eptmp[webphone_api.common.EP_FLAGDEL] === 'true') { continue; }
if (!webphone_api.common.isNull(eptmp[webphone_api.common.EP_LINE]) && webphone_api.common.IsNumber(eptmp[webphone_api.common.EP_LINE]) === true)
{
if (setuptimeTmp < webphone_api.common.StrToInt(eptmp[webphone_api.common.EP_SETUPTIME]))
{
prevline = webphone_api.common.StrToInt(eptmp[webphone_api.common.EP_LINE]);
}
}
}
}
webphone_api.common.PutToDebugLog(2, 'EVENT, mlogic API_Accept AcceptHold');
webphone_api.accept(webphone_api.global.aline);
if (prevline > 0)
{
webphone_api.common.PutToDebugLog(2, 'EVENT, API_Hold mainlogic hold call from cl AcceptHold; ' + ' on line: ' + prevline );
webphone_api.plhandler.Hold(true, prevline, true);
setTimeout(function ()
{
AddCallFunctions(false);
}, 250);
webphone_api.common.PutToDebugLog(2, 'EVENT, AcceptHold hold finished');
}
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: AcceptHold", err); }
}
function AcceptEnd(callapi)
{
try{
webphone_api.global.acceptReject = true;
AddCallFunctions(false);
showignore = false;
hanguponchat = false;
//webphone_api.common.PutToDebugLog(5, "EVENT,rrrrrr C3");
webphone_api.$('#mline_layout').hide();
webphone_api.$('#hangup_layout').show();
webphone_api.$('#callfunctions_layout').show();
setTimeout(function () { MeasureCall(); }, 200);
if (callapi)
{
// find previous active line to end that call
var prevline = -10;
var setuptimeTmp = 0;
if (!webphone_api.common.isNull(webphone_api.global.ep))
{
for (var i = 0; i < webphone_api.global.ep.length; i++)
{
var eptmp = webphone_api.global.ep[i];
if (webphone_api.common.isNull(eptmp) || eptmp.length < 1) { continue; }
if (eptmp[webphone_api.common.EP_FLAGDEL] === 'true') { continue; }
if (!webphone_api.common.isNull(eptmp[webphone_api.common.EP_LINE]) && webphone_api.common.IsNumber(eptmp[webphone_api.common.EP_LINE]) === true)
{
if (setuptimeTmp < webphone_api.common.StrToInt(eptmp[webphone_api.common.EP_SETUPTIME]))
{
prevline = webphone_api.common.StrToInt(eptmp[webphone_api.common.EP_LINE]);
}
}
}
}
webphone_api.common.PutToDebugLog(2, 'EVENT, AcceptEnd called');
webphone_api.plhandler.Accept(webphone_api.global.aline);
if (prevline > 0)
{
webphone_api.common.PutToDebugLog(2, 'EVENT, hangup AcceptEnd');
webphone_api.plhandler.Hangup(prevline, true);
}
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: AcceptEnd", err); }
}
function MeasureCall() // resolve window height size change
{
try{
//-- var pgh = webphone_api.common.GetDeviceHeight() - 1; webphone_api.$('#page_call').css('min-height', pgh + 'px'); // must be set when softphone is skin in div
webphone_api.$('#page_call').css('min-height', 'auto'); // must be set when softphone is skin in div
var volumevisible = false;
var audiodevicevisible = false;
if (webphone_api.$('#volumecontrols').is(':visible')) { volumevisible = true; }
if (webphone_api.$('#audiodevice_container').is(':visible')) { audiodevicevisible = true; }
webphone_api.$("#page_call_content").height(webphone_api.common.GetDeviceHeight() - webphone_api.$("#call_header").height() -webphone_api.$('.separator_line_thick').height());
var pageHeight = webphone_api.common.GetDeviceHeight() - webphone_api.$("#call_header").height();
webphone_api.$('#page_call_content').height(pageHeight - 3);
var max_vid_height = pageHeight - 3;
var numpadHeight = pageHeight - webphone_api.$("#hangup_layout").height() - webphone_api.$("#callfunctions_layout").height() - webphone_api.$(".separator_color_bg").height() - 12;
if (webphone_api.$('#mlcontainer').is(':visible')) { numpadHeight = numpadHeight - webphone_api.$('#mlcontainer').height() - 2; }
var rowHeight = Math.floor(numpadHeight / 5);
webphone_api.$("#numpad_btn_grid .ui-btn").height(rowHeight);
rowHeight = rowHeight - 6;
webphone_api.$("#numpad_number_container").height(rowHeight);
webphone_api.$("#numpad_number_container").css("line-height", rowHeight + "px");
if (calltype === "outgoing")
{
pageHeight = pageHeight - webphone_api.$("#hangup_layout").height() - webphone_api.$("#callfunctions_layout").height() - webphone_api.$(".separator_color_bg").height() - 1;
if (volumevisible) { pageHeight = pageHeight - webphone_api.$("#volumecontrols").height(); }
if (audiodevicevisible) { pageHeight = pageHeight - webphone_api.$("#audiodevice_container").height(); }
pageHeight = pageHeight - webphone_api.$("#mlcontainer").height() - webphone_api.$(".separator_line_thick").height();
pageHeight = Math.floor(pageHeight);
webphone_api.$("#contact_image").height( pageHeight );
//-- webphone_api.$("#contact_image").css("line-height", pageHeight + "px");
var mTop = (pageHeight - webphone_api.$("#contact_image_img").height() - webphone_api.$("#page_call_additional_info").height()) / 2;
webphone_api.$("#contact_image_img").css("margin-top", mTop + "px");
}
if (calltype === "incoming")
{
if (document.getElementById('acceptreject_layout').style.display === 'block')
{
pageHeight = pageHeight - webphone_api.$("#acceptreject_layout").height() - 3;
if (volumevisible) { pageHeight = pageHeight - webphone_api.$("#volumecontrols").height(); }
if (audiodevicevisible) { pageHeight = pageHeight - webphone_api.$("#audiodevice_container").height(); }
pageHeight = pageHeight - webphone_api.$("#mlcontainer").height() - webphone_api.$(".separator_line_thick").height();
pageHeight = Math.floor(pageHeight);
}else
{
pageHeight = pageHeight - webphone_api.$("#hangup_layout").height() - webphone_api.$("#callfunctions_layout").height() - webphone_api.$(".separator_color_bg").height() - 1;
if (volumevisible) { pageHeight = pageHeight - webphone_api.$("#volumecontrols").height(); }
if (audiodevicevisible) { pageHeight = pageHeight - webphone_api.$("#audiodevice_container").height(); }
pageHeight = pageHeight - webphone_api.$("#mlcontainer").height() - webphone_api.$(".separator_line_thick").height();
pageHeight = Math.floor(pageHeight);
}
webphone_api.$("#contact_image").height( pageHeight );
//-- webphone_api.$("#contact_image").css("line-height", pageHeight + "px");
var mTop = (pageHeight - webphone_api.$("#contact_image_img").height() - webphone_api.$("#page_call_additional_info").height()) / 2;
webphone_api.$("#contact_image_img").css("margin-top", mTop + "px");
}
var brandW = Math.floor(webphone_api.common.GetDeviceWidth() / 4.6);
webphone_api.$("#app_name_call").width(brandW);
// handle video container height/aspect ratio
if (webphone_api.$('#video_container').is(':visible'))
{
var vh = webphone_api.$('#video_remote').height();
if (!webphone_api.common.isNull(vh) && webphone_api.common.IsNumber(vh))
{
vh = vh - 55; // space for full screen button (for some reason video_container reports invalid height value so we have to use video remote DIV)
max_vid_height = max_vid_height - webphone_api.$("#hangup_layout").height() - webphone_api.$("#callfunctions_layout").height() - webphone_api.$(".separator_color_bg").height() - 1;
//alert('webphone_api.$("#hangup_layout").height(): ' + webphone_api.$("#hangup_layout").height() + '\nj$("#callfunctions_layout").height(): ' + webphone_api.$("#callfunctions_layout").height() + '\nmax_vid_height: ' + max_vid_height);
if (vh > max_vid_height)
{
webphone_api.$('#video_container').height(max_vid_height);
webphone_api.$('#video_remote').height(max_vid_height - 55);
}
}
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: MeasureCall", err); }
}
function HangupCall()
{
try{
// reset mute, hold, speaker buttons state
//-- webphone_api.$('#mute_status').removeClass("callfunc_status_on");
//-- webphone_api.$('#hold_status').removeClass("callfunc_status_on");
//-- webphone_api.$('#speaker_status').removeClass("callfunc_status_on");
webphone_api.global.dontshowdiscreason = true;
if (webphone_api.common.GetNrOfActiveCalls() < 2)
{
webphone_api.global.hangupPressedCount++;
}
if(webphone_api.common.CanLog(4)) { webphone_api.common.PutToDebugLog(4, 'EVENT, _call HangupCall'); }
if (webphone_api.global.hangupPressedCount < 2)
{
if (webphone_api.common.GetNrOfActiveCalls() < 2 && (webphone_api.common.isNull(webphone_api.global.waiting_conf_numbers) || webphone_api.global.waiting_conf_numbers.length < 1) && webphone_api.global.dontshow_closecall === false)
{
webphone_api.$('#callfunctions_layout').hide();
webphone_api.$('#btn_hangup_img').attr('src', '' + webphone_api.common.GetElementSource() + 'images/btn_close_txt.png');
webphone_api.$("#btn_hangup").attr("title", webphone_api.stringres.get("hint_closecall"));
}
webphone_api.hangup();
//-- UpdateLineUI();
setTimeout(function ()
{
webphone_api.common.RefreshInfo(3);
}, 400);
}
else if (webphone_api.global.hangupPressedCount > 1)
{
webphone_api.hangup();
webphone_api.$.mobile.back();
webphone_api.global.hangupPressedCount = 0;
}
callmode = 0;
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: HangupCall", err); }
}
function AcceptCall(callapi)
{
var lastoop = 0;
try{
lastoop = 1;
webphone_api.global.acceptReject = true;
lastoop = 2;
AddCallFunctions(false);
lastoop = 3;
showignore = false;
hanguponchat = false;
lastoop = 4;
try{
lastoop = 11;
//webphone_api.common.PutToDebugLog(5, "EVENT,rrrrrr C4");
webphone_api.$('#mline_layout').hide();
lastoop = 12;
webphone_api.$('#acceptreject_layout').hide();
lastoop = 13;
webphone_api.$('#hangup_layout').show();
lastoop = 14;
webphone_api.$('#callfunctions_layout').show();
} catch(ee) { webphone_api.common.PutToDebugLogWarning(2, "_call: AcceptCallInternal "+lastoop.toString(), ee); }
lastoop = 5;
setTimeout(function () { lastoop = 6; MeasureCall(); lastoop = 7; }, 200);
//-- CallfunctionUsage(); TODO: implement
lastoop = 8;
if (callapi)
{
lastoop = 9;
webphone_api.accept(-2);
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: AcceptCall "+lastoop.toString(), err); }
}
function RejectCall(callapi)
{
try{
showignore = false;
hanguponchat = false;
//webphone_api.common.PutToDebugLog(5, "EVENT,rrrrrr C5");
webphone_api.$('#mline_layout').hide();
webphone_api.$('#acceptreject_layout').hide();
if (webphone_api.common.GetNrOfActiveCalls() < 2)
{
webphone_api.$('#callfunctions_layout').hide();
}
webphone_api.$('#hangup_layout').show();
setTimeout(function () { MeasureCall(); }, 200);
webphone_api.global.acceptReject = true;
webphone_api.global.hangupPressedCount = 1;
if (callapi)
{
webphone_api.reject(-2,15);
}
callmode = 0;
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: RejectCall", err); }
}
function SendDtmf(numChar)
{
try{
webphone_api.common.PutToDebugLog(5,"EVENT, _call SendDtmf: " + numChar);
webphone_api.dtmf(numChar, -1);
var currNumVal = webphone_api.$('#numpad_number').html();
if (webphone_api.common.isNull(currNumVal)) { currNumVal = ''; }
if (currNumVal.length > 18) { currNumVal = currNumVal.substring(10, currNumVal.length) + ' '; }
webphone_api.$('#numpad_number').html(currNumVal + numChar);
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: SendDtmf", err); }
}
function CloseCall()
{
try{
if(webphone_api.common.CanLog(4)) { webphone_api.common.PutToDebugLog(3, 'EVENT, _call CloseCall'); }
webphone_api.$.mobile.back();
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: CloseCall", err); }
}
// show close button if the caller hangs up before it is accepted or rejected
function OnCallerHangup() //--TODO:
{
try{
//-- if (isVideoOn) VideoOnPause(); // stop video
webphone_api.global.hangupPressedCount = 1;
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: OnCallerHangup", err); }
}
var lastBtns = '';
function UpdateLineButtons(fromcode)
{
try{
if (webphone_api.common.isNull(fromcode)) fromcode = 0;
//webphone_api.common.PutToDebugLog(5, "EVENT,rrrrrr A0 "+fromcode.toString());
if (webphone_api.common.IsSDK() === true) { return; }
var mlcont = document.getElementById('mlcontainer');
if (webphone_api.common.isNull(mlcont)) { return; }
var ml_btns = document.getElementById('ml_buttons');
if (webphone_api.common.isNull(ml_btns)) { return; }
if (webphone_api.common.isNull(webphone_api.global.ep) || webphone_api.global.ep.length < 1) { return; }
var template = '' +
'';
var buttonIds = [];
var currBtns = '';
for (var i = 0; i < webphone_api.global.ep.length; i++)
{
var item = webphone_api.global.ep[i];
if (webphone_api.common.isNull(item) || item.length < 1) { continue; }
var lntmp = item[webphone_api.common.EP_LINE];
if (webphone_api.common.isNull(lntmp) || lntmp.length < 1 || webphone_api.common.IsNumber(lntmp) === false) { continue; }
var iline = webphone_api.common.StrToInt(lntmp);
var isActive = '';
if (webphone_api.global.aline == iline)
{
isActive = 'line_status_on';
}
var btn = webphone_api.common.ReplaceAll(template, '[LINENR]', iline.toString());
btn = btn.replace('[ISACTIVE]', isActive);
currBtns += btn;
buttonIds.push(iline.toString());
}
if (currBtns === lastBtns)
{
//webphone_api.common.PutToDebugLog(5, "EVENT,rrrrrr A1 "+currBtns);
return;
}else
{
lastBtns = currBtns;
}
ml_btns.innerHTML = currBtns;
for (var i = 0; i < buttonIds.length; i++)
{
webphone_api.$('#btn_line_' + buttonIds[i]).off('click');
webphone_api.$('#btn_line_' + buttonIds[i]).on('click', function (e)
{
LineCliked(webphone_api.$(this).attr('id'));
});
}
if (buttonIds.length > 1) // display buttons only if there are at least 2 lines
{
if (mlcont.style.display === 'none') { mlcont.style.display = 'block'; }
}else
{
ml_btns.innerHTML = '';
mlcont.style.display = 'none';
}
if(fromcode < 1) fromcode = 20;
webphone_api.common.RefreshInfo(fromcode);
MeasureCall();
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: UpdateLineButtons", err); }
}
function LineCliked(id)
{
try{
if (webphone_api.common.IsSDK() === true) { return; }
if (webphone_api.common.isNull(id) || id.indexOf('btn_line_') !== 0)
{
webphone_api.common.PutToDebugLog(2, 'ERROR, _call: LineCliked invalid id: ' + id);
return;
}
id = id.replace('btn_line_', '');
var line = webphone_api.common.StrToInt(id);
webphone_api.common.PutToDebugLog(1, 'EVENT, Line ' + line.toString() + ' selected by user');
webphone_api.setline(line);
// defmute: 0=both, 1=mute out (speakers), 2=mute in (microphone), 3=both, 4=both, 5=disable mute
var mutedirection = webphone_api.common.GetParameterInt('defmute', 0);
if (mutedirection === 3 || mutedirection === 4) mutedirection = 0;
var automute = webphone_api.common.GetParameterInt('automute', 0);
var autohold = webphone_api.common.GetParameterInt('autohold', 0);
for (var i = 0; i < webphone_api.global.ep.length; i++)
{
var item = webphone_api.global.ep[i];
if (webphone_api.common.isNull(item) || item.length < 1) { continue; }
var lntmp = item[webphone_api.common.EP_LINE];
if (webphone_api.common.isNull(lntmp) || lntmp.length < 1 || webphone_api.common.IsNumber(lntmp) === false) { continue; }
var iline = webphone_api.common.StrToInt(lntmp);
// handle automute/autohold 4=on other line button click
//-- ha az automute és/vagy autohold 4-re van állitva, akkor kezelni kéne a vissza váltás –t is (amelyik line –ra váltunk, arra kell unhold/unmute).
//--if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_WEBRTC)
//--{
if (webphone_api.global.aline == iline)
{
if (automute >= 4)
{
if (item[webphone_api.common.EP_MUTESTATE] == 'true') // if is muted
{
// call directly to engine API files to be able to pass exact line
webphone_api.common.PutToDebugLog(2, 'EVENT, EVENT, USER, automute, API_MuteEx, false on line: ' + iline + '; dest: ' + item[webphone_api.common.EP_DESTNR]);
if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_WEBRTC)
{
webphone_api.webrtcapi.SipToggleMute(false, mutedirection, iline);
}
else if (webphone_api.common.GetParameter('devicetype') === webphone_api.common.DEVICE_WIN_SOFTPHONE() || webphone_api.common.getuseengine() === webphone_api.global.ENGINE_SERVICE)
{
webphone_api.common.WinAPI('API_MuteEx', null, iline, false, mutedirection);
}
else if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_JAVA)
{
webphone_api.webphone.MuteEx(iline, false, mutedirection);
}
webphone_api.global.ep[i][webphone_api.common.EP_MUTESTATE] = 'false';
}
}
if (autohold >= 4)
{
if (item[webphone_api.common.EP_HOLDSTATE] == 'true') // if is on hold
{
webphone_api.common.PutToDebugLog(2, 'EVENT, EVENT, USER, autohold, API_Hold mainlogic, false on line: ' + iline + '; dest: ' + item[webphone_api.common.EP_DESTNR]);
if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_WEBRTC)
{
if(webphone_api.webrtcapi.SipToggleHoldResume(false, iline, 13))
{
item[webphone_api.common.EP_HOLDSTATE] = 'false';
}
}
else if (webphone_api.common.GetParameter('devicetype') === webphone_api.common.DEVICE_WIN_SOFTPHONE() || webphone_api.common.getuseengine() === webphone_api.global.ENGINE_SERVICE)
{
webphone_api.common.WinAPI('API_Hold', null, iline, false);
item[webphone_api.common.EP_HOLDSTATE] = 'false';
}
else if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_JAVA)
{
webphone_api.webphone.Hold(iline, false);
item[webphone_api.common.EP_HOLDSTATE] = 'false';
}
}
}
}else
{
if (automute >= 4)
{
if (item[webphone_api.common.EP_MUTESTATE] == 'false') // if not muted
{
webphone_api.common.PutToDebugLog(2, 'EVENT, EVENT, USER, automute, API_MuteEx, true on line: ' + iline + '; dest: ' + item[webphone_api.common.EP_DESTNR]);
if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_WEBRTC)
{
webphone_api.webrtcapi.SipToggleMute(true, mutedirection, iline);
}
else if (webphone_api.common.GetParameter('devicetype') === webphone_api.common.DEVICE_WIN_SOFTPHONE() || webphone_api.common.getuseengine() === webphone_api.global.ENGINE_SERVICE)
{
webphone_api.common.WinAPI('API_MuteEx', null, iline, true, mutedirection);
}
else if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_JAVA)
{
webphone_api.webphone.MuteEx(iline, true, mutedirection);
}
webphone_api.global.ep[i][webphone_api.common.EP_MUTESTATE] = 'true';
}
}
if (autohold >= 4)
{
if (item[webphone_api.common.EP_HOLDSTATE] == 'false') // if not on hold
{
webphone_api.common.PutToDebugLog(2, 'EVENT, EVENT, USER, autohold, API_Hold mainlogic, true on line: ' + iline + '; dest: ' + item[webphone_api.common.EP_DESTNR]);
if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_WEBRTC)
{
if(webphone_api.webrtcapi.SipToggleHoldResume(true, iline, 14))
{
item[webphone_api.common.EP_HOLDSTATE] = 'true';
}
}
else if (webphone_api.common.GetParameter('devicetype') === webphone_api.common.DEVICE_WIN_SOFTPHONE() || webphone_api.common.getuseengine() === webphone_api.global.ENGINE_SERVICE)
{
webphone_api.common.WinAPI('API_Hold', null, iline, true);
item[webphone_api.common.EP_HOLDSTATE] = 'true';
}
else if (webphone_api.common.getuseengine() === webphone_api.global.ENGINE_JAVA)
{
webphone_api.webphone.Hold(iline, true);
item[webphone_api.common.EP_HOLDSTATE] = 'true';
}
}
}
}
//--}
}
UpdateLineButtons(11);
AddCallFunctions(false);
MeasureCall();
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_call: LineCliked", err); }
}
// change active line, add line buttons and display otion for call
function NewMultilineCall(phoneNr)
{
try{
webphone_api.common.PutToDebugLog(2, 'EVENT, NewMultilineCall');
if (webphone_api.global.isdebugversion)
{
webphone_api.common.GetContacts(function () {});
}
var popupWidth = webphone_api.common.GetDeviceWidth();
if ( !webphone_api.common.isNull(popupWidth) && webphone_api.common.IsNumber(popupWidth) && popupWidth > 100 )
{
popupWidth = Math.floor(popupWidth / 1.2);
}else
{
popupWidth = 220;
}
var btnimage = 'btn_add_contact_txt.png';
var template = '' +
'