JAVASCRIPT 27
Phone.js Guest on 19th April 2021 07:58:35 PM
  1. var Phone = function () {
  2.     this.flashphonerListener = null;
  3.     this.currentCall = null;
  4.     this.holdedCall = null;
  5.     this.logs = "";
  6.     this.intervalId = -1;
  7. };
  8.  
  9. Phone.prototype.init = function () {
  10.     this.flashphonerListener = new DefaultListener();
  11.  
  12.     Flashphoner.getInstance().addListener(WCSEvent.ErrorStatusEvent, this.errorStatusEvent, this);
  13.     Flashphoner.getInstance().addListener(WCSEvent.ConnectionStatusEvent, this.connectionStatusListener, this);
  14.     Flashphoner.getInstance().addListener(WCSEvent.RegistrationStatusEvent, this.registrationStatusListener, this);
  15.     Flashphoner.getInstance().addListener(WCSEvent.OnCallEvent, this.onCallListener, this);
  16.     Flashphoner.getInstance().addListener(WCSEvent.CallStatusEvent, this.callStatusListener, this);
  17.     Flashphoner.getInstance().addListener(WCSEvent.OnTransferEvent, this.onTransferEventListener, this);
  18.     Flashphoner.getInstance().addListener(WCSEvent.TransferStatusEvent, this.onTransferStatusListener, this);
  19.  
  20.     Flashphoner.getInstance().addListener(WCSEvent.OnMessageEvent, this.onMessageListener, this);
  21.     Flashphoner.getInstance().addListener(WCSEvent.MessageStatusEvent, this.messageStatusListener, this);
  22.  
  23.     Flashphoner.getInstance().addListener(WCSEvent.RecordingStatusEvent, this.recordingStatusListener, this);
  24.     Flashphoner.getInstance().addListener(WCSEvent.SubscriptionStatusEvent, this.subscriptionStatusListener, this);
  25.     Flashphoner.getInstance().addListener(WCSEvent.XcapStatusEvent, this.xcapStatusListener, this);
  26.     Flashphoner.getInstance().addListener(WCSEvent.BugReportStatusEvent, this.bugReportStatusListener, this);
  27.     Flashphoner.getInstance().addListener(WCSEvent.OnDataEvent, this.onDataEventListener, this);
  28.     Flashphoner.getInstance().addListener(WCSEvent.DataStatusEvent, this.dataStatusEventListener, this);
  29. };
  30.  
  31. Phone.prototype.getMediaProvider = function () {
  32.     var mediaProviders = Flashphoner.getInstance().mediaProviders;
  33.     var mediaProvider;
  34.  
  35.     var forceMediaProvider = ConfigurationLoader.getInstance().forceMediaProvider;
  36.     if (forceMediaProvider) {
  37.         if (mediaProviders.get(forceMediaProvider)) {
  38.             mediaProvider = forceMediaProvider;
  39.         }
  40.     }
  41.     if (!mediaProvider) {
  42.         mediaProvider = MediaProvider.Flash;
  43.         if (mediaProviders.get(MediaProvider.WebRTC)) {
  44.             mediaProvider = MediaProvider.WebRTC;
  45.         }
  46.     }
  47.     return mediaProvider;
  48. };
  49.  
  50. Phone.prototype.connect = function () {
  51.     if ($("#outbound_proxy").val() == "") {
  52.         $("#outbound_proxy").val($("#domain").val());
  53.     }
  54.  
  55.     var connection = new Connection();
  56.     connection.sipLogin = $('#sipLogin').val();
  57.     connection.sipPassword = $('#sipPassword').val();
  58.     connection.sipAuthenticationName = $('#sipAuthenticationName').val();
  59.     connection.sipDomain = $('#sipDomain').val();
  60.     connection.sipOutboundProxy = $('#sipOutboundProxy').val();
  61.     connection.sipPort = $('#sipPort').val();
  62.     connection.useProxy = true;
  63.     connection.appKey = "defaultApp";
  64.     //This parameter will be defined from flashphoner.xml config
  65.     connection.sipRegisterRequired = null;
  66.  
  67.     for (var key in connection) {
  68.         Flashphoner.getInstance().setCookie(key, connection[key]);
  69.     }
  70.  
  71.     var result = Flashphoner.getInstance().connect(connection);
  72.     if (result == 0) {
  73.         trace("Phone - connecting");
  74.     }
  75. };
  76.  
  77. Phone.prototype.disconnect = function () {
  78.     trace("Phone - disconnect");
  79.     Flashphoner.getInstance().disconnect();
  80. };
  81.  
  82. Phone.prototype.cancel = function () {
  83.     if (this.currentCall) {
  84.         this.hangup(this.currentCall);
  85.     }
  86. };
  87.  
  88. Phone.prototype.msrpCall = function (callee) {
  89.     var me = this;
  90.     callee = me.applyCalleeLetterCase(callee);
  91.     trace("Phone - msrpCall " + callee);
  92.  
  93.     me.currentCall = Flashphoner.getInstance().msrpCall({
  94.         callee: callee,
  95.         visibleName: 'Caller',
  96.         hasVideo: false,
  97.         inviteParameters: {param1: "value1", param2: "value2"},
  98.         isMsrp: true
  99.     });
  100. };
  101.  
  102. Phone.prototype.call = function (callee, hasVideo, mediaProvider) {
  103.     var me = this;
  104.     callee = me.applyCalleeLetterCase(callee);
  105.     trace("Phone - call " + callee);
  106.     if (!me.hasAccess(mediaProvider, hasVideo)) {
  107.         if (me.intervalId == -1) {
  108.             var checkAccessFunc = function () {
  109.                 if (me.hasAccess(mediaProvider, hasVideo)) {
  110.                     clearInterval(me.intervalId);
  111.                     me.intervalId = -1;
  112.                     me.call(callee, hasVideo, mediaProvider);
  113.                 }
  114.             };
  115.             me.intervalId = setInterval(checkAccessFunc, 500);
  116.         }
  117.         me.getAccess(mediaProvider, hasVideo);
  118.     } else if (me.hasAccess(mediaProvider, hasVideo)) {
  119.         var call = new Call();
  120.         call.callee = callee;
  121.         call.visibleName = "Caller";
  122.         call.hasVideo = hasVideo;
  123.         //uncomment for receive video in audio call
  124.         //call.receiveVideo = true;
  125.         call.inviteParameters = {param1: "value1", param2: "value2"};
  126.         call.mediaProvider = mediaProvider;
  127.         this.currentCall = Flashphoner.getInstance().call(call);
  128.         this.flashphonerListener.onCall();
  129.     } else {
  130.         trace("Microphone is not plugged in");
  131.     }
  132. };
  133.  
  134. Phone.prototype.changeVideoState = function (call, enable) {
  135.     trace("Phone - changeVideoState");
  136.     Flashphoner.getInstance().changeVideoState(call, enable);
  137. };
  138.  
  139. Phone.prototype.sendMessage = function (message) {
  140.     trace("Phone - sendMessage " + message.to + " body: " + message.body);
  141.     Flashphoner.getInstance().sendMessage(message);
  142. };
  143.  
  144. Phone.prototype.answer = function (call, hasVideo) {
  145.     trace("Phone - answer " + call.callId);
  146.     var me = this;
  147.     if (!me.hasAccess(call.mediaProvider, hasVideo)) {
  148.         if (me.intervalId == -1) {
  149.             var checkAccessFunc = function () {
  150.                 if (me.hasAccess(call.mediaProvider, hasVideo)) {
  151.                     clearInterval(me.intervalId);
  152.                     me.intervalId = -1;
  153.                     me.answer(call, hasVideo);
  154.                 }
  155.             };
  156.             me.intervalId = setInterval(checkAccessFunc, 500);
  157.         }
  158.         me.getAccess(call.mediaProvider, hasVideo);
  159.     } else if (me.hasAccess(call.mediaProvider, hasVideo)) {
  160.         call.hasVideo = hasVideo;
  161.         Flashphoner.getInstance().answer(call);
  162.         this.flashphonerListener.onAnswer(call.callId);
  163.     } else {
  164.         trace("Microphone is not plugged in");
  165.     }
  166. };
  167.  
  168. Phone.prototype.hangup = function (call) {
  169.     trace("Phone - hangup " + call.callId);
  170.     Flashphoner.getInstance().hangup(call);
  171.     this.flashphonerListener.onHangup();
  172. };
  173.  
  174. Phone.prototype.sendDTMF = function (callId, dtmf) {
  175.     trace("Phone - sendDTMF callId: " + callId + " dtmf: " + dtmf);
  176.     Flashphoner.getInstance().sendDTMF({callId: callId, dtmf: dtmf});
  177. };
  178.  
  179. Phone.prototype.hold = function (call) {
  180.     trace("Phone - hold callId: " + call.callId);
  181.     Flashphoner.getInstance().hold(call);
  182. };
  183.  
  184. Phone.prototype.holdForTransfer = function (call) {
  185.     trace("Phone - hold callId: " + call.callId);
  186.     Flashphoner.getInstance().holdForTransfer(call);
  187. };
  188.  
  189. Phone.prototype.unhold = function (call) {
  190.     trace("Phone - hold callId: " + call.callId);
  191.     Flashphoner.getInstance().unhold(call);
  192. };
  193.  
  194. Phone.prototype.transfer = function (callId, target) {
  195.     trace("Phone - transfer callId: " + callId + " target: " + target);
  196.     Flashphoner.getInstance().transfer({callId: callId, target: target});
  197. };
  198.  
  199. Phone.prototype.getStatistics = function() {
  200.     Flashphoner.getInstance().getCallStatistics(this.currentCall, function(statistics){
  201.         trace("Statistics: " +  JSON.stringify(statistics), null, ' ');
  202.     });
  203. };
  204.  
  205. Phone.prototype.sendXcapRequest = function () {
  206.     var url = ConfigurationLoader.getInstance().xcapUrl;
  207.     if (url) {
  208.         Flashphoner.getInstance().sendXcapRequest({url: url});
  209.     }
  210. };
  211.  
  212. Phone.prototype.subscribe = function () {
  213.     var subscribeObj = {};
  214.     subscribeObj.event = ConfigurationLoader.getInstance().subscribeEvent;
  215.     subscribeObj.expires = 3600;
  216.     Flashphoner.getInstance().subscribe(subscribeObj);
  217. };
  218.  
  219. Phone.prototype.changeRelationMyVideo = function (relation) {
  220.     trace("Phone - changeRelationMyVideo " + relation);
  221.     Flashphoner.getInstance().changeRelationMyVideo(relation);
  222. };
  223.  
  224. Phone.prototype.submitBugReport = function () {
  225.     var bugReportText = getElement('bugReportText').value;
  226.     trace("submitBugReport " + bugReportText);
  227.     Flashphoner.getInstance().submitBugReport({text: bugReportText, type: "no_media"});
  228. };
  229.  
  230. Phone.prototype.sendData = function (data) {
  231.     trace("sendData " + data);
  232.     Flashphoner.getInstance().sendData(data);
  233. };
  234.  
  235. /* ------------------ LISTENERS ----------------- */
  236.  
  237. Phone.prototype.connectionStatusListener = function (event) {
  238.     trace("Phone - Connection status " + event.status);
  239.     this.connectionStatus = event.status;
  240.     if (event.status == ConnectionStatus.Disconnected ||
  241.         event.status == ConnectionStatus.Failed) {
  242.         this.currentCall = null;
  243.         this.holdedCall = null;
  244.         $(".b-display__header__sip_login").html("");
  245.         $(".b-display__header__login").html("Log in");
  246.         $(".b-volume").removeClass("open");
  247.     } else if (event.status == ConnectionStatus.Established) {
  248.         $(".b-display__header__sip_login").html(event.sipLogin);
  249.         $(".b-display__header__login").html("Log out");
  250.     }
  251. };
  252.  
  253. Phone.prototype.registrationStatusListener = function (event) {
  254.     var status = event.status;
  255.     var sipObject = event.sipMessageRaw;
  256.     trace("Phone - registrationStatusListener " + status);
  257.     if (status == RegistrationStatus.Failed) {
  258.         this.viewMessage("Register fail, please check your SIP account details.");
  259.         this.disconnect();
  260.     } else if (status == RegistrationStatus.Unregistered) {
  261.         this.viewMessage("Unregistered from sip server");
  262.         this.disconnect();
  263.     } else if (status == WCSError.AUTHENTICATION_FAIL) {
  264.         this.viewMessage("Authentication failed, please check your SIP account details.");
  265.         this.disconnect();
  266.     } else {
  267.         SoundControl.getInstance().playSound("REGISTER");
  268.         this.flashphonerListener.onRegistered();
  269.  
  270.         if (ConfigurationLoader.getInstance().subscribeEvent != null && ConfigurationLoader.getInstance().subscribeEvent.length != 0) {
  271.             this.subscribe();
  272.         }
  273.         this.sendXcapRequest();
  274.     }
  275. };
  276.  
  277. Phone.prototype.onCallListener = function (event) {
  278.     var call = event;
  279.     trace("Phone - onCallListener " + call.callId + " call.mediaProvider: " + call.mediaProvider + " call.status: " + call.status);
  280.     if (this.currentCall != null && !call.incoming) {
  281.         this.holdedCall = this.currentCall;
  282.         this.currentCall = call;
  283.         trace("Phone - It seems like a hold: holdedCall: " + this.holdedCall.callId + " currentCall: " + this.currentCall.callId);
  284.     } else {
  285.         this.currentCall = call;
  286.         if (call.incoming == true) {
  287.             this.flashphonerListener.onIncomingCall(call.callId);
  288.         }
  289.         trace("Phone - It seems like a new call currentCall: " + this.currentCall.callId + " status: " + this.currentCall.status);
  290.  
  291.         $("body").addClass("voice_call__inc");                                            // add incoming call class
  292.         $(".b-nav").addClass("close");                                                          // hide black buttons and do 'answer call' buttons visible
  293.         $(".b-nav__inc, .call__inc__dial").addClass("open");
  294.         $(".call__inc__dial").addClass("open");
  295.         if (call.incoming) {
  296.             $(".call__inc__dial").text(call.caller);
  297.         }
  298.     }
  299. };
  300.  
  301. Phone.prototype.callStatusListener = function (event) {
  302.     var sipObject = event.sipMessageRaw;
  303.     if (event.status==CallStatus.FAILED){
  304.         trace("Call failed: callId: "+event.id+" info: "+event.info);
  305.         return;
  306.     }
  307.     var call = event;
  308.     trace("Phone - callStatusListener call id: " + call.callId + " status: " + call.status + " mediaProvider: " + call.mediaProvider);
  309.     if (this.currentCall.callId == call.callId) {
  310.         this.currentCall.status = call.status;
  311.         if (call.status == CallStatus.FINISH) {
  312.             trace("Phone - ... Call is finished...");
  313.             SoundControl.getInstance().stopSound("RING");
  314.             if (this.holdedCall != null) {
  315.                 this.currentCall = this.holdedCall;
  316.                 this.holdedCall = null;
  317.             } else if (this.isCurrentCall(call)) {
  318.                 this.currentCall = null;
  319.                 this.flashphonerListener.onRemoveCall();
  320.                 SoundControl.getInstance().playSound("FINISH");
  321.  
  322.                 $(".voice_call__transfer").removeClass("tr_call__pause");     // remove additional style of the transfer button
  323.                 $("#transfer").val("");                                                         // remove value in the transfer field if the value is present
  324.                 $(".b-nav__cancel_call span").text("Cancel");                       // return to initial state of button
  325.                 $(".interlocutor2").text("");                                 // clear login name of callee in the call window
  326.                 $(".voice_call__stop").addClass("open");          // do visible hold button
  327.  
  328.                 this.cancel();
  329.                 clearInterval(this.timerInterval);
  330.                 this.timerInterval = null;
  331.                 $(".b-time").html("<span class='b-min'>00</span>:<span class='b-sec'>00</span>");     // return timer to initial state
  332.  
  333.                 $(".b-volume").removeClass("open");
  334.                 $(".b-send_video").removeClass("open");
  335.             }
  336.         } else if (call.status == CallStatus.HOLD) {
  337.             trace('Phone - ...Call on hold...');
  338.             if (call.incoming) {
  339.                 $(".voice_call__call__pause").text(call.caller);
  340.             } else {
  341.                 $(".voice_call__call__pause").text(call.callee);
  342.             }
  343.             $(".voice_call__call__pause").addClass("open"); // do visible button of unhold and call window with hold button
  344.             $(".voice_call__call__play").addClass("close");       // hide call view
  345.             $(".b-video").removeClass("open");                          // hide video view (if exists)
  346.             $(".voice_call__transfer").addClass("tr_call__pause");      // add class for transfer button to know point of return
  347.         } else if (call.status == CallStatus.ESTABLISHED) {
  348.             trace('Phone - ...Talking...');
  349.             $(".b-alert, .b-nav__inc, .call__inc__dial").removeClass("open"); // hide a set of buttons and buttons allow/deny
  350.             $(".b-nav").removeClass("close");   // re-open default navigation buttons (i.e. if the buttons was hidden while an incoming call)
  351.             if ($("body").hasClass("video")) {
  352.                 $(".b-video__video").addClass("open");
  353.                 $(".b-video, .hook").addClass("open");
  354.             } else {
  355.                 $(".hook").addClass("open");
  356.             }
  357.  
  358.             $(".b-nav__cancel_call span").text("Hangup");   // change text of "Cancel" button
  359.             if ($("body").hasClass("voice_call__inc")) {    // if the call is incoming
  360.                 $(".voice_call__call").addClass("open");    // open talk view
  361.                 if (call.incoming) {
  362.                     $(".interlocutor2").text(call.caller);
  363.                 } else {
  364.                     $(".interlocutor2").text(call.callee);
  365.                 }
  366.             } else {
  367.                 $(".call__out__dial").removeClass("open");  // hide call view
  368.                 $(".voice_call__call").addClass("open");    // open talk view
  369.                 $(".b-nav__cancel_call span").text("Hangup");     // change text for Hangup button
  370.                 $(".interlocutor2").text($(".b-numbers").val());  // set number of callee in the talk view
  371.                 $(this).removeClass("open");                                                                                  // hide 'Answer' button
  372.             }
  373.  
  374.             if (MediaProvider.Flash == call.mediaProvider && ConfigurationLoader.getInstance().reoffersEnabled) {
  375.                 $(".b-send_video").addClass("open");
  376.             }
  377.  
  378.             if (call.hasVideo) {
  379.                 $(".b-send_video").text("Stop video");
  380.             } else {
  381.                 $(".b-send_video").text("Send video");
  382.             }
  383.  
  384.             this.startTimer();
  385.  
  386.             $(".voice_call__transfer").removeClass("close");
  387.             $(".voice_call__stop").addClass("open");        // do visible hold button
  388.             $(".voice_call__play").removeClass("open");                             // hide unhold button
  389.             $(".voice_call__call__pause").removeClass("open");    // hide hold view and transfer view (if the views was opened)
  390.             $(".voice_call__call__play").removeClass("close");                      // open talk view
  391.             $(".voice_call__transfer").removeClass("tr_call__pause");         // remove class from the transfer button (if the class exists, then after transfer cancellation)
  392.  
  393.             SoundControl.getInstance().stopSound("RING");
  394.         } else if (call.status == CallStatus.RING) {
  395.             trace('Phone - ...Ringing...');
  396.             if (this.isRingSoundAllowed()) {
  397.                 SoundControl.getInstance().playSound("RING");
  398.             }
  399.         } else if (call.status == CallStatus.RING_MEDIA) {
  400.             trace('Phone - ...Ringing...');
  401.             SoundControl.getInstance().stopSound("RING");
  402.         } else if (call.status == CallStatus.BUSY) {
  403.             SoundControl.getInstance().playSound("BUSY");
  404.         } else if (call.status == CallStatus.SESSION_PROGRESS) {
  405.             trace('Phone - ...Call in Progress...');
  406.             SoundControl.getInstance().stopSound("RING");
  407.         }
  408.     } else {
  409.         if (this.holdedCall.callId == call.callId) {
  410.             if (call.status == CallStatus.FINISH) {
  411.                 trace("It seems we received FINISH status on holdedCall. Just do null the holdedCall.");
  412.                 this.holdedCall = null;
  413.             }
  414.         }
  415.     }
  416. };
  417.  
  418. Phone.prototype.onTransferStatusListener = function (event) {
  419.     trace("Phone - onTransferStatusListener status:" + event.status + " incoming:" + event.incoming);
  420. };
  421.  
  422. Phone.prototype.onTransferEventListener = function (event) {
  423.     trace("Phone - onTransferEventListener status:" + event.status + " incoming:" + event.incoming);
  424. };
  425.  
  426. Phone.prototype.cancel = function () {
  427.     if (this.currentCall) {
  428.         this.hangup(this.currentCall);
  429.     } else {
  430.         $(".call__out__dial").text("calling to");                             // return to initial view of outgoing call (view without number or login name)
  431.         $("body").removeAttr("class");                                              // remove all classes from the body
  432.         $(".b-mike, .call__out__dial, .call__inc__dial, .voice_call__call, .voice_call__play, .voice_call__call__pause, .b-transfer, .b-video, .b-video__video, .b-nav__inc, .b-alert").removeClass("open"); // close set of blocks which are hidden by default
  433.         $(".b-display__bottom__number>span, .voice_call__call__play, .voice_call__transfer, .b-nav").removeClass("close");    // open a set of blocks which might be hidden, but the blocks are visible by default
  434.         $(".b-alert").text("").removeClass("video_alert");  // initial view of video alert
  435.  
  436.         this.hideFlashAccess();
  437.     }
  438. };
  439.  
  440. Phone.prototype.messageStatusListener = function (event) {
  441.     var message = event;
  442.     trace("Phone - messageStatusListener id = " + message.id + " status = " + message.status);
  443.     if (message.status == MessageStatus.ACCEPTED) {
  444.         $('#message_' + message.id + ' .b-chat__message__text').css("color", "#000000");
  445.     } else if (message.status == MessageStatus.FAILED ||
  446.         message.status == MessageStatus.IMDN_ERROR ||
  447.         message.status == MessageStatus.FAILED ||
  448.         message.status == MessageStatus.IMDN_FORBIDDEN) {
  449.         $('#message_' + message.id + ' .b-chat__message__text').css("color", "#d90000");
  450.     } else if (message.status == MessageStatus.IMDN_DELIVERED) {
  451.         $('#message_' + message.id + ' .b-chat__message__text').css("color", "#226900");
  452.     }
  453. };
  454.  
  455. Phone.prototype.onMessageListener = function (event) {
  456.     var message = event;
  457.     if (message.contentType == "application/im-iscomposing+xml" || message.contentType == "message/fsservice+xml") {
  458.         trace("ignore message: " + message.body);
  459.         if (ConfigurationLoader.getInstance().disableUnknownMsgFiltering) {
  460.             message.body = escapeXmlTags(message.body);
  461.             SoundControl.getInstance().playSound("MESSAGE");
  462.         }
  463.         return;
  464.     }
  465.  
  466.     //convert body
  467.     var body = this.convertMessageBody(message.body, message.contentType);
  468.     if (body) {
  469.         message.body = body;
  470.         SoundControl.getInstance().playSound("MESSAGE");
  471.     } else {
  472.         trace("Not displaying message " + message.body + ", body is null after convert");
  473.         if (ConfigurationLoader.getInstance().disableUnknownMsgFiltering) {
  474.             message.body = escapeXmlTags(message.body);
  475.             SoundControl.getInstance().playSound("MESSAGE");
  476.         }
  477.     }
  478.  
  479.     trace("Phone - onMessageListener id = " + message.id + " body = " + message.body);
  480.     var tab = $('#tab_' + message.from);
  481.     if (tab.length == 0) {
  482.         this.chatCreateTab(message.from);
  483.     } else {
  484.         this.chatSelectTab(tab);
  485.     }
  486.     $('<div class="b-chat__message"><div class="b-chat__message__head"><span class="b-chat__message__time">' + new Date().toLocaleString() + '</span><span class="b-chat__message__author">' + message.from + '</span></div><div class="b-chat__message__text">' + message.body.replace(/\n/g, "<br />") + '</div></div>').appendTo($(".b-chat_tab.open .mCSB_container"));
  487.     this.chatScrollDown();
  488. };
  489.  
  490. Phone.prototype.convertMessageBody = function (messageBody, contentType) {
  491.     trace("Phone - convertMessageBody " + contentType);
  492.     if (contentType == "application/fsservice+xml") {
  493.         var xml = $.parseXML(messageBody);
  494.         var missedCallNotification;
  495.         var fsService = $(xml).find("fs-services").find("fs-service");
  496.         var action = fsService.attr("action");
  497.         if (action == "servicenoti-indicate") {
  498.             var caw = this.parseMsn(fsService, "caw");
  499.             if (!!caw) {
  500.                 missedCallNotification = caw;
  501.             } else {
  502.                 missedCallNotification = parseMsn(fsService, "mcn");
  503.             }
  504.         } else if (action == "serviceinfo-confirm") {
  505.             //service status confirmation
  506.             missedCallNotification = "Service status: " + $(fsService.find("mcn").find("mcn-data")).attr("status");
  507.         }
  508.         if (missedCallNotification !== undefined) return missedCallNotification;
  509.  
  510.     } else if (contentType == "application/vnd.oma.push") {
  511.         var xml = $.parseXML(messageBody);
  512.         /**
  513.          * application/vnd.oma.push will contain xml with app information
  514.          * Try to handle this information or discard xml
  515.          */
  516.         var content;
  517.         if ($(xml).find("ums-service")) {
  518.             //voice mail service message
  519.             content = $(xml).find("ni-data").attr("content");
  520.         }
  521.         return content;
  522.     }
  523.  
  524.     return messageBody;
  525.  
  526. };
  527.  
  528. Phone.prototype.parseMsn = function (fsService, mcn) {
  529.     trace("Phone - parseMcn: " + mcn);
  530.     var caw = fsService.find(mcn);
  531.     var ret = null;
  532.     if (!!caw) {
  533.         var cawData = caw.find(mcn + "-data");
  534.         if (!!cawData) {
  535.             var sender = $(cawData).attr("sender");
  536.             if (!!sender) {
  537.                 trace("Phone - Missed call: " + sender);
  538.                 ret = "Missed call from " + sender;
  539.             }
  540.         }
  541.     }
  542.     return ret;
  543. };
  544.  
  545. Phone.prototype.recordingStatusListener = function (recordReport) {
  546.     trace("Phone - recordingStatusListener: " + recordReport.report.mixedFilename);
  547. };
  548.  
  549. Phone.prototype.subscriptionStatusListener = function (event) {
  550.     var subscriptionObject = event;
  551.     var sipObject = event.sipMessageRaw;
  552.     trace("Phone - subscriptionStatusListener event: " + subscriptionObject.event + " expires: " + subscriptionObject.expires + " status: " + subscriptionObject.status + " terminate: " + subscriptionObject.terminate);
  553.     trace("Phone - subscriptionStatusListener body: " + subscriptionObject.requestBody);
  554.     if (subscriptionObject.event == "reg") {
  555.         if (subscriptionObject.terminate) {
  556.             this.disconnect();
  557.         }
  558.     }
  559. };
  560.  
  561. Phone.prototype.xcapStatusListener = function (xcapResponse) {
  562.     trace("Phone - xcapStatusListener " + xcapResponse);
  563.     var xml = $.parseXML(xcapResponse.responseBody);
  564.     var history = $(xml).find("history-list").find("history");
  565.     if (history != null && history.length != 0) {
  566.         if (ConfigurationLoader.getInstance().msrpCallee != null && ConfigurationLoader.getInstance().msrpCallee.length != 0) {
  567.             this.msrpCall(ConfigurationLoader.getInstance().msrpCallee);
  568.         }
  569.     }
  570. };
  571.  
  572. Phone.prototype.bugReportStatusListener = function (event) {
  573.     trace("Phone - bugReportStatusListener; filename - " + event.filename);
  574. };
  575.  
  576. Phone.prototype.onDataEventListener = function (event) {
  577.     trace("Phone - onDataEventListener; received data " + event.data);
  578. };
  579.  
  580. Phone.prototype.dataStatusEventListener = function (event) {
  581.     trace("Phone - DataStatusEventListener; received status " + event.status);
  582. };
  583.  
  584. Phone.prototype.errorStatusEvent = function (event) {
  585.     var code = event.status;
  586.     trace("Phone - errorStatusEvent " + code);
  587.     if (code == WCSError.MIC_ACCESS_PROBLEM || code == WCSError.MIC_CAM_ACCESS_PROBLEM) {
  588.         this.cancel();
  589.         this.viewMessage("ERROR - " + event.info);
  590.     } else {
  591.         this.cancel();
  592.         if (code == WCSError.CONNECTION_ERROR) {
  593.             this.viewMessage("ERROR - Can`t connect to server.");
  594.         } else if (code == WCSError.AUTHENTICATION_FAIL) {
  595.             this.viewMessage("ERROR - Register fail, please check your SIP account details.");
  596.             window.setTimeout("disconnect();", 3000);
  597.         } else if (code == WCSError.USER_NOT_AVAILABLE) {
  598.             this.viewMessage("ERROR - User not available.");
  599.         } else if (code == WCSError.LICENSE_RESTRICTION) {
  600.             this.viewMessage("ERROR - You trying to connect too many users, or license is expired");
  601.         } else if (code == WCSError.LICENSE_NOT_FOUND) {
  602.             this.viewMessage("ERROR - Please get a valid license or contact Flashphoner support");
  603.         } else if (code == WCSError.INTERNAL_SIP_ERROR) {
  604.             this.viewMessage("ERROR - Unknown error. Please contact support.");
  605.         } else if (code == WCSError.REGISTER_EXPIRE) {
  606.             this.viewMessage("ERROR - No response from VOIP server during 15 seconds.");
  607.         } else if (code == WCSError.SIP_PORTS_BUSY) {
  608.             this.viewMessage("ERROR - SIP ports are busy. Please open SIP ports range (30000-31000 by default).");
  609.             window.setTimeout("disconnect();", 3000);
  610.         } else if (code == WCSError.MEDIA_PORTS_BUSY) {
  611.             this.viewMessage("ERROR - Media ports are busy. Please open media ports range (31001-32000 by default).");
  612.         } else if (code == WCSError.WRONG_SIPPROVIDER_ADDRESS) {
  613.             this.viewMessage("ERROR - Wrong domain.");
  614.             window.setTimeout("disconnect();", 3000);
  615.         } else if (code == WCSError.CALLEE_NAME_IS_NULL) {
  616.             this.viewMessage("ERROR - Callee name is empty.");
  617.         } else if (code == WCSError.WRONG_FLASHPHONER_XML) {
  618.             this.viewMessage("ERROR - Flashphoner.xml has errors. Please check it.");
  619.         } else if (code == WCSError.PAYMENT_REQUIRED) {
  620.             this.viewMessage("ERROR - Payment required, please check your balance.");
  621.         } else if (code == WCSError.REST_AUTHORIZATION_FAIL) {
  622.             this.viewMessage("ERROR - Rest authorization fail.");
  623.             window.setTimeout("disconnect();", 3000);
  624.         } else if (code == WCSError.REST_FAIL) {
  625.             this.viewMessage("ERROR - Rest fail.");
  626.         }
  627.     }
  628.  
  629.     this.flashphonerListener.onError();
  630. };
  631.  
  632. Phone.prototype.viewMessage = function (message) {
  633.     trace(message);
  634. };
  635.  
  636.  
  637.  
  638. Phone.prototype.hideFlashAccess = function () {
  639.     if ($(".b-video").hasClass("flash_access")) {
  640.         $(".b-video").removeClass("flash_access").resizable("enable");
  641.         $(".b-video__flash").removeClass("access");
  642.         $(".b-video__flash_footer").removeClass("open");
  643.     }
  644. };
  645.  
  646. Phone.prototype.hasAccess = function (mediaProvider, hasVideo) {
  647.     var hasAccess = Flashphoner.getInstance().hasAccess(mediaProvider, hasVideo);
  648.  
  649.     if (hasAccess) {
  650.         if (MediaProvider.Flash == mediaProvider) {
  651.             this.hideFlashAccess();
  652.         } else {
  653.             $(".b-video").draggable("enable");
  654.             $("body").removeClass("mike");
  655.         }
  656.     }
  657.     return hasAccess;
  658. };
  659.  
  660.  
  661. Phone.prototype.getAccess = function (mediaProvider, hasVideo) {
  662.     if (MediaProvider.Flash == mediaProvider) {
  663.         $(".b-video").addClass("flash_access");
  664.         $(".b-video").draggable("disable");
  665.         $(".b-video").resizable("disable");
  666.         $(".b-video__flash").addClass("access");
  667.         $(".b-video__flash").zIndex(1000);
  668.         $(".b-video__flash_footer").addClass("open");
  669.         $(".b-video__flash_footer").html("Please <span>allow</span> access to your web camera and microphone.");
  670.         //check flash div dimensions
  671.         if ($("#flashVideoDiv").width() < 215 || $("#flashVideoDiv").height() < 138) {
  672.             console.log("Size of flashVideoDiv is to small, most likely there will be no Privacy dialog");
  673.         }
  674.  
  675.     } else {
  676.         //hide flash div
  677.         $(".b-video").draggable("enable");
  678.         $(".b-video__flash").zIndex(0);
  679.         hasVideo ? $(".b-alert").html("Please <span>allow</span> access to your web camera and microphone.") : $(".b-alert").html("please <span>allow</span> access to audio device");
  680.         $("body").addClass("mike");
  681.     }
  682.  
  683.     Flashphoner.getInstance().getAccess(mediaProvider, hasVideo);
  684.  
  685. };
  686.  
  687. Phone.prototype.openVideoView = function () {
  688.     var me = this;
  689.     var mediaProvider = me.getMediaProvider();
  690.  
  691.     if ($(".b-video").hasClass("open")) {             // open/close main video view and change class video for body
  692.         $(".b-video").removeClass("open").removeAttr("id");
  693.         $(".b-video").removeAttr('style');
  694.         $("body").removeClass("video");
  695.     } else {
  696.         $("#active").removeAttr("id");
  697.         $(".b-video").addClass("open").attr("id", "active");
  698.         $("body").addClass("video");
  699.     }
  700.     if ($(".voice_call__call").hasClass("open")) {
  701.         $(".b-video__video").addClass("open");
  702.     }
  703.  
  704.     if (!me.hasAccess(mediaProvider, true)) {
  705.         if (me.intervalId == -1) {
  706.             var checkAccessFunc = function () {
  707.                 if (me.hasAccess(mediaProvider, true)) {
  708.                     clearInterval(me.intervalId);
  709.                     me.intervalId = -1;
  710.                     $(".b-alert").removeClass("open");
  711.                 }
  712.             };
  713.             me.intervalId = setInterval(checkAccessFunc, 500);
  714.         }
  715.         me.getAccess(mediaProvider, true);
  716.     }
  717. };
  718.  
  719.  
  720. // talk timer
  721. Phone.prototype.startTimer = function () {
  722.     var me = this;
  723.     if (!me.timerInterval) {
  724.         me.start = 0;
  725.         me.min = 0;
  726.         me.timerInterval = setInterval(function () {
  727.             me.start++;
  728.             if (me.start > 59) {
  729.                 me.start = 0;
  730.                 me.min++;
  731.                 if (me.min < 10) {
  732.                     $(".b-min").html("0" + me.min);
  733.                 } else $(".b-min").html(me.min);
  734.             }
  735.             if (me.start < 10) {
  736.                 $(".b-sec").html("0" + me.start);
  737.             } else $(".b-sec").html(me.start);
  738.         }, 1000);
  739.     }
  740. };
  741.  
  742. Phone.prototype.chatSelectTab = function (elem) {
  743.     if (!elem.hasClass("open")) {                                                                     // if the tab is inactive
  744.         this.elem_prev = $(".b-chat__nav__tab.open").attr("id");                                // save id of previous tab
  745.         $(".b-chat__nav__tab.open, .b-chat_tab.open, .b-chat__new__nav, .b-chat__new__list, .b-chat__nav__tab#new, .b-chat_tab.new").removeClass("open");
  746.         elem.addClass("open");                                                                              // do tab and its content visible
  747.         $(".b-chat_tab." + elem.attr("id")).addClass("open");
  748.         $(".b-chat_tab.open .b-chat__window").mCustomScrollbar({                    // init scroll-bar
  749.             scrollInertia: 50,
  750.             scrollButtons: {
  751.                 enable: false
  752.             }
  753.         });
  754.         this.chatScrollDown();
  755.     }
  756. };
  757.  
  758. Phone.prototype.viewMessage = function (message) {
  759.     $(".b-alert__error__message").html("<p>" + message + "</p>");
  760.     $(".b-alert__error").addClass("open");
  761. };
  762.  
  763. Phone.prototype.chatCreateTab = function (chatUsername) {
  764.     this.chatNames += '<p>' + chatUsername + '</p>';
  765.     Flashphoner.getInstance().setCookie("chatNames", this.chatNames);
  766.     $('.b-chat__new__list .mCSB_container').html(this.chatNames);
  767.  
  768.     $(".b-chat__nav__tab.open, .b-chat_tab.open, .b-chat__new__nav, .b-chat__new__list, .b-chat__nav__tab#new, .b-chat_tab.new").removeClass("open");
  769.     $("#new__chat").val("");                                            // clear search view
  770.     $(".b-chat__nav__tab#new").before('<div class="b-chat__nav__tab open" id="tab_' + chatUsername + '"><span class="tab_text">' + chatUsername + '</span><span class="tab_close"></span></div>'); //tab id is username
  771.     $(".b-chat__new__list p.active").removeClass("active");
  772.     $(".b-chat_tab.new").before('<div class="b-chat_tab open ' + $(".b-chat__nav__tab.open").attr("id") + '"><div class="b-chat__window mCustomScrollbar"></div><div class="b-chat__text"><textarea></textarea><input type="button" value="send" /></div></div>');
  773.     $(".b-chat_tab.open .b-chat__window").mCustomScrollbar({ // init scroll-bar if we load a history
  774.         scrollInertia: 50,
  775.         scrollButtons: {
  776.             enable: false
  777.         }
  778.     });
  779.     this.chatScrollDown();
  780. };
  781.  
  782. Phone.prototype.chatScrollDown = function () {
  783.     $(".b-chat_tab.open .b-chat__window .mCSB_container").css("top", $(".b-chat_tab.open .b-chat__window .mCSB_container").height() - $(".b-chat_tab.open .b-chat__window .mCSB_container").parent().height() + 20 + "px");
  784. };
  785.  
  786. /* ------------- Additional interface functions --------- */
  787. Phone.prototype.isCurrentCall = function (call) {
  788.     return this.currentCall != null && this.currentCall.callId == call.callId;
  789. };
  790.  
  791. Phone.prototype.isRingSoundAllowed = function () {
  792.     try {
  793.         if (ConfigurationLoader.getInstance().suppressRingOnActiveAudioStream) {
  794.             trace("Phone - isRingSoundAllowed false");
  795.             return false;
  796.         }
  797.     } catch (error) {
  798.     }
  799.     trace("Phone - isRingSoundAllowed true");
  800.     return true;
  801. };
  802.  
  803. Phone.prototype.applyCalleeLetterCase = function (callee) {
  804.     if (callee) {
  805.         if ("uppercase" == ConfigurationLoader.getInstance().calleeLetterCase) {
  806.             return callee.toUpperCase();
  807.         }
  808.         if ("lowercase" == ConfigurationLoader.getInstance().calleeLetterCase) {
  809.             return callee.toLowerCase();
  810.         }
  811.     }
  812.     return callee;
  813. };
  814.  
  815.  
  816. $(document).ready(function () {
  817.  
  818.     var phone = new Phone();
  819.  
  820.     phone.chatNames = unescape(Flashphoner.getInstance().getCookie("chatNames"));
  821.  
  822.     ConfigurationLoader.getInstance(function (configuration) {
  823.         trace("Configuration loaded");
  824.         configuration.localMediaElementId = 'localMediaElement';
  825.         configuration.remoteMediaElementId = 'remoteMediaElement';
  826.         configuration.elementIdForSWF = "flashVideoDiv";
  827.         configuration.pathToSWF = "../../dependencies/flash/MediaManager.swf";
  828.  
  829.         Flashphoner.getInstance().init(configuration);
  830.         phone.init();
  831.     });
  832.  
  833.     $(".b-send_video").live("click", function () {
  834.         if ($(this).text() == "Send video") {
  835.             phone.changeVideoState(phone.currentCall, true);
  836.             $(this).text("Stop video");
  837.         } else {
  838.             phone.changeVideoState(phone.currentCall, false);
  839.             $(this).text("Send video");
  840.         }
  841.     });
  842.  
  843.     // open/close authentication view
  844.     $(".b-display__header__login, .b-login__cancel").live("click", function () {
  845.         if (phone.connectionStatus == ConnectionStatus.Established || phone.connectionStatus == ConnectionStatus.Registered) {
  846.             phone.disconnect();
  847.         } else {
  848.             $('#sipLogin').val(Flashphoner.getInstance().getCookie('sipLogin'));
  849.             $('#sipPassword').val(Flashphoner.getInstance().getCookie('sipPassword'));
  850.             $('#sipAuthenticationName').val(Flashphoner.getInstance().getCookie('sipAuthenticationName'));
  851.             $('#sipDomain').val(Flashphoner.getInstance().getCookie('sipDomain'));
  852.             $('#sipOutboundProxy').val(Flashphoner.getInstance().getCookie('sipOutboundProxy'));
  853.             $('#sipPort').val(Flashphoner.getInstance().getCookie('sipPort'));
  854.  
  855.             $(".b-login").toggleClass("open");
  856.             $("#active").removeAttr("id");
  857.             $(".b-login").hasClass("open") ? $(".b-login").attr("id", "active") : $(".b-login").removeAttr("id");
  858.         }
  859.     });
  860.  
  861.     // authentication
  862.     $(".b-login input[type='button']").live("click", function () {
  863.         $(".b-display__header__login").html("Connecting");
  864.         $(".b-login").removeClass("open").removeAttr("id");
  865.         phone.connect();
  866.     });
  867.  
  868.     // open/close microphone gain control
  869.     $(".b-display__header__volume").live("click", function () {
  870.         if (phone.currentCall) {
  871.             $(".b-volume").hasClass("open") ? $(".b-volume").removeClass("open") : $(".b-volume").addClass("open");
  872.         }
  873.     });
  874.     // open/close loudspeaker control
  875.     $("#volume").slider({
  876.         value: 60,
  877.         orientation: "horizontal",
  878.         range: "min",
  879.         animate: true,
  880.         slide: function (event, ui) {
  881.             $(".volume-percent").html(ui.value + "%");
  882.             Flashphoner.getInstance().setVolume(phone.currentCall, ui.value);
  883.         }
  884.     });
  885.     // digital value of loudspeaker volume
  886.     $(".volume-percent").html($("#volume").slider("value") + "%");
  887.  
  888.     // digital value of microphone gain
  889.     $(".b-display__header__mike").live("click", function () {
  890.         $(".b-mike").hasClass("open") ? $(".b-mike").removeClass("open") : $(".b-mike").addClass("open");
  891.     });
  892.     $("#mike").slider({
  893.         value: 60,
  894.         orientation: "horizontal",
  895.         range: "min",
  896.         animate: true,
  897.         slide: function (event, ui) {
  898.             $(".mike-percent").html(ui.value + "%");
  899.         }
  900.     });
  901.     $(".mike-percent").html($("#volume").slider("value") + "%");
  902.  
  903.     // on click "Video" icon in the top menu
  904.     $(".b-display__header__video").live("click", function () {
  905.         phone.openVideoView();
  906.     });
  907.     // close video upon (Ð¥) click
  908. k
  909.     $(".b-video__close").live("click", function (e) {
  910.         $(".b-video").removeClass("open").removeAttr("id");
  911.         $(".b-video").removeAttr('style');
  912.         if ($(".b-video").hasClass("flash_access")) {
  913.             phone.cancel();
  914.         }
  915.     });
  916.   // change video view dimensions
  917. s
  918.   //$(".b-video, .b-login, .b-alert__error, .b-chat, .b-transfer").draggable();     // set video view draggable
  919. e
  920.     $(".b-video").resizable({
  921.         minHeight: 240,
  922.         minWidth: 320,
  923.         aspectRatio: 4 / 3
  924.     });
  925.  
  926.   // enter phone number
  927. r
  928.     $(".b-display__bottom__number>span").live("click", function () // on click by 'Enter your number here'
  929. '
  930.         if (phone.connectionStatus == ConnectionStatus.Established || phone.connectionStatus == ConnectionStatus.Registered) {
  931.             $(this).addClass("close");
  932.             $(".b-numbers__clear").addClass("open");
  933.             $(".b-numbers").addClass("write").focus();
  934.         }
  935.     });
  936.     $(document).keyup(function (event) {                                // listening keyboard input
  937. t
  938.         if (($(".b-numbers").is(":focus")) && (event.keyCode == 8)) // if the focus on the number field and Backspace is pressed
  939. d
  940.             num = $(".b-numbers").val().length;                   // check number of symbols in the field which remain after the symbol removing
  941. g
  942.             if (num == 0) {                                                   // if the latest digit was removed then return to initial position
  943. n
  944.                 $(".b-numbers__clear").removeClass("open");
  945.                 $(".b-numbers").removeClass("write");
  946.                 $(".b-display__bottom__number>span").removeClass("close");
  947.             }
  948.         }
  949.     });
  950.     $(".b-num td").live("click", function () {
  951.         if (phone.connectionStatus == ConnectionStatus.Established || phone.connectionStatus == ConnectionStatus.Registered) {
  952.             if (!$(".b-numbers").hasClass("write")) // if the symbols are entered then remove the text block
  953. k
  954.                 $(".b-display__bottom__number>span").addClass("close");
  955.                 $(".b-numbers").addClass("write").next().addClass("open");
  956.             }
  957.             if (phone.currentCall &&
  958.                 (CallStatus.ESTABLISHED == phone.currentCall.status || CallStatus.HOLD == phone.currentCall.status)) {
  959.                 phone.sendDTMF(phone.currentCall.callId, $(this).text());
  960.             } else {
  961.                 if ($(".b-transfer").hasClass("open")) {
  962.                     $("#transfer").val($("#transfer").val() + $(this).text());
  963.                 } else if (!phone.currentCall) {
  964.                     $(".b-numbers").val($(".b-numbers").val() + $(this).text());
  965.                 }
  966.             }
  967.         }
  968.     });
  969.   // removing of symbols
  970. s
  971.     $(".b-numbers__clear").live("click", function () {
  972.         $(".b-numbers").val($(".b-numbers").val().substring(0, $(".b-numbers").val().length - 1));
  973.         num = $(".b-numbers").val().length;
  974.         if (num == 0) // if the latest digit was removed then return to initial position
  975. n
  976.             $(this).removeClass("open");
  977.             $(".b-numbers").removeClass("write");
  978.             $(".b-display__bottom__number>span").removeClass("close");
  979.         }
  980.     });
  981.  
  982.   // do video and audio call
  983. l
  984.     $(".b-nav__voice, .b-nav__video").live("click", function () {
  985.         if ($(".b-numbers").hasClass("write")) {// check if phone number was entered
  986. d
  987.             $("body").addClass("voice_call__out");
  988.             $(".call__out__dial").addClass("open").html($(".call__out__dial").html() + " + $("(".b-numbers").val())// open outgoing call block and writ here callee number
  989. r
  990.             if ($(this).hasClass("b-nav__video")) {
  991.                 $("body").addClass("video")
  992.             // if it is a video call then add the body class (for alert view)
  993. )
  994.  
  995.             var mediaProvider = phone.getMediaProvider();
  996.  
  997.             if ($("body").hasClass("video")) {
  998.                 phone.call($(".b-numbers").val(), true, mediaProvider);
  999.             } else {
  1000.                 phone.call($(".b-numbers").val(), false, mediaProvider);
  1001.             }
  1002.  
  1003.         }
  1004.     });
  1005.  
  1006.   // answer the incoming call
  1007. l
  1008.     $(".b-nav__answer, .b-nav__answer_video").live("click", function () {
  1009.         if ($(this).hasClass("b-nav__answer_video")) // if it is a video call then open view with video
  1010. o
  1011.             $("body").addClass("video");
  1012.         }
  1013.         if (phone.currentCall) {
  1014.             phone.answer(phone.currentCall, $(this).hasClass("b-nav__answer_video"));
  1015.         }
  1016.     });
  1017.  
  1018.     $(".voice_call__stop").live("click", function () // if the call is on hold
  1019. d
  1020.         if (phone.currentCall) {
  1021.             phone.hold(phone.currentCall);
  1022.             $(".voice_call__transfer").addClass("close");
  1023.             $(this).removeClass("open");              // hide the hold button
  1024. n
  1025.             $(".voice_call__play").addClass("open")// do visible button of returning to the call and hold view
  1026. w
  1027.         }
  1028.     });
  1029.  
  1030.     $(".voice_call__play").live("click", function () // return to talk
  1031. k
  1032.         if (phone.currentCall) {
  1033.             phone.unhold(phone.currentCall);
  1034.             $(".voice_call__transfer").removeClass("close");
  1035.             $(this).removeClass("open");              // hide unhold button
  1036. n
  1037.             $(".voice_call__stop").addClass("open");                    // do visible hold button
  1038. n
  1039.         }
  1040.     });
  1041.  
  1042.     $(".voice_call__transfer").live("click", function () {                          // if the transfer button is pressed
  1043. d
  1044.         if (phone.currentCall) {
  1045.             phone.holdForTransfer(phone.currentCall);
  1046.             $(".voice_call__transfer").addClass("close");// hide transfer button
  1047. n
  1048.             $(".b-transfer").addClass("open");        // open transfer view and hold view
  1049. w
  1050.             $(".b-transfer").attr("id", "active");
  1051.             $("#transfer").focus();                                                                   // set focus on the phone number field
  1052. d
  1053.         }
  1054.     });
  1055.  
  1056.     $(".b-transfer__cancel").live("click", function () {
  1057.         if (phone.currentCall) {
  1058.             phone.unhold(phone.currentCall);
  1059.             $(".voice_call__play").removeClass("open");                 // hide unhold button
  1060. n
  1061.             $(".voice_call__stop").addClass("open");                    // do visible hold button
  1062. n
  1063.         }
  1064.         $(".voice_call__transfer").removeClass("close");
  1065.         $(".b-transfer").removeClass("open").removeAttr("id");
  1066.     });
  1067.  
  1068.     $(".b-transfer__ok").live("click", function () {
  1069.         if (phone.currentCall) {
  1070.             phone.transfer(phone.currentCall.callId, $("#transfer").val());
  1071.         }
  1072.         $(".voice_call__transfer").removeClass("close");
  1073.         $(".b-transfer").removeClass("open").removeAttr("id");
  1074.  
  1075.     });
  1076.  
  1077.     $(".b-nav__chat").live("click", function () {                                         // on "Chat" button click
  1078. k
  1079.         if (phone.connectionStatus == ConnectionStatus.Established || phone.connectionStatus == ConnectionStatus.Registered) {
  1080.             $('.b-chat__new__list .mCSB_container').html(phone.chatNames);
  1081.             if (!$(this).hasClass("chat")) {                                              // if the button does not have the chat class then the chat view is closed
  1082. d
  1083.                 $(this).addClass("chat");                                           // add chat class
  1084. s
  1085.                 $(".b-chat").addClass("open");                    // open the chat window and add button of incoming call
  1086. l
  1087.                 $(".b-chat").attr("id", "active");
  1088.                 $(".b-chat_tab.open .b-chat__window").mCustomScrollbar();// activate styles of scroll-bar of the open chat window
  1089. w
  1090.                 phone.chatScrollDown();
  1091.             } else {                                                                            // if the chat is open then close it and remove the chat class from button
  1092. n
  1093.                 $(this).removeClass("chat");
  1094.                 $(".b-chat").removeAttr("id");
  1095.                 $(".b-chat").removeClass("open");
  1096.             }
  1097.         }
  1098.     });
  1099.  
  1100.     $(".b-alert__close").live("click", function () {
  1101.         $(".b-alert__error").removeAttr("id");
  1102.         $(".b-alert__error").removeClass("open");
  1103.     });
  1104.     $(".b-chat__close").live("click", function () // on close click (Ð¥) on the chat view
  1105. iew
  1106.         $(".b-nav__chat").removeClass("chat");
  1107.         $(".b-chat").removeAttr("id");
  1108.         $(".b-chat").removeClass("open");
  1109.     });
  1110.  
  1111.     $(".b-chat__nav__tab .tab_close").live("click", function (// on close click (X) on the chat tab
  1112. tab
  1113.         var elem = $(this).parent();
  1114.         if (elem.attr("id") == ") {                                                       // do not close the tab if the tab belongs to a new chat window
  1115.            $(" $("#" + phone.elem_prev + ", .b-chat_tab." + phone.elem_prev).addClass("open// do previous tab active
  1116. ive
  1117.             elem.removeClass("open");                                   // hide this tab with its content
  1118. ent
  1119.             $(".b-chat_tab." + elem.attr("id")).removeClass("open");
  1120.             phone.chatScrollDown();
  1121.         } else {
  1122.             if (elem.hasClass("open")) {        // if the tab is open
  1123. pen
  1124.                 if (elem.index() > 0) {                           // and if the element is not first element
  1125. ent
  1126.                     elem.prev().addClass("open");     // do active previous tab and its content
  1127. ent
  1128.                     $("." + elem.prev().attr("id")).addClass("open");
  1129.                 } else {                                          // if the tab is first then do active next tab
  1130. tab
  1131.                     elem.next().addClass("open");
  1132.                     $("." + elem.next().attr("id")).addClass("open");
  1133.                 }
  1134.             }
  1135.             elem.remove();                                        // close the tab and its content
  1136. ent
  1137.             $(".b-chat_tab." + elem.attr("id")).remove();
  1138.         }
  1139.     });
  1140.     $(".b-chat").resizabl// change chat window dimensions
  1141. ons
  1142.         minHeight: 395,
  1143.         minWidth: 500
  1144.     });
  1145.  
  1146.     $(".b-chat__text input").live("click", function (// on click "Send" in the chat
  1147. hat
  1148.         var body = $(this).prev().val();
  1149.         var message = new Message();
  1150.         message.to = $(".b-chat__nav__tab.open span.tab_text").html();
  1151.         message.body = body;
  1152.         phone.sendMessage(message);
  1153.  
  1154.         $('<div id="message_' + message.id + '" class="b-chat__message my_message"><div class="b-chat__message__head"><span class="b-chat__message__time">' + new Date().toLocaleString() + '</span><span class="b-chat__message__author">' + $("input[id='sipLogin']").val() + '</span></div><div class="b-chat__message__text">' + body.replace(g, "<, "<br />") + '</div></div>').appendTo($(".mCSB_container", $(this).parent().prev()));
  1155.         phone.chatScrollDown();
  1156.         $(this).prev().val("// clear the textarea
  1157. rea
  1158.     });
  1159.  
  1160.     $(".b-chat__nav__tab .tab_text").live("click", function () {        // on tab click
  1161. ick
  1162.         var elem = $(this).parent();
  1163.         phone.chatSelectTab(elem);
  1164.     });
  1165.  
  1166.     $("#new__chat").keyup(function () // enter username from keyboard
  1167. ard
  1168.         $(".b-chat__new__list").addClass("open");
  1169.         $(".b-chat__new__nav").addClass("open// do active buttons under the list
  1170. ist
  1171.     });
  1172.     $(".b-chat__new__list p").live("click", function () // on click by username select its name
  1173. ame
  1174.         $(".b-chat__new__list p.active").removeClass("active");
  1175.         $(this).addClass("active");
  1176.         $("#new__chat").val($(this).html());
  1177.     });
  1178.     $(".b-chat__new__cancel").live("click", function ()// on click "Cancel" while search of callee name
  1179. ame
  1180.         $(".b-chat__new__list p.active").removeClass("active// remove active class from the selected username (if the username exists)
  1181. ts)
  1182.         $("#new__chat").val("");                      // clear the search field
  1183. eld
  1184.         $(".b-chat__new__nav, .b-chat__new__list, .b-chat__nav__tab#new, .b-chat_tab.new").removeClass("open// hide all(list, buttons, the tab)
  1185. ab)
  1186.         $("#" + phone.elem_prev + ", .b-chat_tab." + phone.elem_prev).addClass("open// do active the tab previously saved
  1187. ved
  1188.         phone.chatScrollDown();
  1189.     });
  1190.     $(".b-chat__new__ok").live("click", function () {// selected username for the new chat tab
  1191. tab
  1192.         var chatUsername = $("#new__chat").val();
  1193.         phone.chatCreateTab(chatUsername);
  1194.     });
  1195.     $(".b-video, .b-login, .b-chat, .b-alert__error").mousedown(function (// if we pressed on a popup block then the block is bringing to forward
  1196. ard
  1197.         $("#active").removeAttr("id");
  1198.         $(this).attr("id", "active");
  1199.     });
  1200.  
  1201.     $(".b-nav__cancel_call, .close, .b-nav__hangup").live("click", function (// return to initial view
  1202. iew
  1203.         phone.cancel();
  1204.     });

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste
'); $(".b-chat_tab.open .b-chat__window").mCustomScrollbar({ // init scroll-bar if we load a history scrollInertia: 50, scrollButtons: { enable: false } }); this.chatScrollDown(); }; Phone.prototype.chatScrollDown = function () { $(".b-chat_tab.open .b-chat__window .mCSB_container").css("top", $(".b-chat_tab.open .b-chat__window .mCSB_container").height() - $(".b-chat_tab.open .b-chat__window .mCSB_container").parent().height() + 20 + "px"); }; /* ------------- Additional interface functions --------- */ Phone.prototype.isCurrentCall = function (call) { return this.currentCall != null && this.currentCall.callId == call.callId; }; Phone.prototype.isRingSoundAllowed = function () { try { if (ConfigurationLoader.getInstance().suppressRingOnActiveAudioStream) { trace("Phone - isRingSoundAllowed false"); return false; } } catch (error) { } trace("Phone - isRingSoundAllowed true"); return true; }; Phone.prototype.applyCalleeLetterCase = function (callee) { if (callee) { if ("uppercase" == ConfigurationLoader.getInstance().calleeLetterCase) { return callee.toUpperCase(); } if ("lowercase" == ConfigurationLoader.getInstance().calleeLetterCase) { return callee.toLowerCase(); } } return callee; }; $(document).ready(function () { var phone = new Phone(); phone.chatNames = unescape(Flashphoner.getInstance().getCookie("chatNames")); ConfigurationLoader.getInstance(function (configuration) { trace("Configuration loaded"); configuration.localMediaElementId = 'localMediaElement'; configuration.remoteMediaElementId = 'remoteMediaElement'; configuration.elementIdForSWF = "flashVideoDiv"; configuration.pathToSWF = "../../dependencies/flash/MediaManager.swf"; Flashphoner.getInstance().init(configuration); phone.init(); }); $(".b-send_video").live("click", function () { if ($(this).text() == "Send video") { phone.changeVideoState(phone.currentCall, true); $(this).text("Stop video"); } else { phone.changeVideoState(phone.currentCall, false); $(this).text("Send video"); } }); // open/close authentication view $(".b-display__header__login, .b-login__cancel").live("click", function () { if (phone.connectionStatus == ConnectionStatus.Established || phone.connectionStatus == ConnectionStatus.Registered) { phone.disconnect(); } else { $('#sipLogin').val(Flashphoner.getInstance().getCookie('sipLogin')); $('#sipPassword').val(Flashphoner.getInstance().getCookie('sipPassword')); $('#sipAuthenticationName').val(Flashphoner.getInstance().getCookie('sipAuthenticationName')); $('#sipDomain').val(Flashphoner.getInstance().getCookie('sipDomain')); $('#sipOutboundProxy').val(Flashphoner.getInstance().getCookie('sipOutboundProxy')); $('#sipPort').val(Flashphoner.getInstance().getCookie('sipPort')); $(".b-login").toggleClass("open"); $("#active").removeAttr("id"); $(".b-login").hasClass("open") ? $(".b-login").attr("id", "active") : $(".b-login").removeAttr("id"); } }); // authentication $(".b-login input[type='button']").live("click", function () { $(".b-display__header__login").html("Connecting"); $(".b-login").removeClass("open").removeAttr("id"); phone.connect(); }); // open/close microphone gain control $(".b-display__header__volume").live("click", function () { if (phone.currentCall) { $(".b-volume").hasClass("open") ? $(".b-volume").removeClass("open") : $(".b-volume").addClass("open"); } }); // open/close loudspeaker control $("#volume").slider({ value: 60, orientation: "horizontal", range: "min", animate: true, slide: function (event, ui) { $(".volume-percent").html(ui.value + "%"); Flashphoner.getInstance().setVolume(phone.currentCall, ui.value); } }); // digital value of loudspeaker volume $(".volume-percent").html($("#volume").slider("value") + "%"); // digital value of microphone gain $(".b-display__header__mike").live("click", function () { $(".b-mike").hasClass("open") ? $(".b-mike").removeClass("open") : $(".b-mike").addClass("open"); }); $("#mike").slider({ value: 60, orientation: "horizontal", range: "min", animate: true, slide: function (event, ui) { $(".mike-percent").html(ui.value + "%"); } }); $(".mike-percent").html($("#volume").slider("value") + "%"); // on click "Video" icon in the top menu $(".b-display__header__video").live("click", function () { phone.openVideoView(); }); // close video upon (Ð¥) click $(".b-video__close").live("click", function (e) { $(".b-video").removeClass("open").removeAttr("id"); $(".b-video").removeAttr('style'); if ($(".b-video").hasClass("flash_access")) { phone.cancel(); } }); // change video view dimensions //$(".b-video, .b-login, .b-alert__error, .b-chat, .b-transfer").draggable(); // set video view draggable $(".b-video").resizable({ minHeight: 240, minWidth: 320, aspectRatio: 4 / 3 }); // enter phone number $(".b-display__bottom__number>span").live("click", function () { // on click by 'Enter your number here' if (phone.connectionStatus == ConnectionStatus.Established || phone.connectionStatus == ConnectionStatus.Registered) { $(this).addClass("close"); $(".b-numbers__clear").addClass("open"); $(".b-numbers").addClass("write").focus(); } }); $(document).keyup(function (event) { // listening keyboard input if (($(".b-numbers").is(":focus")) && (event.keyCode == 8)) { // if the focus on the number field and Backspace is pressed num = $(".b-numbers").val().length; // check number of symbols in the field which remain after the symbol removing if (num == 0) { // if the latest digit was removed then return to initial position $(".b-numbers__clear").removeClass("open"); $(".b-numbers").removeClass("write"); $(".b-display__bottom__number>span").removeClass("close"); } } }); $(".b-num td").live("click", function () { if (phone.connectionStatus == ConnectionStatus.Established || phone.connectionStatus == ConnectionStatus.Registered) { if (!$(".b-numbers").hasClass("write")) { // if the symbols are entered then remove the text block $(".b-display__bottom__number>span").addClass("close"); $(".b-numbers").addClass("write").next().addClass("open"); } if (phone.currentCall && (CallStatus.ESTABLISHED == phone.currentCall.status || CallStatus.HOLD == phone.currentCall.status)) { phone.sendDTMF(phone.currentCall.callId, $(this).text()); } else { if ($(".b-transfer").hasClass("open")) { $("#transfer").val($("#transfer").val() + $(this).text()); } else if (!phone.currentCall) { $(".b-numbers").val($(".b-numbers").val() + $(this).text()); } } } }); // removing of symbols $(".b-numbers__clear").live("click", function () { $(".b-numbers").val($(".b-numbers").val().substring(0, $(".b-numbers").val().length - 1)); num = $(".b-numbers").val().length; if (num == 0) { // if the latest digit was removed then return to initial position $(this).removeClass("open"); $(".b-numbers").removeClass("write"); $(".b-display__bottom__number>span").removeClass("close"); } }); // do video and audio call $(".b-nav__voice, .b-nav__video").live("click", function () { if ($(".b-numbers").hasClass("write")) { // check if phone number was entered $("body").addClass("voice_call__out"); $(".call__out__dial").addClass("open").html($(".call__out__dial").html() + " " + $(".b-numbers").val()); // open outgoing call block and writ here callee number if ($(this).hasClass("b-nav__video")) { $("body").addClass("video") } // if it is a video call then add the body class (for alert view) var mediaProvider = phone.getMediaProvider(); if ($("body").hasClass("video")) { phone.call($(".b-numbers").val(), true, mediaProvider); } else { phone.call($(".b-numbers").val(), false, mediaProvider); } } }); // answer the incoming call $(".b-nav__answer, .b-nav__answer_video").live("click", function () { if ($(this).hasClass("b-nav__answer_video")) { // if it is a video call then open view with video $("body").addClass("video"); } if (phone.currentCall) { phone.answer(phone.currentCall, $(this).hasClass("b-nav__answer_video")); } }); $(".voice_call__stop").live("click", function () { // if the call is on hold if (phone.currentCall) { phone.hold(phone.currentCall); $(".voice_call__transfer").addClass("close"); $(this).removeClass("open"); // hide the hold button $(".voice_call__play").addClass("open"); // do visible button of returning to the call and hold view } }); $(".voice_call__play").live("click", function () { // return to talk if (phone.currentCall) { phone.unhold(phone.currentCall); $(".voice_call__transfer").removeClass("close"); $(this).removeClass("open"); // hide unhold button $(".voice_call__stop").addClass("open"); // do visible hold button } }); $(".voice_call__transfer").live("click", function () { // if the transfer button is pressed if (phone.currentCall) { phone.holdForTransfer(phone.currentCall); $(".voice_call__transfer").addClass("close"); // hide transfer button $(".b-transfer").addClass("open"); // open transfer view and hold view $(".b-transfer").attr("id", "active"); $("#transfer").focus(); // set focus on the phone number field } }); $(".b-transfer__cancel").live("click", function () { if (phone.currentCall) { phone.unhold(phone.currentCall); $(".voice_call__play").removeClass("open"); // hide unhold button $(".voice_call__stop").addClass("open"); // do visible hold button } $(".voice_call__transfer").removeClass("close"); $(".b-transfer").removeClass("open").removeAttr("id"); }); $(".b-transfer__ok").live("click", function () { if (phone.currentCall) { phone.transfer(phone.currentCall.callId, $("#transfer").val()); } $(".voice_call__transfer").removeClass("close"); $(".b-transfer").removeClass("open").removeAttr("id"); }); $(".b-nav__chat").live("click", function () { // on "Chat" button click if (phone.connectionStatus == ConnectionStatus.Established || phone.connectionStatus == ConnectionStatus.Registered) { $('.b-chat__new__list .mCSB_container').html(phone.chatNames); if (!$(this).hasClass("chat")) { // if the button does not have the chat class then the chat view is closed $(this).addClass("chat"); // add chat class $(".b-chat").addClass("open"); // open the chat window and add button of incoming call $(".b-chat").attr("id", "active"); $(".b-chat_tab.open .b-chat__window").mCustomScrollbar(); // activate styles of scroll-bar of the open chat window phone.chatScrollDown(); } else { // if the chat is open then close it and remove the chat class from button $(this).removeClass("chat"); $(".b-chat").removeAttr("id"); $(".b-chat").removeClass("open"); } } }); $(".b-alert__close").live("click", function () { $(".b-alert__error").removeAttr("id"); $(".b-alert__error").removeClass("open"); }); $(".b-chat__close").live("click", function () { // on close click (Ð¥) on the chat view $(".b-nav__chat").removeClass("chat"); $(".b-chat").removeAttr("id"); $(".b-chat").removeClass("open"); }); $(".b-chat__nav__tab .tab_close").live("click", function () { // on close click (X) on the chat tab var elem = $(this).parent(); if (elem.attr("id") == "new") { // do not close the tab if the tab belongs to a new chat window $("#" + phone.elem_prev + ", .b-chat_tab." + phone.elem_prev).addClass("open"); // do previous tab active elem.removeClass("open"); // hide this tab with its content $(".b-chat_tab." + elem.attr("id")).removeClass("open"); phone.chatScrollDown(); } else { if (elem.hasClass("open")) { // if the tab is open if (elem.index() > 0) { // and if the element is not first element elem.prev().addClass("open"); // do active previous tab and its content $("." + elem.prev().attr("id")).addClass("open"); } else { // if the tab is first then do active next tab elem.next().addClass("open"); $("." + elem.next().attr("id")).addClass("open"); } } elem.remove(); // close the tab and its content $(".b-chat_tab." + elem.attr("id")).remove(); } }); $(".b-chat").resizable({ // change chat window dimensions minHeight: 395, minWidth: 500 }); $(".b-chat__text input").live("click", function () { // on click "Send" in the chat var body = $(this).prev().val(); var message = new Message(); message.to = $(".b-chat__nav__tab.open span.tab_text").html(); message.body = body; phone.sendMessage(message); $('
' + new Date().toLocaleString() + '' + $("input[id='sipLogin']").val() + '
' + body.replace(/\n/g, "
") + '
').appendTo($(".mCSB_container", $(this).parent().prev())); phone.chatScrollDown(); $(this).prev().val(""); // clear the textarea }); $(".b-chat__nav__tab .tab_text").live("click", function () { // on tab click var elem = $(this).parent(); phone.chatSelectTab(elem); }); $("#new__chat").keyup(function () { // enter username from keyboard $(".b-chat__new__list").addClass("open"); $(".b-chat__new__nav").addClass("open"); // do active buttons under the list }); $(".b-chat__new__list p").live("click", function () { // on click by username select its name $(".b-chat__new__list p.active").removeClass("active"); $(this).addClass("active"); $("#new__chat").val($(this).html()); }); $(".b-chat__new__cancel").live("click", function () { // on click "Cancel" while search of callee name $(".b-chat__new__list p.active").removeClass("active"); // remove active class from the selected username (if the username exists) $("#new__chat").val(""); // clear the search field $(".b-chat__new__nav, .b-chat__new__list, .b-chat__nav__tab#new, .b-chat_tab.new").removeClass("open"); // hide all(list, buttons, the tab) $("#" + phone.elem_prev + ", .b-chat_tab." + phone.elem_prev).addClass("open"); // do active the tab previously saved phone.chatScrollDown(); }); $(".b-chat__new__ok").live("click", function () { // selected username for the new chat tab var chatUsername = $("#new__chat").val(); phone.chatCreateTab(chatUsername); }); $(".b-video, .b-login, .b-chat, .b-alert__error").mousedown(function () { // if we pressed on a popup block then the block is bringing to forward $("#active").removeAttr("id"); $(this).attr("id", "active"); }); $(".b-nav__cancel_call, .close, .b-nav__hangup").live("click", function () { // return to initial view phone.cancel(); }); });

Login or Register to edit or fork this paste. It's free.