Advertisement
Guest User

Untitled

a guest
Jul 5th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function () {
  2.  
  3.     // All these three events are to stop any thing to be dropped on extention
  4.     $("body").on("dragover", function (event) {
  5.         event.preventDefault();
  6.         event.stopPropagation();
  7.  
  8.     });
  9.  
  10.     $("body").on("dragleave", function (event) {
  11.         event.preventDefault();
  12.         event.stopPropagation();
  13.     });
  14.  
  15.  
  16.     $("body").on("drop", function (event) {
  17.         event.preventDefault();
  18.         event.stopPropagation();
  19.  
  20.     });
  21.     var isPresentor = false;
  22.     var joinReceived = false;
  23.     var peerId = "";
  24.     var pendingPresentId = "";
  25.     var shareStream = null;
  26.     var videoStream = null;
  27.     var shareFlowing = false;
  28.     var videoFlowing = false;
  29.     var shareVideoActive = false;
  30.     var shareVideo = null;
  31.     var pauseFlag = false;
  32.     var rtcInfo = {};
  33.     var peerConns = {};
  34.     var seltabid = null;
  35.     var displayUserWaiting = [];
  36.     var intervalidofvalidatenetwork = "";
  37.     var reconnectInterval = 1000 * 10;
  38.     var networkErrorCounter = 0;
  39.     var isPresenting = "";
  40.     var unReadMsgCounts = [];
  41.     var screenShareSource = "";
  42.     var mirrorRequestIpAdd = "";
  43.     var mediaConstraints = {
  44.         'mandatory': {
  45.             'OfferToReceiveAudio': true,
  46.             'OfferToReceiveVideo': true
  47.         }
  48.     };
  49.     $(".version").text(myApp.version);
  50.     setInterval(function () {
  51.         $.fn.hideDisplayAllowRequest();
  52.     }, 5000);
  53.     //connect();
  54.     createstorage();
  55.     document.onkeydown = function (e) {
  56.         if (window.event.keyCode == 123 || e.button == 2)
  57.             return false;
  58.     }
  59.  
  60.     var autoUsername = "";
  61.     if (myApp.loginMode == "" && myApp.chromeIpAddressKeyValue.length == 0) {
  62.         $("#loginBtnTd").show();
  63.         $("#loginBtnTd").css({"padding-top": "90px"});
  64.         $("#myfooter").show();
  65.         $("#myfooter").css({"padding-top": "30px"});
  66.     }
  67.  
  68.     chrome.identity.getProfileUserInfo(function (autoUsername) {
  69.         /* Use userInfo.email, or better (for privacy) userInfo.id
  70.          They will be empty if user is not signed in in Chrome */
  71.         var userlogin = autoUsername.email;
  72.         var userinfo = userlogin.split('@');
  73.         //$("#username").val(userinfo[0]);
  74.     });
  75.     // chrome.tabs.getSelected(null,function(tab){
  76.     //   captureTab();
  77.     //})
  78.  
  79.  
  80.     function networkvalidate()
  81.     {
  82.         var xmlHttp = new XMLHttpRequest();
  83.         var url = "http://" + myApp.domain + "/validatenetwork.php";
  84.         xmlHttp.onreadystatechange = function () {
  85.             if (xmlHttp.readyState == 4) {
  86.                 if (xmlHttp.status >= 200) {
  87.                     var myArr = xmlHttp.responseText;
  88.                     //////////console.log("validatenetwork my arr -", myArr);
  89.                 } else {
  90.                     ////////console.log("error while calling validatenetwork.php");
  91.                     clearInterval(intervalidofvalidatenetwork);
  92.                     //showErrorState(1);
  93.                     setupUILogin(4);
  94.                 }
  95.             }
  96.         }
  97.         xmlHttp.open("GET", url, true);
  98.         xmlHttp.send();
  99.     }
  100.  
  101.     function connect() {
  102.  
  103.         ////////console.log("Websocket Connected");
  104.         $.fn.login();
  105.     }
  106.  
  107.     function myNotifications(strMessage) {
  108.         var opt = {
  109.             type: "basic",
  110.             title: "",
  111.             message: strMessage,
  112.             iconUrl: "icons/vianotification.png"
  113.         };
  114.         chrome.notifications.create("", opt, function (id) {
  115.             if (chrome.runtime.lastError) {
  116.                 //console.error(chrome.runtime.lastError.message);
  117.             }
  118.         });
  119.     }
  120.  
  121.  
  122.     function onWebSocketMessage(evt) {
  123.         var response = "";
  124.         var data = evt.data;
  125.         if ($.fn.isJson(data)) {
  126.             response = JSON.parse(evt.data);
  127.             console.log(response);
  128.             if (response.request == "getRegisterDetailsAndRc") {
  129.                 //Gateway Version information
  130.                 if (response.version != undefined) {
  131.                     myApp.gatewayVersion = response.version;
  132.                     myApp.xmppExeReqKey = response.xmppExeReqKey;
  133.                     myApp.clientReqKey = response.clientReqKey;
  134.                     var dndChatPwdModInfo = response.dndChatPwdMod.split("#");
  135.                     myApp.modToggleDnd = dndChatPwdModInfo[0];
  136.                     myApp.modToggleChat = dndChatPwdModInfo[1];
  137.                     myApp.modPwdReq = dndChatPwdModInfo[2];
  138.                     myApp.currentLoginMode = response.moderation;
  139.                     //console.log(myApp.loginMode + "==" + response.moderation);
  140.                     myApp.roomCode = response.roomCode;
  141.                     if (response.isValidLogin == 1) {
  142.                         if (response.moderation != 0 || response.moderation == "") {
  143.                             if (myApp.loginMode == response.moderation) {
  144.                                 if (response.roomCode != "" && response.roomCode == 0) {
  145.                                     //myApp.roomCode = response.roomCode;
  146.                                     $("#login").html("Login");
  147.                                     $(".rc").show();
  148.                                     $("#roomCode").focus();
  149.                                     myApp.userValidityChk = "yes";
  150.                                     if (response.moderation == "" || response.moderation == 3) {
  151.                                         $("#loginBtnTd").css({"padding-top": "60px"});
  152.                                         $("#myfooter").css({"padding-top": "25px"});
  153.                                     } else if (response.moderation == 4 || response.moderation == 9) {
  154.                                         $("#db_name,#db_pass").prop('disabled', true);
  155.                                         $("#loginBtnTd").css({"padding": "20px"});
  156.                                         $("#myfooter").css({"padding-top": "5px"});
  157.                                     }
  158.                                 } else {
  159.                                     loginXmppUser.login();
  160.                                 }
  161.                             } else {
  162.                                 myApp.userValidityChk = "yes";
  163.                                 if (response.moderation == "" || response.moderation == 3) {
  164.                                     $("#db_pass").val("");
  165.                                     if (response.roomCode != "" && response.roomCode == 0) {
  166.                                         $("#login").html("Login");
  167.                                         //myApp.roomCode = response.roomCode;
  168.                                         $(".basic").show();
  169.                                         $(".rc").show();
  170.                                         $("#roomCode").focus();
  171.                                         $("#loginBtnTd").css({"padding-top": "60px"});
  172.                                         $("#myfooter").css({"padding-top": "25px"});
  173.                                     } else {
  174.                                         /*$(".db").hide();
  175.                                          $(".basic").show();
  176.                                          $("#login").html("Login");
  177.                                          $("#loginBtnTd").css({"padding-top": "90px"});
  178.                                          $("#myfooter").css({"padding-top": "30px"});*/
  179.                                         loginXmppUser.login();
  180.                                         //$("#loginBtnTd").css({"padding": "60px 10px 20px 20px"});
  181.                                         //$("#myfooter").css({"padding-top": "60px"});
  182.                                     }
  183.                                     //$(".basic").show();
  184.                                     $(".db").hide();
  185.                                 } else {
  186.                                     if (response.roomCode != "" && response.roomCode == 0) {
  187.                                         //myApp.roomCode = response.roomCode;
  188.                                         $(".rc").show();
  189.                                         $("#roomCode").focus();
  190.                                         $("#login").html("Login");
  191.                                         $("#loginBtnTd").css({"padding": "20px"});
  192.                                         $("#myfooter").css({"padding-top": "5px"});
  193.                                     } else {
  194.                                         loginXmppUser.login();
  195.                                     }
  196.                                 }
  197.                             }
  198.                         } else {
  199.                             myApp.userValidityChk = "yes";
  200.                             if (response.moderation == "0") {
  201.                                 $("#username").val("");
  202.                                 $("#db_name").focus();
  203.                                 if ($("#db_pass").val() != "") {
  204.                                     $("#db_name,#db_pass").prop('disabled', false);
  205.                                     $("#db_pass").addClass("text_error");
  206.                                     $("#db_pass").focus();
  207.                                 }
  208.                                 $(".db").show();
  209.                                 $(".basic").hide();
  210.                                 $("#login").html("Login");
  211.                                 $("#loginBtnTd").css({"padding-top": "60px"});
  212.                                 $("#myfooter").css({"padding-top": "10px"});
  213.                             }
  214.                         }
  215.  
  216.                     } else if (response.isValidLogin == 0) {
  217.                         if (response.moderation == "0") {
  218.                             $("#username").val("");
  219.                             $("#db_name").focus();
  220.                             //if ($(".db").is(":visible") == true) {
  221.                             if ($("#db_pass").val() != "") {
  222.                                 $("#db_name,#db_pass").prop('disabled', false);
  223.                                 $("#db_pass").addClass("text_error");
  224.                                 $("#db_pass").focus();
  225.                             }
  226.                             //}
  227.                             $(".db").show();
  228.                             $(".basic").hide();
  229.                             $("#loginBtnTd").css({"padding-top": "70px"});
  230.                             $("#myfooter").css({"padding-top": "10px"});
  231.                         } else if (response.moderation == "" || response.moderation == 3) {
  232.                             //if (response.moderation == 3) {
  233.                             myApp.userValidityChk = "yes";
  234.                             if (response.roomCode == 0 && response.roomCode != "") {
  235.                                 $(".rc").show();
  236.                                 $("#roomCode").focus();
  237.                             }
  238.                             $("#loginBtnTd").css({"padding-top": "60px"});
  239.                             $("#myfooter").css({"padding-top": "10px"});
  240.                             /*} else {
  241.                              myApp.userValidityChk = "yes";
  242.                              if (response.roomCode == 0) {
  243.                              $(".rc").show();
  244.                              $("#roomCode").focus();
  245.                              }
  246.                              $("#loginBtnTd").css({"padding-top": "60px"});
  247.                              $("#myfooter").css({"padding-top": "10px"});
  248.                              }*/
  249.                             $("#db_name,#db_pass").val("");
  250.                             $(".basic").show();
  251.                             $(".db").hide();
  252.                         } else if (response.moderation == 4 || response.moderation == 9) {
  253.                             myApp.userValidityChk = "yes";
  254.                             if (response.roomCode == 0) {
  255.                                 $(".rc").show();
  256.                                 $("#roomCode").focus();
  257.                             }
  258.                             $(".basic").hide();
  259.                             $(".db").show();
  260.                             $("#db_name,#db_pass").prop('disabled', true);
  261.                             $("#loginBtnTd").css({"padding-top": "30px"});
  262.                             $("#myfooter").css({"padding-top": "5px"});
  263.                         }
  264.                         $("#login").html("Login");
  265.                     } else if (response.isValidLogin == -2) {
  266.                         myApp.customNotification("Nick name already in use please try with another nick name.");
  267.                         $("#login").html("Login");
  268.                         $("#db_name,#db_pass,#username").prop('disabled', false);
  269.                     }
  270.                 } else {
  271.                     //this is the code for the version 2.1 or 0
  272.                     if (response.isValidLogin == 1 && (response.moderation != 0 || response.moderation == "")) {
  273.                         myApp.xmppExeReqKey = response.xmppExeReqKey;
  274.                         myApp.clientReqKey = response.clientReqKey;
  275.                         var dndChatPwdModInfo = response.dndChatPwdMod.split("#");
  276.                         myApp.modToggleDnd = dndChatPwdModInfo[0];
  277.                         myApp.modToggleChat = dndChatPwdModInfo[1];
  278.                         myApp.modPwdReq = dndChatPwdModInfo[2];
  279.                         myApp.currentLoginMode = response.moderation;
  280.                         myApp.roomCode = response.roomCode;
  281.                         //console.log(myApp.loginMode + "==" + response.moderation);
  282.                         if (myApp.loginMode == response.moderation) {
  283.                             if (response.roomCode != 0) {
  284.                                 myApp.roomCode = response.roomCode;
  285.                                 $("#login").html("Login");
  286.                                 $(".rc").show();
  287.                                 $("#roomCode").focus();
  288.                                 myApp.userValidityChk = "yes";
  289.                                 if (response.moderation == "" || response.moderation == 3) {
  290.                                     $("#loginBtnTd").css({"padding-top": "60px"});
  291.                                     $("#myfooter").css({"padding-top": "25px"});
  292.                                 } else if (response.moderation == 4 || response.moderation == 9) {
  293.                                     $("#loginBtnTd").css({"padding": "20px"});
  294.                                     $("#myfooter").css({"padding-top": "5px"});
  295.                                 }
  296.                             } else if (response.roomCode == 0) {
  297.                                 loginXmppUser.login();
  298.                             }
  299.                         } else {
  300.                             myApp.userValidityChk = "yes";
  301.                             if (response.moderation == "" || response.moderation == 3) {
  302.                                 $("#db_pass").val("");
  303.                                 if (response.roomCode != 0) {
  304.                                     $("#login").html("Login");
  305.                                     myApp.roomCode = response.roomCode;
  306.                                     $(".basic").show();
  307.                                     $(".rc").show();
  308.                                     $("#roomCode").focus();
  309.                                     $("#loginBtnTd").css({"padding-top": "60px"});
  310.                                     $("#myfooter").css({"padding-top": "25px"});
  311.                                 } else {
  312.                                     /*$(".db").hide();
  313.                                      $(".basic").show();
  314.                                      $("#login").html("Login");
  315.                                      $("#loginBtnTd").css({"padding-top": "90px"});
  316.                                      $("#myfooter").css({"padding-top": "30px"});*/
  317.                                     loginXmppUser.login();
  318.                                     //$("#loginBtnTd").css({"padding": "60px 10px 20px 20px"});
  319.                                     //$("#myfooter").css({"padding-top": "60px"});
  320.                                 }
  321.                                 //$(".basic").show();
  322.                                 $(".db").hide();
  323.                             } else {
  324.                                 if (response.roomCode != 0) {
  325.                                     myApp.roomCode = response.roomCode;
  326.                                     $(".rc").show();
  327.                                     $("#roomCode").focus();
  328.                                     $("#login").html("Login");
  329.                                     $("#loginBtnTd").css({"padding": "20px"});
  330.                                     $("#myfooter").css({"padding-top": "5px"});
  331.                                 } else {
  332.                                     loginXmppUser.login();
  333.                                 }
  334.                             }
  335.                         }
  336.                     } else if (response.moderation == 0 && response.isValidLogin == 1) {
  337.                         //console.log("Come");
  338.                         $("#db_pass").prop('disabled', false);
  339.                         $("#username").val("");
  340.                         $(".db").show();
  341.                         $(".basic").hide();
  342.                         $("#db_pass").addClass("text_error");
  343.                         $("#loginBtnTd").css({"padding-top": "60px"});
  344.                         $("#myfooter").css({"padding-top": "10px"});
  345.                         $("#login").html("Login");
  346.                     } else if (response.isValidLogin == 0) {
  347.                         $("#db_pass").val("");
  348.                         $(".basic").show();
  349.                         $(".db").hide();
  350.                         $("#login").html("Login");
  351.                         $("#loginBtnTd").css({"padding-top": "100px"});
  352.                         $("#myfooter").css({"padding-top": "20px"});
  353.                     } else if (response.isValidLogin == -2) {
  354.                         myApp.customNotification("Nick name already in use please try with another nick name.");
  355.                         $("#login").html("Login");
  356.                     }
  357.                 }
  358.  
  359.             } else if (response.request == "cancelDownload") {
  360.                 myApp.dataChannelObj.cancelDownloadViewFiles();
  361.             } else if (response.request == "setFeatureAllow") {
  362.                 var gatewayFeature = response.message;
  363.                 myApp.featureListGateway = gatewayFeature.split("#");
  364.                 if (myApp.featureListGateway.indexOf("B2") < 0) {
  365.                     myApp.featureListChat = "no";
  366.                     $("#allparticipants").hide();
  367.                     $(".chat_start,.chat_selected").hide();
  368.                     $("#file_share_heading").css("margin-left", "60px");
  369.                     $("label[for =file-upload]").css("padding-left", "50px");
  370.                     $("#admin_fileshare").css("padding-left", "50px");
  371.                 }
  372.                 if (myApp.featureListGateway.indexOf("B3") < 0) {
  373.                     $("#cloud_transfer").hide();
  374.                 }
  375.                 if (myApp.featureListGateway.indexOf("B5") < 0) {
  376.                     $("#collaboration").hide();
  377.                 }
  378.                 if (myApp.featureListGateway.indexOf("B6") < 0) {
  379.                     myApp.FeatureListFileTransfer = "no";
  380.                     $("#file_share_heading,#file_transfer_td,.one_share").hide();
  381.                 }
  382.                 if (myApp.featureListGateway.indexOf("B20") < 0) {
  383.                     $("#thirdParyApps").hide();
  384.                 }
  385.                 if (myApp.featureListGateway.indexOf("B25") < 0) {
  386.                     $("#epoll").hide();
  387.                 }
  388.             } else if (response.request == "setViewFIles") {
  389.                 $("#view_file,.file_action_button,.view_file_bar").show();
  390.                 $("#features_disp,.file_transfer_options").hide();
  391.                 parser = new DOMParser();
  392.                 xmlNodes = parser.parseFromString(response.data, "text/xml");
  393.                 var files = xmlNodes.getElementsByTagName("file");
  394.                 $("div.view_files").remove();
  395.                 $("div.view_files_hr").remove();
  396.                 for (i = 0; i < files.length; i++) {
  397.                     var nodes = files[i].childNodes;
  398.                     var fileName = nodes[0].innerHTML;
  399.                     if (fileName.length > 30) {
  400.                         fileName = fileName.slice(0, 30) + "..";
  401.                     }
  402.                     var len = nodes[2].innerHTML;
  403.                     //console.log(len);
  404.                     var fileSize = "&nbsp";
  405.                     if (len > 0) {
  406.                         var kb = len / 1024;
  407.                         fileSize = kb.toFixed(2) + "KB";
  408.                         if (kb >= 1) {
  409.                             var mb = kb / 1024;
  410.                             fileSize = mb.toFixed(2) + "MB";
  411.                             if (mb >= 1) {
  412.                                 var gb = mb / 1024;
  413.                                 if (gb >= 1) {
  414.                                     fileSize = gb.toFixed(2) + "GB";
  415.                                 }
  416.                             }
  417.                         }
  418.                     }
  419.  
  420.  
  421.                     var htmlData = '<div class="view_files">';
  422.                     htmlData += '<div style="float: left; width: 38%; padding-left: 10px;">' + fileName + '</div>'
  423.                     htmlData += '<div style="float: left; width: 15%; text-align: center;">' + nodes[1].innerHTML + '</div>';
  424.                     htmlData += '<div style="float: left; width: 15%; text-align: center;">' + fileSize + '</div>';
  425.                     htmlData += '<div style="float: left; width: 15%; text-align: center;">\n\
  426.                                    <img data-filename = "' + nodes[0].innerHTML + '" data-filepath ="' + nodes[4].innerHTML + '" class="view_file_open" src="icons/fopen_17x11.png" style="vertical-align:middle">\n\
  427.                                </div>';
  428.                     //htmlData += '<div style="float: left; width: 15%; text-align: center;"><input data-filename = "' + nodes[0].innerHTML + '" data-filepath ="' + nodes[4].innerHTML + '" type="checkbox" class="file_check"></div>';
  429.  
  430.                     if (nodes[1].innerHTML != "Folder") {
  431.                         htmlData += '<div style="float: left; width: 15%; text-align: center;">\n\
  432.                                    <img data-filesize="' + nodes[2].innerHTML + '" data-filename = "' + nodes[0].innerHTML + '" data-filepath ="' + nodes[4].innerHTML + '" class="view_file_download" src="icons/download.png" style="vertical-align:middle">\n\
  433.                                </div>';
  434.                     }
  435.                     htmlData += '</div>';
  436.                     htmlData += '<div class="view_files_hr" style="padding-left: 10px; padding-right: 10px;padding-top: 20px;padding-bottom: 5px;"><hr></div>';
  437.                     //console.log(nodes[1].innerHTML);
  438.                     $("#view_files").append(htmlData);
  439.                 }
  440.                 if (myApp.osType == 1 || myApp.osType == 3) {
  441.                     $("#open_cloud_tab,.view_file_open").hide();
  442.                 }
  443.                 $("#view_file_info,#view_files").show();
  444.             } else if (response.request == "fileTransferFormat") {
  445.                 if (response.message.charAt(response.message.length - 1) == '#') {
  446.                     var format = response.message.substr(0, response.message.length - 1);
  447.                     myApp.fileTransferFormatArray = format.split("#");
  448.                 } else {
  449.                     myApp.fileTransferFormatArray = response.message.split("#");
  450.                 }
  451.                 if (myApp.fileTransferFormatArray[0] != "All") {
  452.                     myApp.fileTransferFormatStr = myApp.fileTransferFormatArray.join(",.");
  453.                     myApp.fileTransferFormatStr = "." + myApp.fileTransferFormatStr;
  454.                     setTimeout(function () {
  455.                         $("#file-upload").attr("accept", myApp.fileTransferFormatStr);
  456.                         $("#file_open_via").attr("accept", myApp.fileTransferFormatStr);
  457.                     }, 1000);
  458.                 }
  459.             } else if (response.request == "fileTransfer") {
  460.                 if ($("#file_download_info").is(":visible") == true) {
  461.                     $('.file_receive_prompt').css({"height": "372px"});
  462.                 }
  463.                 var isDuplicateFile = "No";
  464.                 if (myApp.dataChannel.readyState != "open") {
  465.                     myApp.startDataChannel();
  466.                 }
  467.                 var totalFileSize = response.fileSize;
  468.                 var ftTotLength = 0
  469.                 if (totalFileSize > 1024000) {
  470.                     ftTotLength = (totalFileSize / (1024 * 1024)).toFixed(2) + " MB";
  471.                 } else {
  472.                     ftTotLength = (totalFileSize / 1024).toFixed(2) + " KB";
  473.                 }
  474.                 if (myApp.trasferFileNames.indexOf(response.fileName) == -1) {
  475.                     fileRecTimeStamp = myApp.getCurrentTimeStamp();
  476.                     var senderName = response.from.split("@")[0];
  477.                     if (!(response.fileName in myApp.fileTransferReceived)) {
  478.                         myApp.fileTransferReceived[response.fileName] = fileRecTimeStamp;
  479.                     } else {
  480.                         // this varibale help to know whether user want to download the orignal file or the one that come later with same name treat as duplicate
  481.                         isDuplicateFile = "Yes";
  482.                         // in case if any user send the same file from one to one and share to all user
  483.                         myApp.fileTransferReceived[response.fileName + '|duplicate'] = fileRecTimeStamp;
  484.                     }
  485.                     //console.log(myApp.fileTransferReceived);
  486.                     window.resizeTo(585, 650);
  487.                     myApp.trasferFileNames[response.fileName] = response.fileSize;
  488.                     var htmlData = '<div style="padding-left: 10px;">';
  489.                     htmlData += '<div style="padding-top: 10px; padding-bottom: 15px;">From: ' + senderName + '</div>';
  490.                     htmlData += '<div style="padding-top: 10px; padding-bottom: 10px;" class="transfer_file_class">File Name: ' + response.fileName + '</div>  ';
  491.                     htmlData += '<div style="color: #000000;" class="file_rec_basic">\n\
  492.                                    <div style="color: #000000;" class="file_rec_color" id="rec_file_' + fileRecTimeStamp + '">0%</div></div>';
  493.                     htmlData += '<div class="sc_operation" id="save_cancel_' + fileRecTimeStamp + '">';
  494.                     htmlData += '&nbsp;&nbsp; &nbsp;&nbsp;<input type="button" data-duplicate="' + isDuplicateFile + '" data-sendby="' + senderName + '" data-sendtype = "' + response.sendType + '" style="width:75px; height:25px; vertical-align: bottom;" class="logout save_transfer" value="save"/>';
  495.                     htmlData += '&nbsp;&nbsp; <input type="button" data-sendtype = "' + response.sendType + '" style="width:75px; height:25px; vertical-align: bottom;" class="logout cancel_transfer" value="cancel"/>';
  496.                     htmlData += '</div>';
  497.                     htmlData += '<div class="open_operation" id="open_' + fileRecTimeStamp + '" style="display: none;">';
  498.                     htmlData += '&nbsp;&nbsp; &nbsp;&nbsp;<input data-filename="' + response.fileName + '" type="button" style="width:75px; height:30px; vertical-align: bottom;" class="logout open_transfer" value="open"/>';
  499.                     htmlData += '</div>';
  500.                     htmlData += '<div style="padding-top: 10px; padding-bottom: 10px;" class="file_in_length">' + ftTotLength + '  <span style="padding-left:220px;" class="rec_file_length" id="rec_len_' + fileRecTimeStamp + '" ></span></div>';
  501.                     htmlData += '<div style="padding-right: 10px;"><hr></div>';
  502.                     htmlData += '</div>';
  503.                     $("#chat_user,#chat_window").hide()
  504.                     $("#features_disp,#coordinator_div,#mirror_users,#third_party_apps,#detail_grid,#choose_file,#touch_pad,.file_transfer_options,#view_file_info").hide();
  505.                     $(".file_receive_prompt").append(htmlData);
  506.                     $(".file_receive_prompt").show();
  507.                 }
  508.             } else if (response.request == "kickOff") {
  509.                 disconnect();
  510.                 setTimeout(function () {
  511.                     window.resizeTo(440, 480);
  512.                     window.location.reload();
  513.                 }, 1000);
  514.             } else if (response.request == "sessionReset") {
  515.                 disconnect();
  516.                 setTimeout(function () {
  517.                     myApp.customNotification("The session has ended or been reset.");
  518.                     window.resizeTo(440, 480);
  519.                     window.location.reload();
  520.                 }, 1000);
  521.             } else if (response.request == "presentStopTwo") {
  522.                 if (myApp.presentOnMonitorId == 2) {
  523.                     if (isPresentor == true) {
  524.                         stopPresenting();
  525.                     }
  526.                 }
  527.             } else if (response.request == "GDARequestState") {
  528.                 myApp.customNotification("You are already in requesting state.Please wait for your turn.");
  529.             } else if (response.request == "pcConfig") {
  530.                 ////console.log(response.pcConfig["iceServers"]);
  531.                 myApp.pcConfig = response.pcConfig["iceServers"];
  532.             } else if (response.request == "xmppClosed") {
  533.                 $.fn.reboot();
  534.             } else if (response.request == "unAuthorisedUser") {
  535.                 myNotifications("Authentication failed. VIA unit may not be registered with authentication server or chrome service may not be enabled.");
  536.                 return;
  537.             } else if (response.request == "roomNotExist") {
  538.                 myNotifications("Room not available to connect. VIA Gateway is not able to access the server, Please Contact Adminisrator.");
  539.                 //document.getElementById("strMsg-label").innerHTML="Room not available to connect.";
  540.                 roomnotavilable();
  541.             } else if (response.request == "presence") {
  542.                 var fromName = response.from.split("@");
  543.                 if (response.presence == "online" || response.presence == "offline") {
  544.                     if (response.presence == "online") {
  545.                         if ($("#" + fromName[0]).length == 0 && $("." + fromName[0] + "_class").length == 0) {
  546.                             if (response.from != response.to) {
  547.                                 $.fn.setPresence({"presence": response.presence, "from": response.from, "isPresenting": response.isPresenting, "isWaiting": response.isWaiting});
  548.                                 //$.fn.setPresence(response.presence + "~" + response.from + "~" + response.isPresenting + "~" + response.isWaiting);
  549.                             }
  550.                         }
  551.                         //if (myApp.currentLoginMode == 4) {
  552.                         if (response.isWaiting == "No") {
  553.                             if ($("." + fromName[0] + "_allow").length > 0) {
  554.                                 $("." + fromName[0] + "_allow").remove();
  555.                                 if ($(".allow_present_screen .allow").length == 0) {
  556.                                     $(".allow_present_screen").hide();
  557.                                 }
  558.                             }
  559.                         }
  560.  
  561.                         if (myApp.currentLoginMode != "") {
  562.                             if (response.presenceStatusMod == "Yes") {
  563.                                 if (fromName[0] != "viaadmin") {
  564.                                     if (myApp.currentLoginMode == 4) {
  565.                                         if (myApp.moderatorNames.indexOf(response.from) == -1) {
  566.                                             myApp.moderatorNames.push(response.from);
  567.                                         }
  568.                                         console.log(myApp.moderatorNames);
  569.                                     } else {
  570.                                         if (myApp.currentLoginMode == 3) {
  571.                                             myApp.moderatorName = response.from;
  572.                                             if (myApp.modToggleDnd == 1) {
  573.                                                 if (myApp.moderatorName == myApp.jid) {
  574.                                                     if (response.isPresenting == "Yes" && $("#btnfullscreen").is(":visible") == false) {
  575.                                                         $("#dnd_toggle").show();
  576.                                                     } else {
  577.                                                         $("#dnd_toggle").hide();
  578.                                                     }
  579.                                                     //$.fn.markPresenceForDndGateway("Yes");                                                  
  580.                                                 }
  581.  
  582.                                             }
  583.                                         }
  584.                                     }
  585.                                     if (response.from != response.to) {
  586.                                         // when any user become moderator
  587.                                         $(".mod").hide();
  588.                                         $("#moderator").html(fromName[0] + " is Moderator").prop('disabled', true);
  589.                                     } else if (response.from == response.to) {
  590.                                         if (myApp.osType != 3) {
  591.                                             if (myApp.modToggleChat == 1) {
  592.  
  593.                                                 $("#mod_chat_disp").show();
  594.                                                 //$("#moderation_chat").prop("checked", true);
  595.                                             }
  596.                                         }
  597.                                         myApp.socketId.send(JSON.stringify({
  598.                                             "request": "getMirroringList",
  599.                                             "jid": myApp.jid,
  600.                                             "type": "client",
  601.                                             "xmppExeReqKey": myApp.xmppExeReqKey
  602.                                         }));
  603.                                         $("#moderator").html("Leave Moderation");
  604.                                     }
  605.                                 }
  606.                             } else {
  607.                                 // console.log(response.from + "-" + response.to + "-" + myApp.moderatorName);
  608.                                 $("#mirror_band").hide();
  609.                                 $("#mirror_users").hide();
  610.                                 $("#mirror_listing").empty();
  611.                                 myApp.isMirrorUsers = "No";
  612.                                 if (response.from != response.to) {
  613.                                     if (myApp.moderatorName == response.from) {
  614.                                         $("#moderator").html("Become Moderator").prop('disabled', false);
  615.                                     }
  616.  
  617.                                 }
  618.                             }
  619.                         }
  620.                         /*if (response.isPresenting == "Yes" && $('#btnfullscreen').is(':hidden') == true) {
  621.                          if (myApp.modToggleDnd == 1) {
  622.                          if (myApp.currentLoginMode == 3) {
  623.                          if (myApp.moderatorName == myApp.jid && response.from == myApp.jid) {
  624.                          $("#dnd_toggle").show();
  625.                          //$.fn.markPresenceForDndGateway();
  626.                          }
  627.                          } else if (myApp.currentLoginMode == "") {
  628.                          if (response.from == myApp.jid) {
  629.                          $("#dnd_toggle").show();
  630.                          //$.fn.markPresenceForDndGateway();
  631.                          }
  632.                          } else if (myApp.currentLoginMode == 4) {
  633.                          if (myApp.moderatorNames.indexOf(myApp.jid) != -1 && response.from == myApp.jid) {
  634.                          $("#dnd_toggle").show();
  635.                          //$.fn.markPresenceForDndGateway();
  636.                          }
  637.                          }
  638.                          }
  639.                          }*/
  640.                         if (response.isWaiting == "No") {
  641.                             if (isPresentor == false) {
  642.                                 $("#presentmeimg").attr('src', 'icons/PRESENT-OFF.png');
  643.                             }
  644.                         }
  645.                         var displayUserId = fromName[0] + "_display";
  646.                         if (response.isWaiting == "Yes" && response.isPresenting == "No") {
  647.                             $("#" + displayUserId + ".display").children("img").attr('src', 'icons/display_waiting.png');
  648.                         } else if (response.isPresenting == "Yes" && response.isWaiting == "No") {
  649.                             $("#" + displayUserId + ".display").children("img").attr('src', 'icons/present_active.png');
  650.                         } else {
  651.                             $("#" + displayUserId + ".display").children("img").attr('src', 'icons/display.png');
  652.                         }
  653.                         if (response.from == response.to) {
  654.                             myApp.userIsPresenting = response.isPresenting;
  655.                         }
  656.                     } else if (response.presence == "offline") {
  657.                         if (response.from != response.to) {
  658.                             myApp.moderatorNames.splice(myApp.moderatorNames.indexOf(response.from), 1);
  659.                             $.fn.setPresence({"presence": response.presence, "from": response.from});
  660.                         }
  661.                     }
  662.                 }
  663.             } else if (response.request == "duplicate") {
  664.                 myApp.customNotification("Nick name already in use please try with another nick name.");
  665.                 $("#login").html("Login");
  666.             } else if (response.request == "inValidRc") {
  667.                 $("#login").html("Login");
  668.                 $("#roomCode").addClass("text_error");
  669.             } else if (response.request == "loginError") {
  670.                 if (response.errorType == "Database Mode") {
  671.                     $(".db").show();
  672.                     $("#username").val("");
  673.                     $(".basic").hide();
  674.                 } else if (response.errorType == "Basic Mode") {
  675.                     $(".basic").show();
  676.                     $(".db").hide();
  677.                 }
  678.             } else if (response.request == "loggedin") {
  679.                 if (response.valid == "success") {
  680.                     if (myApp.gatewayVersion == 0) {
  681.                         $(".participane_name").width("375px");
  682.                         $("#collaboration,#thirdParyApps,#file_transfer_td,#cloud_transfer,.feature_seperator,#file_share_heading").hide();
  683.                     }
  684.                     myApp.osType = response.osType;
  685.                     if (myApp.osType == 3) {
  686.                         $(".all_features,.all_exam,.chat_selected").hide();
  687.                         $(".all_participants").width("50%");
  688.                         $(".participane_name").width("400px");
  689.                     }
  690.                     if (myApp.osType == 1) {
  691.                         $(".open_on_via_td").hide();
  692.                         $("#thirdParyApps").hide();
  693.                     }
  694.                     chrome.runtime.sendMessage({
  695.                         "jid": myApp.jid,
  696.                         "xmppExeReqKey": myApp.xmppExeReqKey,
  697.                         "clientReqKey": myApp.clientReqKey,
  698.                         "socketId": myApp.socketId,
  699.                         "serverUrl": myApp.serverUrl,
  700.                         "serverPort": myApp.serverPort
  701.                     });
  702.                     if (response.moderation != "") {
  703.                         adddata();
  704.                         updateuserlastlogin(myApp.domain, '1', myApp.currentLoginMode);
  705.                         if (myApp.currentLoginMode == 3) {
  706.                             $("#moderator").show();
  707.                         } else {
  708.                             $("#moderator").hide();
  709.                         }
  710.                     }
  711.                     $.fn.screenAfterLogin();
  712.                 }
  713.             } else if (response.request == "basicModeratorPwd") {
  714.                 if (response.data == "success") {
  715.                     /*myApp.socketId.send(JSON.stringify({
  716.                      "request": "getMirroringList",
  717.                      "jid": myApp.jid,
  718.                      "type": "client",
  719.                      "xmppExeReqKey": myApp.xmppExeReqKey
  720.                      }));*/
  721.                     if (myApp.osType != 3) {
  722.                         if (myApp.modToggleChat == 1) {
  723.                             $("#mod_chat_disp").show();
  724.                         }
  725.                     }
  726.                     if (myApp.modToggleDnd == 1) {
  727.                         if (myApp.userIsPresenting == "Yes") {
  728.                             $("#dnd_toggle").show();
  729.                         }
  730.                     }
  731.                     $.fn.markPresenceForDndGateway("Yes");
  732.                     $("#moderator").html("Leave Moderation");
  733.                     $("#mod_pass").val("");
  734.                     $(".mod,#mod_error").hide();
  735.                 } else if (response.data == "fail") {
  736.                     $("#mod_error").show();
  737.                 }
  738.             } else if (response.request == "cordinates") {
  739.                 //console.log("cordinates" + response.xAxis + " " + response.yAxis);
  740.                 myApp.serverXaxis = response.xAxis;
  741.                 myApp.serverYaxis = response.yAxis;
  742.             } else if (response.request == "thirdPartyFromGateway") {
  743.                 var messageLen = response.data.length;
  744.                 if (response.totalBytes == messageLen) {
  745.                     //$("#third_party_apps").hide();
  746.                     myApp.setThirdPartyApps(response.data);
  747.                 }
  748.             } else if (response.request == "chat") {
  749.                 var fromUser = response.from.split("@");
  750.                 var onlyUser = myApp.jid.split("@");
  751.                 if (response.message == "Exam Coordinator" && fromUser[0] == "viaadmin") {
  752.                     $("#coordinator_div").show();
  753.                 } else if (response.message == "ChatEnabled" & & response.subject == "Command" && fromUser[0] == "viaadmin") {
  754.                     myApp.isChatDisabled = false;
  755.                     $(".chat_start,#allparticipants").removeClass("inactiveLink");
  756.                     $("#moderation_chat").prop('disabled', false).prop('checked', true);
  757.                 } else if (response.message == "ChatDisabled" && response.subject == "Command" && fromUser[0] == "viaadmin") {
  758.                     myApp.isChatDisabled = true;
  759.                     $("#moderation_chat").prop('checked', false);
  760.                     $(".chat_start,#allparticipants").addClass("inactiveLink");
  761.                 } else if (response.message == "ExamStarted" && fromUser[0] == "viaadmin") {
  762.                     $(".all_features").hide();
  763.                     $("#exam_td,.all_exam").show();
  764.                     $("#detail_grid,.always-at-bottom").hide();
  765.                     $("#user_listing,.features,#presentmeimg,#moderator,#moderation_chat").addClass("inactiveLink");
  766.                     window.resizeTo(585, 145);
  767.                     $(".always-at-bottom,#myfooter,#touch_pad,#chat_user,#chat_window,.allow_present_screen,#users,#detail_grid,#features_disp,#third_party_apps,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info").hide();
  768.                     if (isPresentor == true) {
  769.                         stopPresenting();
  770.                     }
  771.  
  772.                 } else if (response.message == "ExamStoped" && fromUser[0] == "viaadmin") {
  773.                     $("#coordinator_div").hide();
  774.                     $(".all_features,always-at-bottom").show();
  775.                     $("#exam_td,.all_exam").hide();
  776.                     $("#user_listing,.features,#presentmeimg,#moderator,#moderation_chat").removeClass("inactiveLink");
  777.                     $(".always-at-bottom,#myfooter,#touch_pad,#chat_user,#chat_window,.allow_present_screen,#users,#detail_grid,#features_disp,#third_party_apps,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info").hide();
  778.                     window.resizeTo(585, 130);
  779.                 } else if (response.message == "SetStaff" && fromUser[0] == "viaadmin") {
  780.                     myApp.socketId.send(JSON.stringify({
  781.                         "request": "basicModeratorIn", "isPresenting": isPresenting, "isPwdReq": 0, "password": mod_pass, "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey, "clientReqKey": myApp.clientReqKey
  782.                     }));
  783.                     $.fn.markPresenceForDndGateway("Yes");
  784.                 } else if (response.message == "UnSetStaff" && fromUser[0] == "viaadmin") {
  785.                     $("#moderator").html("Become Moderator").prop('disabled', false);
  786.                     if ($("#mirror_users").is(":visible") == true) {
  787.                         $("#mirror_users").hide();
  788.                         $("#detail_grid,#users").show();
  789.                     }
  790.                     myApp.moderatorName = "";
  791.                     $.fn.sendLeaveModerationReq();
  792.                     $("#mirror_band").hide();
  793.                 } else if (response.message == "SetDNDAdmin" && fromUser[0] == "viaadmin") {
  794.                     $.fn.enableDnd();
  795.                 } else if (response.message == "UnSetDNDAdmin" && fromUser[0] == "viaadmin") {
  796.                     $.fn.disableDnd();
  797.                 } else if ((response.subject == "MirroringUpdated" || response.subject == "SetMirroringList") && fromUser[0] == "viaadmin") {
  798.                     $("#mirror_listing").empty();
  799.                     if (response.message == "UNAVAILABLE") {
  800.                         myApp.isMirrorUsers = "No";
  801.                         $("#mirror_band").hide();
  802.                         $("#mirror_users").hide();
  803.                         $("#mirror_listing").empty();
  804.                         if ($("#coordinator_div").is(":visible") == true) {
  805.                             window.resizeTo(585, 145);
  806.                         } else {
  807.                             window.resizeTo(585, 130);
  808.                         }
  809.                         $("#users,#detail_grid,.always-at-bottom").hide();
  810.                     } else {
  811.                         var mirr_users_arr = response.message.split("#");
  812.                         if (mirr_users_arr.length > 0) {
  813.                             myApp.isMirrorUsers = "Yes";
  814.                         }
  815.                         mirr_users_arr.forEach(function (element) {
  816.                             if (element != "") {
  817.                                 var htmlData = '<div style="padding-top: 5px;width: 100%">';
  818.                                 htmlData += '<div style="float: left; width: 16%; margin-left: 20px"><img src="icons/MediumSmiley.png" style="vertical-align:middle"></div>';
  819.                                 htmlData += '<div style="float: left; width: 38%; padding-top: 8px;">' + element.split("_")[1] + '</div>'
  820.                                 htmlData += '<div class="' + element + ' mirror_stop" style="float: left; width: 40%; text-align: center; padding-top: 5px;"><img src="icons/display_active.png" style="vertical-align:middle"></div>';
  821.                                 if (mirr_users_arr.length > 1 && mirr_users_arr[2] != undefined) {
  822.                                     htmlData += '<div style="width: 96%; float: left; padding-left: 20px;"><hr></hr></div>';
  823.                                 }
  824.                                 htmlData += '</div>';
  825.                                 $("#mirror_listing").append(htmlData);
  826.                             }
  827.                         });
  828.                         if ($("#mirror_users").is(":visible") == false) {
  829.                             if ($("#touch_pad").is(":visible") == false) {
  830.                                 $("#mirror_band").show();
  831.                                 window.resizeTo(585, 650);
  832.                             }
  833.                             //$("#mirror_band").show();
  834.                         }
  835.                     }
  836.  
  837.                 } else if (response.message == "PresentRequest" && fromUser[0] == "viaadmin") {
  838.                     var classNameAllow = fromUser[0] + '_present';
  839.                     if ($("." + classNameAllow).length == 0) {
  840.                         var htmlData = '<div class="' + classNameAllow + '" style="border: 1px solid;  background-color: #FFFFFF; width: 283px; height: 185px; margin-right: auto; margin-left: auto;">';
  841.                         htmlData += '<table style="width:100%;">';
  842.                         htmlData += '<tr>';
  843.                         htmlData += '<td style="background-color: #FFC001; height: 30px;"></td>';
  844.                         htmlData += '</tr>';
  845.                         htmlData += '<tr>';
  846.                         htmlData += '<td style=" font-size: 13px; padding-left:5px;padding-top:5px; color:#000000">You have been selected to present to the main dispaly.</td>';
  847.                         htmlData += '</tr>';
  848.                         htmlData += '<tr>';
  849.                         htmlData += '<td style="padding-top:65px;">';
  850.                         htmlData += '<button class="logout" id="accept_present" style="width: 35%; height: 32px; font-size: 12px; margin-left: 5px;">Accept</button>';
  851.                         htmlData += '<button class="logout" id="reject_present" style="width: 35%; height: 32px; font-size: 12px; margin-left:10px;">Reject</button>';
  852.                         htmlData += '<img src="icons/logo_noname.png" style="outline:none; vertical-align:middle; padding-left:10px;" border=0>';
  853.                         htmlData += '</td>';
  854.                         htmlData += '</tr>';
  855.                         htmlData += '</table>';
  856.                         htmlData += '</div>';
  857.                         $(".allow_present_screen").append(htmlData);
  858.                         $(".allow_present_screen").show();
  859.                         var d = new Date();
  860.                         var startTime = d.getTime();
  861.                         displayUserWaiting.push(classNameAllow + "~" + startTime);
  862.                     }
  863.  
  864.                 } else if ((response.message == "PresentRequestOne" || response.message == "PresentRequestShare") && fromUser[0] == "viaadmin") {
  865.                     //PresentRejected comes when user rejected the moderator present request.                    
  866.                     var counter = 1;
  867.                     var timer = setInterval(function () {
  868.                         if (counter == 15 || $(".moderator_share_req").is(":visible") == false) {
  869.                             $(".moderator_share_req").hide();
  870.                             clearInterval(timer);
  871.                         }
  872.                         counter++;
  873.                     }, 1000)
  874.                     $(".moderator_share_req").show();
  875.                     $("#users,#detail_grid,.always-at-bottom").show();
  876.                     window.resizeTo(585, 650);
  877.                     $(document).on("click", ".moderator_share_reply", function () {
  878.                         var message = $(this).val();
  879.                         $(".moderator_share_req").hide();
  880.                         myApp.socketId.send(JSON.stringify({
  881.                             "request": "modAskShareReply", "totalDisp": myApp.totalDisplayRunning,
  882.                             "actionType": response.message, "action": message, "jid": myApp.jid,
  883.                             "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey, "clientReqKey": myApp.clientReqKey
  884.                         }));
  885.                     });
  886.                 } else if (response.subject == "GDARequestShareTwo" && fromUser[0] == "viaadmin") {
  887.                     window.resizeTo(585, 650);
  888.                     $("#touch_pad,#chat_user,#third_party_apps,#features_disp,.file_transfer_options,.file_receive_prompt,#chat_window").hide();
  889.                     $("#users,#detail_grid,.always-at-bottom").show();
  890.                     var requestFrom = response.message.split("@");
  891.                     var classNameAllow = requestFrom[0] + '_allow_dual';
  892.                     if ($("." + classNameAllow).length == 0) {
  893.                         var htmlData = '<div class="' + classNameAllow + ' allow_dual" style="border: 1px solid;  background-color: #FFFFFF;">';
  894.                         htmlData += '<table style="width:100%; padding-top: 10px; padding-left:5px;" cellspacing="5" cellpadding="5">';
  895.                         htmlData += '<tr> ';
  896.                         htmlData += '<td align="center">'
  897.                         htmlData += '<img src="icons/logo_noname.png" style="outline:none;" border=0>';
  898.                         htmlData += '<img class="allow_dual_share_cross" src="icons/cross.png" border=0 style="outline:none;" align="right">';
  899.                         htmlData += '</td>';
  900.                         htmlData += '</tr>';
  901.                         htmlData += '<tr>';
  902.                         htmlData += '<td style="border: 1px solid blue; height: 50px; vertical-align: top;"><span>[' + requestFrom[0] + ']</span> has requested to present.</td>';
  903.                         htmlData += '</tr>';
  904.                         htmlData += '<tr>';
  905.                         htmlData += '<td style="height: 50px; vertical-align: top;">';
  906.                         htmlData += '<button data-allowto="' + response.message + '" class="logout allow_dual_first" style="margin-left: 7px; width: 47%; height: 32px; font-size: 11px;">Allow full screen on first display</button>';
  907.                         htmlData += '<button data-allowto="' + response.message + '" class="logout allow_dual_second" style="margin-left: 7px; width: 47%; height: 32px; font-size: 11px;">Allow full screen on second display</button>';
  908.                         htmlData += '<button data-allowto="' + response.message + '" class="logout allow_dual_auto_position" style="margin-left: 7px; width: 47%;height: 32px; font-size: 11px;">Allow (Auto Position)</button>';
  909.                         htmlData += '<button data-denyto="' + response.message + '" class="logout deny_access_dual" style="margin-left: 7px; width: 47%; height: 32px; font-size: 11px;">Deny</button>';
  910.                         htmlData += '</td>';
  911.                         htmlData += '</tr>';
  912.                         htmlData += '</table>';
  913.                         htmlData += '</div>';
  914.                         $(".allow_present_screen").append(htmlData);
  915.                         $(".allow_present_screen").show();
  916.                     }
  917.                 } else if ((response.subject == "GDARequestShare" || response.subject == "GDARequestFull") && fromUser[0] == "viaadmin") {
  918.                     window.resizeTo(585, 650);
  919.                     $("#touch_pad,#chat_user,#third_party_apps,#features_disp,.file_transfer_options,.file_receive_prompt,#chat_window").hide();
  920.                     $("#users,#detail_grid,.always-at-bottom").show();
  921.                     if (response.message.indexOf("IOSMIRRORNAME") < 5) {
  922.                         var requestFrom = response.message.split("@");
  923.                         var classNameAllow = requestFrom[0] + '_allow';
  924.                         if ($("." + classNameAllow).length == 0) {
  925.                             var htmlData = '<div class="' + classNameAllow + ' allow" style="border: 1px solid;  background-color: #FFFFFF;">';
  926.                             htmlData += '<table style="width:100%; padding-top: 10px; padding-left:5px;" cellspacing="5" cellpadding="5">';
  927.                             htmlData += '<tr > ';
  928.                             htmlData += '<td align="center">'
  929.                             htmlData += '<img src="icons/logo_noname.png" style="outline:none;" border=0>';
  930.                             htmlData += '<img class="allow_share_cross" src="icons/cross.png" border=0 style="outline:none;" align="right">';
  931.                             htmlData += '</td>';
  932.                             htmlData += '</tr>';
  933.                             htmlData += '<tr>';
  934.                             htmlData += '<td style="border: 1px solid blue; height: 50px; vertical-align: top;"><span>[' + requestFrom[0] + ']</span> has requested to present.</td>';
  935.                             htmlData += '</tr>';
  936.                             htmlData += '<tr>';
  937.                             htmlData += '<td style="height: 50px; vertical-align: top;">';
  938.                             htmlData += '<button class="logout allow_full_screen" style="width: 47%; height: 32px; font-size: 11px;">Allow full screen</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  939.                             if (response.subject == "GDARequestShare") {
  940.                                 htmlData += '<button class="logout allow_auto_position" style="width: 47%;height: 32px; font-size: 11px;">Allow (Auto Position)</button>';
  941.                             }
  942.                             htmlData += '<button id="' + requestFrom[0] + '_deny" class="logout deny_access" style="width: 47%; height: 32px; font-size: 11px;">Deny</button>';
  943.                             htmlData += '</td>';
  944.                             htmlData += '</tr>';
  945.                             htmlData += '</table>';
  946.                             htmlData += '</div>';
  947.                             $(".allow_present_screen").append(htmlData);
  948.                             $(".allow_present_screen").show();
  949.                             var d = new Date();
  950.                             var startTime = d.getTime();
  951.                             displayUserWaiting.push(classNameAllow + "~" + startTime);
  952.                         }
  953.                     } else if (response.message.indexOf("IOSMIRRORNAME") > 5) {
  954.                         // $("#touch_pad,#chat_user,#third_party_apps,#features_disp,.file_transfer_options,.file_receive_prompt,#chat_window").hide();
  955.                         var mirrorRequestFrom = response.message.split("@");
  956.                         mirrorRequestIpAdd = mirrorRequestFrom[1].split("_")[0];
  957.                         if (!(mirrorRequestIpAdd in myApp.mirrorUsers)) {
  958.                             myApp.mirrorUsers[mirrorRequestIpAdd] = {"onlyName": mirrorRequestFrom[0],
  959.                                 "fullName": response.message,
  960.                                 "time": myApp.getCurrentTimeStamp()
  961.                             };
  962.                             var allowMirrTimerClass = myApp.mirrorUsers[mirrorRequestIpAdd].time + "_timer";
  963.                             showMirroringTimer(30, mirrorRequestIpAdd);
  964.                             var htmlData = '<div class="' + myApp.mirrorUsers[mirrorRequestIpAdd].time + ' allow" style="border: 1px solid;  background-color: #FFFFFF;">';
  965.                             htmlData += '<table style="width:100%; padding-top: 0px; padding-left:5px;" cellspacing="5" cellpadding="5">';
  966.                             htmlData += '<tr> ';
  967.                             htmlData += '<td colspan="2">'
  968.                             htmlData += '<img src="icons/logo_noname.png" style="outline:none;" border=0>';
  969.                             htmlData += '<img class="allow_share_cross" src="icons/cross.png" border=0 style="outline:none;" align="right">';
  970.                             htmlData += '</td>';
  971.                             htmlData += '</tr>';
  972.                             htmlData += '<tr>';
  973.                             htmlData += '<td style="height: 40px; vertical-align: top;"><span>[' + mirrorRequestFrom[0] + ']</span> has requested to present.</td>';
  974.                             htmlData += '<td align="right" style="vertical-align: top;"><span class="' + allowMirrTimerClass + '">&nbsp;</span></td>';
  975.                             htmlData += '</tr>';
  976.                             htmlData += '<tr>';
  977.                             htmlData += '<td colspan="2" style="height: 50px; vertical-align: top;">';
  978.                             htmlData += '<button class="logout mirror_full_screen" data-from ="' + mirrorRequestIpAdd + '" style="width: 47%; height: 32px; font-size: 11px;">Allow full screen</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  979.                             if (response.subject == "GDARequestShare") {
  980.                                 htmlData += '<button class="logout mirror_auto_position" data-from ="' + mirrorRequestIpAdd + '"style="width: 47%;height: 32px; font-size: 11px;">Allow (Auto Position)</button>';
  981.                             }
  982.                             htmlData += '<button class="logout deny_mirror" data-from ="' + mirrorRequestIpAdd + '" style="width: 47%; height: 32px; font-size: 11px;">Deny</button>';
  983.                             htmlData += '</td>';
  984.                             htmlData += '</tr>';
  985.                             htmlData += '</table>';
  986.                             htmlData += '</div>';
  987.                             $(".allow_present_screen").append(htmlData);
  988.                             $(".allow_present_screen").show();
  989.                         }
  990.                     }
  991.  
  992.                 } else if (response.subject == "GDAGrantShare" && fromUser[0] == "viaadmin") {
  993.                     var requestFrom = response.message.split("@");
  994.                     //myApp.presentRequestFrom = response.message;
  995.                     //////console.log(myApp.presentRequestFrom);    
  996.                     $("#users,#detail_grid,.always-at-bottom").show();
  997.                     window.resizeTo(585, 650);
  998.                     var classNameAllow = requestFrom[0] + '_allow';
  999.                     if ($("." + classNameAllow).length == 0) {
  1000.                         var htmlData = '<div class="' + classNameAllow + ' allow" style="border: 1px solid;  background-color: #FFFFFF;">';
  1001.                         htmlData += '<table style="width:100%; padding-top: 10px; padding-left:5px;" cellspacing="5" cellpadding="5">';
  1002.                         htmlData += '<tr > ';
  1003.                         htmlData += '<td align="center">'
  1004.                         htmlData += '<img src="icons/logo_noname.png" style="outline:none;" border=0>';
  1005.                         htmlData += '<img class="allow_share_cross" src="icons/cross.png" border=0 style="outline:none;" align="right">';
  1006.                         htmlData += '</td>';
  1007.                         htmlData += '</tr>';
  1008.                         htmlData += '<tr>';
  1009.                         htmlData += '<td style="border: 1px solid blue; height: 50px; vertical-align: top;"><span>[' + requestFrom[0] + ']</span> has requested to present.</td>';
  1010.                         htmlData += '</tr>';
  1011.                         htmlData += '<tr>';
  1012.                         htmlData += '<td style="height: 50px; vertical-align: top;">';
  1013.                         htmlData += '<button class="logout allow_full_screen" style="width: 47%; height: 32px; font-size: 11px;">Allow full screen</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1014.                         htmlData += '<button class="logout allow_auto_position" style="width: 47%;height: 32px; font-size: 11px;">Allow (Auto Position)</button>';
  1015.                         htmlData += '</td>';
  1016.                         htmlData += '</tr>';
  1017.                         htmlData += '</table>';
  1018.                         htmlData += '</div>';
  1019.                         $(".allow_present_screen").append(htmlData);
  1020.                         $(".allow_present_screen").show();
  1021.                     }
  1022.                 } else if (response.subject == "GDAGrantShareTwo" && fromUser[0] == "viaadmin") {
  1023.                     window.resizeTo(585, 650);
  1024.                     $("#users,#detail_grid,.always-at-bottom").show();
  1025.                     var requestFrom = response.message.split("@");
  1026.                     var classNameAllow = requestFrom[0] + '_allow_dual';
  1027.                     if ($("." + classNameAllow).length == 0) {
  1028.                         var htmlData = '<div  class="' + classNameAllow + ' allow_dual" style="border: 1px solid;  background-color: #FFFFFF;">';
  1029.                         htmlData += '<table style="width:100%; padding-top: 10px; padding-left:5px;" cellspacing="5" cellpadding="5">';
  1030.                         htmlData += '<tr > ';
  1031.                         htmlData += '<td align="center">';
  1032.                         htmlData += '<img src="icons/logo_noname.png" style="outline:none;" border=0>';
  1033.                         htmlData += '<img class="allow_dual_share_cross" src="icons/cross.png" border=0 style="outline:none;" align="right">';
  1034.                         htmlData += '</td>';
  1035.                         htmlData += '</tr>';
  1036.                         htmlData += '<tr>';
  1037.                         htmlData += '<td style="border: 1px solid blue; height: 50px; text-align: center;vertical-align: top;">Selected User: <span>[' + requestFrom[0] + ']</span></td>';
  1038.                         htmlData += '</tr>';
  1039.                         htmlData += '<tr>';
  1040.                         htmlData += '<td style="height: 50px; vertical-align: top;">';
  1041.                         htmlData += '<button data-allowto="' + response.message + '" class="logout allow_dual_first" style="margin-left: 7px; width: 47%; height: 32px; font-size: 11px;">Allow full screen on first display</button>';
  1042.                         htmlData += '<button data-allowto="' + response.message + '" class="logout allow_dual_second" style="margin-left: 7px; width: 47%; height: 32px; font-size: 11px;">Allow full screen on second display</button>';
  1043.                         htmlData += '<button data-allowto="' + response.message + '" class="logout allow_dual_auto_position" style="margin-left: 7px; width: 47%;height: 32px; font-size: 11px;">Allow (Auto Position)</button>';
  1044.                         htmlData += '</td>';
  1045.                         htmlData += '</tr>';
  1046.                         htmlData += '</table>';
  1047.                         htmlData += '</div>';
  1048.                         $(".allow_present_screen").append(htmlData);
  1049.                         $(".allow_present_screen").show();
  1050.                     }
  1051.                 } else if (response.message == "PresentStopWaiting") {
  1052.                     $("#presentmeimg").attr('src', 'icons/PRESENT-OFF.png');
  1053.                     if (myApp.currentLoginMode == "") {
  1054.                         var isModSending = "Yes";
  1055.                     } else if (myApp.currentLoginMode == 3) {
  1056.                         var isModSending = myApp.moderatorName == myApp.jid ? "Yes" : "No";
  1057.                     } else if (myApp.currentLoginMode == 4 || myApp.currentLoginMode == 9) {
  1058.                         var isModSending = myApp.moderatorNames.indexOf(myApp.jid) != -1 ? "Yes" : "No";
  1059.                     }
  1060.                     myApp.socketId.send(JSON.stringify({
  1061.                         "boxPeerId": peerId,
  1062.                         "request": "stopPresentStatus",
  1063.                         "isModerator": isModSending,
  1064.                         "jid": myApp.jid,
  1065.                         "type": "client",
  1066.                         "xmppExeReqKey": myApp.xmppExeReqKey
  1067.                     }));
  1068.                     return;
  1069.                 } else if (response.message == "Present" && fromUser[0] == "viaadmin") {
  1070.                     publishPresenting();
  1071.                 } else if (response.message == "PresentUnStaff" && fromUser[0] == "viaadmin") {
  1072.                     publishPresenting();
  1073.                 } else if ((response.message == "PresentStopOne" || response.message == "PresentStop") && fromUser[0] == "viaadmin") {
  1074.                     if (response.message == "PresentStopOne") {
  1075.                         if (myApp.presentOnMonitorId == 1) {
  1076.                             if (isPresentor == true) {
  1077.                                 stopPresenting();
  1078.                             }
  1079.                         }
  1080.                     } else if (response.message == "PresentStop") {
  1081.                         if (isPresentor == true) {
  1082.                             stopPresenting();
  1083.                         }
  1084.                     }
  1085.                 } else if (response.message == "PollStarted") {
  1086.                     myApp.chromeButtonNotification("A new poll is available. Please participate.")
  1087.                     $("#epoll").show();
  1088.                 } else if (response.message == "PollStoped") {
  1089.                     $("#epoll").hide();
  1090.                 } else if (response.subject == "DNDEnabled") {
  1091.                     if (onlyUser[0] != response.message) {
  1092.                         if (isPresentor == true) {
  1093.                             stopPresenting();
  1094.                         }
  1095.                         $("#coordinator_div").html("[" + response.message + "] has enabled DND.").show();
  1096.                         $("#user_listing,.features,#presentmeimg").addClass("inactiveLink");
  1097.                         //$("#presentmeimg").attr('src', 'icons/admin_dnd.png')
  1098.                         window.resizeTo(585, 145);
  1099.                         $(".always-at-bottom,#myfooter,#touch_pad,#chat_user,#chat_window,.allow_present_screen,#users,#detail_grid,#features_disp,#third_party_apps,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info").hide();
  1100.                     }
  1101.                 } else if (response.subject == "DNDDisabled") {
  1102.                     $("#user_listing,.features,#presentmeimg,#presentmetext,.chat_start").removeClass("inactiveLink");
  1103.                     if (onlyUser[0] != response.message) {
  1104.                         if(myApp.isChatDisabled == true){
  1105.                            $(".chat_start").addClass("inactiveLink");
  1106.                         }
  1107.                         $("#coordinator_div").hide();
  1108.                         window.resizeTo(585, 130);
  1109.                         $(".always-at-bottom,#myfooter,#touch_pad,#chat_user,#chat_window,.allow_present_screen,#users,#detail_grid,#features_disp,#third_party_apps,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info").hide();
  1110.                     } else if (onlyUser[0] == response.message) {
  1111.                         $("#moderator").removeClass("inactiveLink");
  1112.                         if ($("#moderation_chat").is(":checked") == false) {
  1113.                             $(".chat_start").addClass("inactiveLink");
  1114.                         }
  1115.                     }
  1116.  
  1117.                 } else {
  1118.                     if (response.subject == "Chat") {
  1119.                         $("#mirror_users,#mirror_band").hide();
  1120.                         //var sendData = "chat~" + response.to + "~" + response.from + "~" + response.message + "~" + response.subject;
  1121.                         xmppChat.onMessage({"type": "chat", "to": response.to, "from": response.from, "message": response.message, "subject": response.subject});
  1122.                     }
  1123.  
  1124.                 }
  1125.             } else if (response.request == "boxPeerId") {
  1126.                 peerId = response.boxPeerId;
  1127.                 myApp.socketId.send(JSON.stringify({
  1128.                     "boxPeerId": peerId,
  1129.                     "request": "showMe",
  1130.                     "username": myApp.loginUserId,
  1131.                     "extwidth": screen.width,
  1132.                     "extheight": screen.height,
  1133.                     "clientReqKey": myApp.clientReqKey,
  1134.                     "type": "client"
  1135.                 }));
  1136.             } else if (response.request == "startPresent") {
  1137.                 $("#presentmeimg").attr("src", "icons/PRESENT-OFF.png");
  1138.                 myApp.totalDisplayRunning = response.numDispRun;
  1139.                 myApp.monitorId = response.monitorId;
  1140.                 //console.log(myApp.totalDisplayRunning, myApp.monitorId);
  1141.                 if (isAskingPermission == "No") {
  1142.                     $('.present_type_radio').prop('checked', false);
  1143.                     $(".prompt_present_screen").show();
  1144.                     window.resizeTo(585, 650);
  1145.                     $("#chat_window,#chat_user,#features_disp,#third_party_apps,#touch_pad,#myfooter,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info").hide();
  1146.                     $("#users,#detail_grid,.always-at-bottom").show();
  1147.                 } else {
  1148.                     isAskingPermission = "No";
  1149.                     if (isPresentor && !joinReceived) {
  1150.                         joinReceived = true;
  1151.                         window.resizeTo(669, 490);
  1152.                         if (screenShareSource == "screen") {
  1153.                             pendingPresentId = chrome.desktopCapture.chooseDesktopMedia(
  1154.                                     ["screen"], onAccessApproved);
  1155.                         } else if (screenShareSource == "window") {
  1156.                             pendingPresentId = chrome.desktopCapture.chooseDesktopMedia(
  1157.                                     ["window", "audio"], onAccessApproved);
  1158.                         } else if (screenShareSource == "tab") {
  1159.                             pendingPresentId = chrome.desktopCapture.chooseDesktopMedia(
  1160.                                     ["tab", "audio"], onAccessApproved);
  1161.                         }
  1162.                         screenShareSource = "";
  1163.                     }
  1164.                 }
  1165.                 //
  1166.             } else if (response.request == "iceCandidate" && shareFlowing) {
  1167.                 //////console.log('Received ICE candidate...');
  1168.                 var candidate = new RTCIceCandidate({
  1169.                     sdpMLineIndex: response.candidate.sdpMLineIndex,
  1170.                     sdpMid: response.candidate.sdpMid,
  1171.                     candidate: response.candidate.candidate
  1172.                 });
  1173.                 ////////console.log(candidate);
  1174.                 rtcInfo[peerId].addIceCandidate(candidate);
  1175.             } else if (response.request == "rccollaborationIceCandidate") {
  1176.                 myApp.dataChannelObj.addDcIceCandidate(response);
  1177.             } else if (response.request == "answer" && shareFlowing) {
  1178.                 //////console.log("recieved answer");
  1179.                 var RTCSessionDescription = window.mozRTCSessionDescription || window.webkitRTCSessionDescription || window.RTCSessionDescription;
  1180.                 rtcInfo[peerId].setRemoteDescription(new RTCSessionDescription(response.peerDescription));
  1181.             } else if (response.request == "collabanswer") {
  1182.                 console.log(response.peerDescription);
  1183.                 myApp.dataChannelObj.setDcRemoteDescription(response);
  1184.             } else if (response.request == "showFullScreenBtn") {
  1185.                 myApp.presentOnMonitorId = response.monitorId;
  1186.                 myApp.totalDisplayRunning = response.screenReserved;
  1187.                 //console.log("shikha");
  1188.                 if (isPresentor == true) {
  1189.                     $("#btnfullscreen").show();
  1190.                 }
  1191.                 if (myApp.currentLoginMode == "") {
  1192.                     $("#dnd_toggle").hide();
  1193.                     $.fn.markPresenceForDndGateway("Yes");
  1194.                 } else if (myApp.currentLoginMode == 3) {
  1195.                     if (myApp.modToggleDnd == 1) {
  1196.                         if (myApp.moderatorName == myApp.jid) {
  1197.                             $("#dnd_toggle").hide();
  1198.                             $.fn.markPresenceForDndGateway("Yes");
  1199.                         } else {
  1200.                             //$.fn.markPresenceForDndGateway("No");
  1201.                         }
  1202.                     }
  1203.                 } else if (myApp.currentLoginMode == 4) {
  1204.                     if (myApp.modToggleDnd == 1) {
  1205.                         if (myApp.moderatorNames.indexOf(myApp.jid) != -1) {
  1206.                             $("#dnd_toggle").hide();
  1207.                             $.fn.markPresenceForDndGateway("Yes");
  1208.                         } else {
  1209.                             // $.fn.markPresenceForDndGateway("No");
  1210.                         }
  1211.                     }
  1212.                 }
  1213.  
  1214.             } else if (response.request == "NOSPACE") {
  1215.                 //////console.log("Space Not Available");
  1216.                 myNotifications("Space Not Available to Show your Screen, Please try again after some time.");
  1217.                 $("#login").html("Login");
  1218.                 isPresentor = false;
  1219.             } else if (response.request == "hideFullScreenBtn") {
  1220.                 myApp.presentOnMonitorId = response.monitorId;
  1221.                 myApp.totalDisplayRunning = response.screenReserved;
  1222.                 if (myApp.currentLoginMode == "") {
  1223.                     if (myApp.modToggleDnd == 1) {
  1224.                         $("#dnd_toggle").show();
  1225.                         if ($("#btnfullscreen").is(":visible")) {
  1226.                             $.fn.markPresenceForDndGateway("Yes");
  1227.                         }
  1228.                     }
  1229.                 } else if (myApp.currentLoginMode == 3) {
  1230.                     if (myApp.modToggleDnd == 1) {
  1231.                         if (myApp.moderatorName == myApp.jid) {
  1232.                             $("#dnd_toggle").show();
  1233.                             if ($("#btnfullscreen").is(":visible")) {
  1234.                                 $.fn.markPresenceForDndGateway("Yes");
  1235.                             }
  1236.  
  1237.                         } else {
  1238.                             if ($("#btnfullscreen").is(":visible")) {
  1239.                                 $.fn.markPresenceForDndGateway("No");
  1240.                             }
  1241.                         }
  1242.                     }
  1243.                 } else if (myApp.currentLoginMode == 4) {
  1244.                     if (myApp.modToggleDnd == 1) {
  1245.                         if (myApp.moderatorNames.indexOf(myApp.jid) != -1) {
  1246.                             $("#dnd_toggle").show();
  1247.                             if ($("#btnfullscreen").is(":visible")) {
  1248.                                 $.fn.markPresenceForDndGateway("Yes");
  1249.                             }
  1250.  
  1251.                         } else {
  1252.                             if ($("#btnfullscreen").is(":visible")) {
  1253.                                 $.fn.markPresenceForDndGateway("No");
  1254.                             }
  1255.  
  1256.                         }
  1257.                     }
  1258.                 }
  1259.                 $("#btnfullscreen").hide();
  1260.             } else if (response.request == "stopShareAll") {
  1261.                 myNotifications("Another user has taken over the full screen or there is no additional space available to present.");
  1262.                 stopPresenting();
  1263.             } else if (response.request == "mediaRunning") {
  1264.                 myNotifications("Presentation is not allowed while media is playing on the main display. Please wait.");
  1265.                 stopPresenting();
  1266.             } else if (response.request == "byeserver" && shareFlowing) {
  1267.                 myNotifications("Room not available to present, Please try after some time.");
  1268.                 roomnotavilable()
  1269.                 stopPresenting();
  1270.             }
  1271.         }
  1272.     }
  1273.     $(document).on("click", ".mirror_stop", function (e) {
  1274.         var mirror_details = $(this).attr("class").split("_");
  1275.         var mirror_ip = mirror_details[0];
  1276.         myApp.socketId.send(JSON.stringify({
  1277.             "request": "stopMirroring",
  1278.             "mirrorIp": mirror_ip,
  1279.             "jid": myApp.jid,
  1280.             "type": "client",
  1281.             "xmppExeReqKey": myApp.xmppExeReqKey
  1282.         }));
  1283.     })
  1284.     document.addEventListener("contextmenu", function (e) {
  1285.         e.preventDefault();
  1286.     });
  1287.     $("#open_on_via").on("click", function () {
  1288.         $("#file_open_on_via").trigger("click");
  1289.     });
  1290.     $(document).on("change", "#file_open_on_via", function () {
  1291.         console.log(myApp.sendFileOpenOnVia);
  1292.         if (myApp.sendFileOpenOnVia == true) {
  1293.             var file = this.files[0];
  1294.             fileChangeOpenVia(file);
  1295.             $(".file_transfer_options,#features_disp").hide();
  1296.             $(this).val("");
  1297.         } else {
  1298.             $("#open_on_via_div").show();
  1299.             $("#features_disp,#detail_grid,.file_transfer_options").hide();
  1300.             myApp.customNotification("File is uploading. Please wait for it's completion to send another one.");
  1301.         }
  1302.  
  1303.     })
  1304.  
  1305.     $("#mouse_pad").bind("contextmenu", function (e) {
  1306.         e.preventDefault();
  1307.     });
  1308.     var message_text = "";
  1309.     var allXmppUsers = [];
  1310.     $.fn.extend({
  1311.         screenAfterLogin: function () {
  1312.             if (myApp.gatewayVersion != 0) {
  1313.                 /*setTimeout(function () {
  1314.                  createCollaborationPeerConn();
  1315.                  }, 1500);
  1316.                  setTimeout(function () {
  1317.                  peerConns[myApp.xmppExeReqKey].createOffer(setLocalPCOffer, errorCallback);
  1318.                  }, 2500);
  1319.                  setTimeout(function () {
  1320.                  peerConns[myApp.xmppExeReqKey].createOffer(setLocalPCOffer, errorCallback);
  1321.                  }, 2500); */
  1322.             }
  1323.             $("#allAction").show();
  1324.             $("#login_details").hide();
  1325.             $(myfooter).hide();
  1326.             $("#room_name").text(myApp.roomNameText);
  1327.             $("#login_user").text($.fn.getUserName(myApp.loginUserId));
  1328.             window.resizeTo(585, 130);
  1329.         },
  1330.         markPresenceForDndGateway: function (mod) {
  1331.             var isPresenting = isPresentor == true ? "Yes" : "No";
  1332.             myApp.socketId.send(JSON.stringify({
  1333.                 "request": "markPresence", "isPresenting": isPresenting, "totalDisp": myApp.totalDisplayRunning, "isMod": mod, "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey, "clientReqKey": myApp.clientReqKey
  1334.             }));
  1335.         },
  1336.         getUserName: function (username) {
  1337.             if (username.length > 15) {
  1338.                 return username.substr(0, 15) + "...";
  1339.             } else {
  1340.                 return username;
  1341.             }
  1342.         },
  1343.         screenAfterPresentation: function () {
  1344.             $("#touch_pad,#third_party_apps,#features_disp").hide();
  1345.             window.resizeTo(585, 650);
  1346.             if ($("#users").is(":visible") == false) {
  1347.                 $("#users,#detail_grid,.always-at-bottom").show();
  1348.             }
  1349.             //$("#chat_user,#coordinator_div,#third_party_apps,#features_disp,#detail_grid,.allow_present_screen,#users,#chat_window,#touch_pad,#myfooter,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info").hide();
  1350.         },
  1351.         manageXmppUsePosition: function (user, html) {
  1352.             allXmppUsers.push(user);
  1353.             allXmppUsers.sort();
  1354.             //////console.log(allXmppUsers);
  1355.             if (allXmppUsers.length == 1) {
  1356.                 $("#user_listing").append(html);
  1357.             } else if (allXmppUsers.length > 1) {
  1358.                 var pos = allXmppUsers.indexOf(user);
  1359.                 if (pos + 1 != allXmppUsers.length) {
  1360.                     var pos_insert = pos + 1;
  1361.                     var insert_before = "." + allXmppUsers[pos_insert] + "_class";
  1362.                     $(html).insertBefore(insert_before);
  1363.                     //////console.log(user, insert_before);
  1364.                 } else if (pos + 1 == allXmppUsers.length) {
  1365.                     var pos_insert = pos - 1;
  1366.                     var insert_after = "." + allXmppUsers[pos_insert] + "_class";
  1367.                     $(html).insertAfter(insert_after);
  1368.                 }
  1369.             }
  1370.         },
  1371.         getOnlineUsersHtml: function (user, isPresenting, isWaiting) {
  1372.             if (myApp.gatewayVersion == 0) {
  1373.                 var user_width = myApp.osType == 3 ? "400px" : "375px";
  1374.             } else {
  1375.                 var user_width = myApp.osType == 3 ? "400px" : "320px";
  1376.             }
  1377.             var display_width = myApp.osType == 3 ? "90px" : "70px";
  1378.             var chat_width = myApp.osType == 3 ? "70px" : "50px";
  1379.             var fileshare_width = "40px";
  1380.             var displayImage = "";
  1381.             if (user != "") {
  1382.                 html = '<div class="new_user ' + user + '_class">';
  1383.                 html += '<div class="user" style="width:' + user_width + '"><img src="icons/MediumSmiley.png" style="vertical-align:middle">&nbsp;&nbsp;' + $.fn.getUserName(user) + '</div>';
  1384.                 if (isPresenting == "Yes") {
  1385.                     displayImage = "icons/display_active.png";
  1386.                 } else if (isPresenting == "No") {
  1387.                     if (isWaiting == "Yes") {
  1388.                         displayImage = "icons/display_waiting.png";
  1389.                     } else if (isWaiting == "No") {
  1390.                         displayImage = "icons/display.png";
  1391.                     }
  1392.                 }
  1393.                 if (user != "viaadmin") {
  1394.                     html += '<div id="' + user + '_display" class="user display" style="width:' + display_width + '; text-align:center;"><img src="' + displayImage + '" style="vertical-align:middle"></div>';
  1395.                 } else {
  1396.                     html += '<div id="' + user + '_display" class="user" style="width:' + display_width + '; text-align:center;"><img src="' + displayImage + '" style="vertical-align:middle"></div>';
  1397.                 }
  1398.                 if (myApp.osType != 3) {
  1399.                     console.log(myApp.featureListChat, );
  1400.                     if (myApp.featureListChat == "yes") {
  1401.                         html += '<div id="' + user + '" class="user chat_start" style="width:' + chat_width + ';cursor:pointer;margin-left:20px; text-align:center;"><img src="icons/chat.png" style="vertical-align:middle"></div>';
  1402.                     }
  1403.  
  1404.                     if (myApp.gatewayVersion != 0) {
  1405.                         if (myApp.FeatureListFileTransfer == "yes") {
  1406.                             html += '<div id="' + user + '_share" class="user one_share" style="width:' + fileshare_width + '; text-align:center;margin-left:20px;">';
  1407.                             if (user != "viaadmin") {
  1408.                                 html += '  <label for="file-upload" style="padding-left:15px;"> <img src="icons/fileshare.png" style="vertical-align:middle"></label>';
  1409.                             } else if (user == "viaadmin") {
  1410.                                 html += '  <label id="admin_fileshare" style="padding-left:15px;"> <img src="icons/fileshare.png" style="vertical-align:middle"></label>';
  1411.                             }
  1412.                             html += '</div>';
  1413.                         }
  1414.                     }
  1415.                 }
  1416.                 html += "<div><hr></hr></div>";
  1417.                 html += "</div>";
  1418.                 $.fn.manageXmppUsePosition(user, html);
  1419.             }
  1420.             //$("#user_listing").append(html);
  1421.             //$("#" + user + ".chat_start").find("img").attr('src', 'ix`cons/chat_active.png');
  1422.         },
  1423.         setPresence: function (obj) {
  1424.             var userInfo = obj.from.split("@");
  1425.             if (obj.presence == "online") {
  1426.                 $.fn.getOnlineUsersHtml(userInfo[0], obj.isPresenting, obj.isWaiting);
  1427.             } else if (obj.presence == "offline") {
  1428.                 //console.log(obj);
  1429.                 myApp.manageChatUsers(userInfo[0], "remove");
  1430.                 var indexDelete = allXmppUsers.indexOf(userInfo[0]);
  1431.                 if (indexDelete > -1) {
  1432.                     allXmppUsers.splice(indexDelete, 1);
  1433.                 }
  1434.  
  1435.                 // If the moderator user is getting offline without doing the leave moderation
  1436.                 if (myApp.moderatorName == obj.from) {
  1437.                     $("#moderator").html("Become Moderator").prop('disabled', false);
  1438.                 }
  1439.  
  1440.                 if ($("." + userInfo[0] + "_allow")) {
  1441.                     $("." + userInfo[0] + "_allow").remove();
  1442.                     if ($(".allow_present_screen .allow").length == 0) {
  1443.                         $(".allow_present_screen").hide();
  1444.                     }
  1445.                 }
  1446.                 if ($("#" + userInfo[0]).length == 0) {
  1447.                     $("#" + userInfo[0] + "_display").parent().remove();
  1448.                 } else {
  1449.                     $("#" + userInfo[0]).parent().remove();
  1450.                 }
  1451.  
  1452.                 $("#" + myApp.getUserChatId(userInfo[0])).hide();
  1453.                 $("#" + myApp.getUserChatBoxId(userInfo[0])).hide();
  1454.                 if ($("#" + myApp.getUserChatId(userInfo[0])).hasClass("active_chat_user")) {
  1455.                     if ($("#chat_user").children(".open_chat").is(":visible") == false) {
  1456.                         $.fn.showParticipants("participants");
  1457.                     }
  1458.                     var setUserChatId = $('.open_chat:visible:first').attr("id");
  1459.                     if (setUserChatId) {
  1460.                         var setUserChatInfo = setUserChatId.split("_user");
  1461.                         $("#" + myApp.getUserChatId(setUserChatInfo[0])).addClass("active_chat_user");
  1462.                         $("#" + myApp.getUserChatBoxId(setUserChatInfo[0])).show();
  1463.                     }
  1464.  
  1465.                 }
  1466.             }
  1467.         },
  1468.         startChating: function (obj, callOn, messageText) {
  1469.             var user = obj.id;
  1470.             $("#" + user + ".chat_start").find("img").attr('src', 'icons/chat_active.png');
  1471.             myApp.manageChatUsers(user, "add");
  1472.             for (var i = 0; i < myApp.chatUsers.length; i++) {
  1473.                 var id_user = myApp.getUserChatId(myApp.chatUsers[i]);
  1474.                 var id_user_chat = myApp.getUserChatBoxId(myApp.chatUsers[i]);
  1475.                 if ($("#" + id_user).length == 0 && $("#" + id_user_chat).length == 0) {
  1476.                     $("#chat_user").append('<div id="' + id_user + '" class="open_chat"><img src="icons/SmallSmiley.png" style="vertical-align:middle; padding-right:10px;">' + $.fn.getUserName(myApp.chatUsers[i]) + '<span class="unseen_msg"></span></div>');
  1477.                     $("#chats").append('<div id="' + id_user_chat + '" style="height:440px;display:none;overflow:auto;" class="user_chat_msg"></div>');
  1478.                 }
  1479.             }
  1480.             if (callOn == "onMessage") {
  1481.                 if (messageText) {
  1482.                     messageText = messageText.replace(/\n/g, "<br />");
  1483.                     if (messageText.length > 45) {
  1484.                         var htmlAppend = '<div class="message_len rcorners2" style="text-align: left; margin: 15px 10px; 0 0">' + messageText + '</div>';
  1485.                     } else {
  1486.                         var htmlAppend = '<div class="message_len" style="text-align: left; margin-top: 15px;"><span class="rcorners2">' + messageText + '</span></div>';
  1487.                     }
  1488.  
  1489.                     if ($("#chat_user").is(":hidden") == true) {
  1490.                         $(".open_chat").removeClass("active_chat_user");
  1491.                         $(".user_chat_msg").hide();
  1492.                         $("#" + myApp.getUserChatId(user)).addClass("active_chat_user").show();
  1493.                         $("#" + myApp.getUserChatBoxId(user)).append(htmlAppend);
  1494.                         $("#" + myApp.getUserChatBoxId(user)).show();
  1495.                         $('.user_chat_msg').scrollTop(1000000);
  1496.                     } else {
  1497.                         var activeChatUser = $(".active_chat_user").closest("div").attr("id").split("_user");
  1498.                         if (user == activeChatUser[0]) {
  1499.                             $("#" + myApp.getUserChatBoxId(activeChatUser[0])).append(htmlAppend);
  1500.                             $("#" + myApp.getUserChatId(activeChatUser[0])).show();
  1501.                             $("#" + myApp.getUserChatBoxId(activeChatUser[0])).show();
  1502.                             $('.user_chat_msg').scrollTop(1000000);
  1503.                         } else {
  1504.                             if (user in unReadMsgCounts) {
  1505.                                 var cnt = unReadMsgCounts[user];
  1506.                                 var newCount = cnt + 1;
  1507.                                 unReadMsgCounts[user] = newCount;
  1508.                                 $("#" + myApp.getUserChatId(user) + " span").text(newCount);
  1509.                             } else {
  1510.                                 unReadMsgCounts[user] = 1;
  1511.                                 $("#" + myApp.getUserChatId(user) + " span").text("1");
  1512.                             }
  1513.                             $("#" + myApp.getUserChatBoxId(user)).append(htmlAppend);
  1514.                             $('.user_chat_msg').scrollTop(1000000);
  1515.                             $("#" + myApp.getUserChatId(activeChatUser[0])).show();
  1516.                         }
  1517.                     }
  1518.                 }
  1519.  
  1520.             } else if (callOn = "sendMessage") {
  1521.                 $(".user_chat_msg").hide();
  1522.                 $("#" + myApp.getUserChatId(user)).show();
  1523.                 $("#" + myApp.getUserChatBoxId(user)).show();
  1524.                 $(".open_chat").removeClass("active_chat_user");
  1525.                 $("#" + myApp.getUserChatId(user)).addClass("active_chat_user");
  1526.                 $("#" + myApp.getUserChatId(user) + " span").text("");
  1527.                 delete unReadMsgCounts[user];
  1528.             }
  1529.  
  1530.             $("#chat_window").show();
  1531.             $("#chat_user").show();
  1532.             $("#users").hide();
  1533.             $("#detail_grid").hide();
  1534.         },
  1535.         openChat: function (obj) {
  1536.             $("#msg").val("");
  1537.             $(".user_chat_msg").hide();
  1538.             var chat_user_id = obj.id + "_chat";
  1539.             $(".open_chat").removeClass("active_chat_user");
  1540.             $("#" + obj.id).addClass("active_chat_user");
  1541.             $("#" + obj.id + " span").text("");
  1542.             delete unReadMsgCounts[obj.id.split("_user")[0]];
  1543.             $("#" + chat_user_id).show();
  1544.         },
  1545.         showParticipants: function (id) {
  1546.             //$("#detail_grid").toggle();    
  1547.             $(".file_transfer_options").hide();
  1548.             if (id == "participants") {
  1549.                 if ($(window).height() > 160 && $("#users").is(":visible")) {
  1550.                     $("#mirror_band").hide();
  1551.                     if ($("#coordinator_div").is(":visible") == true) {
  1552.                         window.resizeTo(585, 145);
  1553.                     } else {
  1554.                         window.resizeTo(585, 130);
  1555.                     }
  1556.                     $("#users,#detail_grid,.always-at-bottom").hide();
  1557.                 } else {
  1558.                     if (myApp.isMirrorUsers == "Yes") {
  1559.                         $("#mirror_band").show();
  1560.                     }
  1561.                     window.resizeTo(585, 650);
  1562.                     $("#mirror_users,#chat_window,#chat_user,#features_disp,#third_party_apps,#touch_pad,#myfooter,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info,#open_on_via_div").hide();
  1563.                     $("#users,#detail_grid,.always-at-bottom").show();
  1564.                 }
  1565.             } else if (id == "allparticipants") {
  1566.                 if ($("#chat_user").parent().find('.active_chat_user').length == 1) {
  1567.                     var current_user_id = $("#chat_user").parent().find('.active_chat_user').attr("id");
  1568.                     var current_user_id = current_user_id.split("_user")
  1569.                     $.fn.startChating({"id": current_user_id[0]});
  1570.                     $("#features_disp").hide();
  1571.                 } else {
  1572.                     if (myApp.isMirrorUsers == "Yes") {
  1573.                         $("#mirror_band").show();
  1574.                     }
  1575.                     $("#mirror_users,#chat_window,#chat_user,#features_disp,#third_party_apps,#touch_pad,#myfooter,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info,#open_on_via_div").hide();
  1576.                     $("#users,#detail_grid,.always-at-bottom").show();
  1577.                 }
  1578.             }
  1579.  
  1580.         },
  1581.         login: function () {
  1582.             if (myApp.userValidityChk == "yes") {
  1583.                 //check for lower version 2.1 or 0
  1584.                 if (myApp.gatewayVersion == 0) {
  1585.                     if (myApp.roomCode != 0) {
  1586.                         $("#login").html("Login");
  1587.                         if (myApp.roomCode == $("#roomCode").val()) {
  1588.                             $("#login").html("Logging In...");
  1589.                             loginXmppUser.login();
  1590.                         } else {
  1591.                             $("#roomCode").addClass("text_error");
  1592.                             myApp.userValidityChk = "no";
  1593.                             $.fn.validateUser();
  1594.                         }
  1595.                     } else if (myApp.roomCode == 0) {
  1596.                         loginXmppUser.login();
  1597.                     }
  1598.                 } else {
  1599.                     loginXmppUser.login();
  1600.                 }
  1601.             } else {
  1602.                 //$("#login").html("Login");
  1603.                 $.fn.validateUser();
  1604.             }
  1605.             //intervalidofvalidatenetwork = setInterval(networkvalidate, reconnectInterval);
  1606.         },
  1607.         validateUser: function () {
  1608.             var db_name = $("#db_name").val().toLowerCase().replace(/ /g, "_");
  1609.             var db_pass = $("#db_pass").val();
  1610.             var username = $("#username").val().toLowerCase().replace(/ /g, "_");
  1611.             var domain = $("#domain").val();
  1612.             myApp.loginUserId = username != "" ? username : db_name;
  1613.             myApp.domain = domain;
  1614.             myApp.roomNameText = domain;
  1615.             if ($.fn.validateSpecialCharacters(myApp.loginUserId) == true) {
  1616.                 if (myApp.domain === "") {
  1617.                     $("#domain").setAttribute("class", "server-box-after");
  1618.                     return;
  1619.                 }
  1620.                 //////////////////////////////////////code to get id for gateway authorization with which you want to share/////////////////////////////////////
  1621.                 var xmlHttp = new XMLHttpRequest();
  1622.                 var url = "http://" + myApp.domain + "/id.php";
  1623.                 var showError = false;
  1624.                 xmlHttp.onreadystatechange = function () {
  1625.                     if (xmlHttp.readyState == 4) {
  1626.                         if (xmlHttp.status == 200) {
  1627.                             parseOut = [];
  1628.                             var response = xmlHttp.responseText;
  1629.                             var parseResposne = JSON.parse(response);
  1630.                             myApp.uniqueGatewayId = parseResposne['uniqueid'];
  1631.                             myApp.serverUrl = parseResposne['serverIP'];
  1632.                             myApp.serverPort = parseResposne['port'];
  1633.                             myApp.jid = username != "" ? username + "@" + parseResposne['ipadd'] : db_name + "@" + parseResposne['ipadd'];
  1634.                             myApp.domain = parseResposne['ipadd'];
  1635.                             var ws = new WebSocket("wss://" + myApp.serverUrl + ":" + myApp.serverPort);
  1636.                             myApp.socketId = ws;
  1637.                             ws.onopen = function ()
  1638.                             {
  1639.                                 ////////console.log("Websocket Connected");
  1640.                                 myApp.socketId.send(JSON.stringify({
  1641.                                     "request": "validateUser", "jid": myApp.jid, "db_pass": db_pass, "boxId": myApp.domain, "gatewayUniqueId": myApp.uniqueGatewayId, "version": "2.2", "type": "client"
  1642.                                 }));
  1643.                                 myApp.socketId.addEventListener("message", onWebSocketMessage, false);
  1644.                             }
  1645.  
  1646.  
  1647.                         } else {
  1648.                             ////console.log(" ocing while calling id.php");
  1649.                             if (showError == false) {
  1650.                                 myApp.customNotification("Login unsuccessful. Unable to reach chrome at this address");
  1651.                                 $("#login").html("Login");
  1652.                                 showError = true;
  1653.                             }
  1654.                         }
  1655.                     }
  1656.                 };
  1657.                 xmlHttp.open("GET", url, true);
  1658.                 xmlHttp.send();
  1659.             }
  1660.  
  1661.         },
  1662.         collaboration: function () {
  1663.             //shikha////////////////////
  1664.             $("#mouse_pad").width(myApp.touchPadWidth).height(myApp.touchPadHeight);
  1665.             var xmL = collaborationScreen.getXml("R", "1000", "0", "0", myApp.loginUserId);
  1666.             collaborationScreen.start(xmL);
  1667.             $("#touch_pad").show();
  1668.             $("#detail_grid,#features_disp,#third_party_apps,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info,.file_transfer_options").hide();
  1669.         },
  1670.         clearMessageBox: function () {
  1671.             $("#msg").blur();
  1672.             setTimeout(function () {
  1673.                 $("#msg").focus();
  1674.             }, 100);
  1675.         },
  1676.         sendMessage: function () {
  1677.             if ($.trim(message_text).length != 0) {
  1678.                 xmppChat.sendMessage();
  1679.             } else {
  1680.                 $.fn.clearMessageBox();
  1681.             }
  1682.             message_text = "";
  1683.         },
  1684.         logout: function () {
  1685.             if (isPresentor == true) {
  1686.                 stopPresenting();
  1687.             }
  1688.             $("#presentmeimg").attr("src", "icons/PRESENT-OFF.png");
  1689.             myApp.socketId.send(JSON.stringify({
  1690.                 "request": "logout", "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey, "clientReqKey": myApp.clientReqKey
  1691.             }));
  1692.             myApp.socketId.close();
  1693.             if (myApp.loginMode == 0) {
  1694.                 $("#loginBtnTd").css({"padding-top": "60px"});
  1695.                 $("#myfooter").css({"padding-top": "10px"});
  1696.             } else {
  1697.  
  1698.                 $("#loginBtnTd").css({"padding-top": "90px"});
  1699.                 $("#myfooter").css({"padding-top": "10px"});
  1700.             }
  1701.             window.resizeTo(440, 480);
  1702.             myApp.userValidityChk = "no";
  1703.             $("#moderator").html("Become Moderator");
  1704.             $("#roomCode").val("");
  1705.             $("#exam_td,#chat_user,#dnd_toggle,#allow_present_screen,#allAction,#chat_window,#features_disp,#third_party_apps,#touch_pad,#myfooter,#detail_grid,.always-at-bottom,#coordinator_div,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info").hide();
  1706.             $("#login_details,#myfooter").show();
  1707.             $("user_listing,.allow_present_screen").empty();
  1708.             $("#login").html("Login");
  1709.             $(".rc").hide();
  1710.             $("user_listing,.allow_present_screen").empty();
  1711.             myApp.loginMode = "";
  1712.             myApp.currentLoginMode = "";
  1713.             myApp.moderatorName = "";
  1714.             myApp.modToggleDnd = "";
  1715.             myApp.modToggleChat = "";
  1716.             myApp.modPwdReq = "";
  1717.             myApp.jid = "";
  1718.             window.location.reload();
  1719.         },
  1720.         reboot: function () {
  1721.             /*if (myApp.loginMode == 0 && myApp.loginMode != "" ) {                
  1722.              $("#loginBtnTd").css({"padding-top": "60px"});
  1723.              $("#myfooter").css({"padding-top": "10px"});
  1724.              } else if (myApp.loginMode == "" || myApp.loginMode == 3) {
  1725.              $("#loginBtnTd").css({"padding-top": "90px"});
  1726.              $("#myfooter").css({"padding-top": "10px"});
  1727.              }*/
  1728.             if (isPresentor == true) {
  1729.                 stopPresenting();
  1730.             }
  1731.             $("#presentmeimg").attr("src", "icons/PRESENT-OFF.png");
  1732.             $("#btnpause").hide();
  1733.             myApp.loginMode = "";
  1734.             myApp.currentLoginMode = "";
  1735.             myApp.moderatorName = "";
  1736.             myApp.modToggleDnd = "";
  1737.             myApp.modToggleChat = "";
  1738.             myApp.modPwdReq = "";
  1739.             // chrome.runtime.reload();
  1740.             $("#login").html("Login");
  1741.             $(".rc").hide();
  1742.             window.resizeTo(440, 480);
  1743.             myApp.socketId.close();
  1744.             myApp.userValidityChk = "no";
  1745.             $("#moderator").html("Become Moderator");
  1746.             $("#roomCode").val("");
  1747.             $("user_listing,.allow_present_screen").empty();
  1748.             $("#chat_user,#dnd_toggle,#allAction,#chat_window,#features_disp,#third_party_apps,#touch_pad,#myfooter,#detail_grid,.always-at-bottom,#coordinator_div,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info").hide();
  1749.             $("#login_details,#myfooter").show();
  1750.             window.location.reload();
  1751.         },
  1752.         isJson: function (str) {
  1753.             try {
  1754.                 JSON.parse(str);
  1755.             } catch (e) {
  1756.                 return false;
  1757.             }
  1758.             return true;
  1759.         },
  1760.         enableDnd: function () {
  1761.             $("#dnd_toggle").attr('src', 'icons/dnd_ena.png');
  1762.             $("#moderator").addClass("inactiveLink");
  1763.             $("#user_listing,.features,#presentmeimg").addClass("inactiveLink");
  1764.             myApp.socketId.send(JSON.stringify({
  1765.                 "request": "dnd", "message": "SetDND", "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  1766.             }));
  1767.         },
  1768.         disableDnd: function () {
  1769.             $("#dnd_toggle").attr('src', 'icons/dnd_dis.png');
  1770.             //$("#moderator").removeClass("inactiveLink");
  1771.             //$("#user_listing,.features,#presentmeimg").removeClass("inactiveLink");
  1772.             myApp.socketId.send(JSON.stringify({
  1773.                 "request": "dnd", "message": "UnSetDND", "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  1774.             }));
  1775.         },
  1776.         hideDisplayAllowRequest: function () {
  1777.             var d = new Date();
  1778.             var startTime = d.getTime();
  1779.             var endTime = startTime + 30000;
  1780.             if (displayUserWaiting.length > 0) {
  1781.                 for (var i = 0; i <= displayUserWaiting.length - 1; i++) {
  1782.                     //////console.log(displayUserWaiting[0]);
  1783.                     //////console.log(i, displayUserWaiting[i]);
  1784.                     var elemsArray = displayUserWaiting[i].split("~");
  1785.                     //////console.log(elemsArray);
  1786.                     if (d.getTime() > parseInt(elemsArray[1]) + 30000) {
  1787.                         $("." + elemsArray[0]).remove();
  1788.                         displayUserWaiting.splice(i, 1);
  1789.                         //console.log(displayUserWaiting);
  1790.                         if (displayUserWaiting.length == 0) {
  1791.                             $(".allow_present_screen").hide();
  1792.                         }
  1793.                     }
  1794.                 }
  1795.             }
  1796.         },
  1797.         authenticateModerator: function () {
  1798.             var mod_pass = $("#mod_pass").val();
  1799.             if (mod_pass != "") {
  1800.                 $.fn.sendModeratorReq(mod_pass);
  1801.             } else {
  1802.                 //$("#mod_error").show();
  1803.             }
  1804.         },
  1805.         validateSpecialCharacters: function (username) {
  1806.             var pattern = new RegExp(/[@^&,]/); //unacceptable chars
  1807.             if (pattern.test(username)) {
  1808.                 $("#login").html("Login");
  1809.                 $("#username").prop('disabled', false);
  1810.                 myNotifications("Invalid Nick Name. Please enter a Nick Name that does not contain any special characters.");
  1811.                 return false;
  1812.             }
  1813.             return true; //good user input
  1814.         },
  1815.         sendModeratorReq: function (mod_pass) {
  1816.             isPresenting = $("#presentmetext").text() == "Present" ? "No" : "Yes";
  1817.             ////console.log(isPresenting);
  1818.             myApp.socketId.send(JSON.stringify({
  1819.                 "request": "basicModeratorIn", "totalDisp": myApp.totalDisplayRunning, "isPresenting": isPresenting, "isPwdReq": myApp.modPwdReq, "password": mod_pass, "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey, "clientReqKey": myApp.clientReqKey
  1820.             }));
  1821.         },
  1822.         sendLeaveModerationReq: function () {
  1823.             $("#dnd_toggle,#mod_chat_disp").hide();
  1824.             isPresenting = $("#presentmetext").text() == "Present" ? "No" : "Yes";
  1825.             myApp.socketId.send(JSON.stringify({
  1826.                 "request": "basicModeratorOut", "totalDisp": myApp.totalDisplayRunning, "isPresenting": isPresenting, "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey, "clientReqKey": myApp.clientReqKey
  1827.             }));
  1828.             myApp.socketId.send(JSON.stringify({
  1829.                 "request": "manageModChat", "message": "ChatEnabled", "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  1830.             }));
  1831.             $("#user_listing,#allparticipants").removeClass("inactiveLink");
  1832.         },
  1833.         loginOnClick: function () {
  1834.             if ($("#domain").val() != "") {
  1835.                 if ($("#username").is(":hidden") == false) {
  1836.                     if ($("#username").val() != "") {
  1837.                         $("#username").prop('disabled', true);
  1838.                         $("#login").html("Logging In...");
  1839.                         connect();
  1840.                     } else {
  1841.                         $("#username").addClass("text_error");
  1842.                     }
  1843.                 }
  1844.                 if ($("#db_name").is(":hidden") == false) {
  1845.                     if ($("#db_name").val() != "" && $("#db_pass").val() != "") {
  1846.                         $("#login").html("Logging In...");
  1847.                         $("#db_name,#db_pass").prop('disabled', true);
  1848.                         connect();
  1849.                     } else {
  1850.                         if ($("#db_name").val() == "") {
  1851.                             $("#db_name").addClass("text_error");
  1852.                         }
  1853.                         if ($("#db_pass").val() == "") {
  1854.                             $("#db_pass").addClass("text_error");
  1855.                         }
  1856.                     }
  1857.                 }
  1858.                 if ($("#roomCode").is(":hidden") != false) {
  1859.                     if ($("#roomCode").val() == "") {
  1860.                         $("#roomCode").addClass("text_error");
  1861.                     }
  1862.                 }
  1863.             } else {
  1864.                 $("#domain").addClass("text_error");
  1865.             }
  1866.         }
  1867.  
  1868.     });
  1869.     $(document).on("click", ".present_type_radio", function () {
  1870.         screenShareSource = this.id;
  1871.         if (isAskingPermission == "No") {
  1872.             if (isPresentor && !joinReceived) {
  1873.                 joinReceived = true;
  1874.                 window.resizeTo(669, 490);
  1875.                 if (screenShareSource == "screen") {
  1876.                     pendingPresentId = chrome.desktopCapture.chooseDesktopMedia(
  1877.                             ["screen"], onAccessApproved);
  1878.                 } else if (screenShareSource == "window") {
  1879.                     pendingPresentId = chrome.desktopCapture.chooseDesktopMedia(
  1880.                             ["window", "audio"], onAccessApproved);
  1881.                 } else if (screenShareSource == "tab") {
  1882.                     pendingPresentId = chrome.desktopCapture.chooseDesktopMedia(
  1883.                             ["tab", "audio"], onAccessApproved);
  1884.                 }
  1885.                 screenShareSource = "";
  1886.             }
  1887.         } else {
  1888.             myApp.socketId.send(JSON.stringify({
  1889.                 "request": "grantDisplayMe", "message": "GrantDisplayMe", "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  1890.             }));
  1891.         }
  1892.         $(".prompt_present_screen").hide();
  1893.     });
  1894.     /* View Files code starts */
  1895.  
  1896.     $(document).on("click", "#call_view_files,#refresh_view_file", function () {
  1897.         myApp.socketId.send(JSON.stringify({
  1898.             "request": "viewFiles", "jid": myApp.jid, "type": "client", "clientReqKey": myApp.clientReqKey, "xmppExeReqKey": myApp.xmppExeReqKey
  1899.         }));
  1900.     });
  1901.     $(document).on("click", ".file_check", function () {
  1902.         if (this.checked == true) {
  1903.             if ($('input.file_check:checked').length <= 1) {
  1904.                 myApp.viewFileDownload.push({"filaname": $(this).attr('data-filename'), "filepath": $(this).attr('data-filepath')});
  1905.             } else {
  1906.                 alert("You can select only one file.");
  1907.                 $(this).prop('checked', false);
  1908.             }
  1909.         } else {
  1910.             var selectedFile = $(this).attr('data-filename');
  1911.             $.each(myApp.viewFileDownload, function (index, value) {
  1912.                 $.each(value, function (key, val) {
  1913.                     if (key == "filaname") {
  1914.                         if (val == selectedFile) {
  1915.                             delete myApp.viewFileDownload[index];
  1916.                         }
  1917.                     }
  1918.                 });
  1919.             });
  1920.         }
  1921.     })
  1922.     $(document).on("click", ".view_file_open", function () {
  1923.         var viewFileOpen = $(this).attr('data-filename');
  1924.         var viewFileOpenPath = $(this).attr('data-filepath');
  1925.         myApp.socketId.send(JSON.stringify({
  1926.             "request": "openFileAtGateway",
  1927.             "jid": myApp.jid,
  1928.             "type": "client",
  1929.             "filePath": viewFileOpenPath,
  1930.             "xmppExeReqKey": myApp.xmppExeReqKey
  1931.         }));
  1932.     })
  1933.  
  1934.     $(document).on("click", "#cloud_transfer", function () {
  1935.         if (myApp.dataChannel.readyState != "open") {
  1936.             myApp.startDataChannel();
  1937.         }
  1938.     })
  1939.  
  1940.  
  1941.     $(document).on("click", ".view_file_download", function () {
  1942.         if ($(".download_operation").length == 0) {
  1943.             downloadDataHtml();
  1944.         }
  1945.         var viewFileOpen = $(this).attr('data-filename');
  1946.         var viewFileOpenPath = $(this).attr('data-filepath');
  1947.         var viewFileSize = $(this).attr('data-filesize');
  1948.         $(".cancel_download").attr('data-filename', viewFileOpen);
  1949.         $(".cancel_download").attr('data-filepath', viewFileOpenPath);
  1950.         $(".cancel_download").attr('data-filesize', viewFileSize);
  1951.         myApp.socketId.send(JSON.stringify({
  1952.             "request": "sendDownloadFile", "action": "start", "fileSize": viewFileSize, "fileName": viewFileOpen.trim(), "filePath": viewFileOpenPath.trim(), "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  1953.         }));
  1954.     })
  1955.     /* View Files code ends */
  1956.  
  1957.  
  1958.     /* Tranfer of file action button */
  1959.  
  1960.     $(document).on("click", "#admin_fileshare", function () {
  1961.         $(".file_transfer_options").show();
  1962.         $(".download_from_via,.download_from_via_files").hide();
  1963.     })
  1964.  
  1965.     $(document).on("click", ".open_transfer", function () {
  1966.         chrome.downloads.open(myApp.deltaId[$(this).attr('data-filename').trim()]);
  1967.     });
  1968.     $(document).on("click", ".file_transfer", function () {
  1969.         var isReceived = $(".file_receive_prompt").find(".transfer_file_send,.transfer_file_class").length;
  1970.         if (isReceived > 0) {
  1971.             $("#features_disp").hide();
  1972.             $(".file_receive_prompt").show();
  1973.         } else {
  1974.             $.fn.showParticipants("participants");
  1975.         }
  1976.     })
  1977.  
  1978.     $(document).on("click", ".one_share", function () {
  1979.         if (myApp.dataChannel.readyState != "open") {
  1980.             myApp.startDataChannel();
  1981.         }
  1982.         if (this.id.split("_share")[0] != "viaadmin") {
  1983.             myApp.sendFileTo = this.id.split("_share")[0] + "@" + myApp.domain;
  1984.             myApp.shareFileWith = this.id.split("_share")[0];
  1985.         }
  1986.  
  1987.     })
  1988.  
  1989.     $(document).on("click", "#transfer_file_cross", function () {
  1990.         $(".file_transfer_options").hide();
  1991.     })
  1992.  
  1993.     $(document).on("click", "#save_transfer", function (event) {
  1994.         myApp.shareFileWith = "viaadmin";
  1995.         myApp.sendFileTo = "viaadmin@" + myApp.domain;
  1996.     })
  1997.  
  1998.     $(document).on("click", ".save_transfer", function (event) {
  1999.         if (myApp.isDownloadFileMode == "yes") {
  2000.             var divText = $(this).parents('div').eq(1).find(".transfer_file_class").text();
  2001.             var fileSendType = $(this).attr('data-sendtype');
  2002.             var fileSendBy = $(this).attr('data-sendby');
  2003.             var fileName = divText.split(":")[1];
  2004.             myApp.isDuplicateDownload = $(this).attr("data-duplicate");
  2005.             $(this).parents('div').eq(1).find(".my_bar_basic").html("");
  2006.             //$(".my_bar_basic").html("");        
  2007.             myApp.socketId.send(JSON.stringify({
  2008.                 "request": "sendTranferFile", "fileSendBy": fileSendBy, "action": "start", "fileSendType": fileSendType, "osType": myApp.osType, "fileName": fileName.trim(), "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2009.             }));
  2010.         } else if (myApp.isDownloadFileMode == "no") {
  2011.             myApp.customNotification("Download in progress.");
  2012.         }
  2013.     });
  2014.  
  2015.     $(document).on("click", ".cancel_download", function () {
  2016.         //$(this).parents('div').eq(2).remove();
  2017.         /*if ($("#file_download_info > div .download_file_class").length == 0) {
  2018.          $.fn.showParticipants("participants");
  2019.          }*/
  2020.         var viewFileOpen = $(this).attr('data-filename');
  2021.         var viewFileOpenPath = $(this).attr('data-filepath');
  2022.         var viewFileSize = $(this).attr('data-filesize');
  2023.         myApp.socketId.send(JSON.stringify({
  2024.             "request": "sendDownloadFile", "action": "stop", "fileSize": viewFileSize, "fileName": viewFileOpen.trim(), "filePath": viewFileOpenPath.trim(), "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2025.         }));
  2026.     });
  2027.     /* Tranfer of file action button */
  2028.  
  2029.     $(document).on("click", ".file_error_cross", function () {
  2030.         $("#media_support_err").hide();
  2031.     })
  2032.  
  2033.     $(document).on("click", ".present_type_cross", function () {
  2034.         $(".prompt_present_screen").hide();
  2035.         stopPresenting();
  2036.     })
  2037.  
  2038.     $(document).on("click", "#mirror_band", function () {
  2039.         $("#detail_grid,#third_party_apps,#touch_pad,.file_receive_prompt").hide();
  2040.         $("#mirror_users").show();
  2041.         $("#mirror_band").hide();
  2042.     })
  2043.  
  2044.     $(document).on("click", ".chat_start", function () {
  2045.         if (myApp.isCollaborationStarted == "Yes") {
  2046.             myApp.isCollaborationStarted = "No";
  2047.             collaborationScreen.stop();
  2048.         }
  2049.         $("#mirror_band").hide();
  2050.         $.fn.startChating(this, "sendMessage");
  2051.     });
  2052.     $(document).on("click", ".open_chat", function () {
  2053.         $.fn.openChat(this);
  2054.     });
  2055.     $(document).on("click", "#login", function () {
  2056.         $.fn.loginOnClick();
  2057.         intervalidofvalidatenetwork = setInterval(networkvalidate, reconnectInterval);
  2058.     });
  2059.  
  2060.     $(document).keypress(function (e) {
  2061.         if (e.which == 13) {
  2062.             if ($("#domain").is(':focus') || $("#username").is(':focus') || $("#db_name").is(':focus') || $("#db_pass").is(':focus') || $("#roomCode").is(':focus')) {
  2063.                 $.fn.loginOnClick();
  2064.                 intervalidofvalidatenetwork = setInterval(networkvalidate, reconnectInterval);
  2065.             }
  2066.             if ($("#mod_pass").focus()) {
  2067.                 $.fn.authenticateModerator();
  2068.             }
  2069.         }
  2070.     });
  2071.  
  2072.     $(document).on("click", "#collaboration,.open_third_party", function () {
  2073.         //var checkDcTimer = myApp.isChromeOs == true ? 2000 : 1500;
  2074.         if (myApp.dataChannel.readyState != "open") {
  2075.             myApp.startDataChannel();
  2076.             myApp.isCollaborationStarted = "Yes";
  2077.             /*setTimeout(function () {
  2078.              console.log("Opened SetTimeOut.");
  2079.              myApp.isCollaborationStarted = "Yes";
  2080.              if (myApp.dataChannel.readyState == "open") {
  2081.              console.log("Opened.");
  2082.              $.fn.collaboration();
  2083.              }
  2084.              }, 2000);*/
  2085.         } else if (myApp.dataChannel.readyState == "open") {
  2086.             $.fn.collaboration();
  2087.         }
  2088.     });
  2089.  
  2090.     $(document).on("keypress", "#msg,#send", function (e) {
  2091.         message_text = $("#msg").val();
  2092.         if ($.trim(message_text).length != 0) {
  2093.             if (event.keyCode == 13) {
  2094.                 xmppChat.sendMessage();
  2095.                 $.fn.clearMessageBox();
  2096.             }
  2097.         } else {
  2098.             if (event.keyCode == 13) {
  2099.                 $.fn.clearMessageBox();
  2100.             }
  2101.         }
  2102.     });
  2103.  
  2104.     $(document).on("click", "#logout", function () {
  2105.         $.fn.logout();
  2106.     });
  2107.  
  2108.     $(document).on("click", "#viewAllUsers", function () {
  2109.         client.getRoster();
  2110.     });
  2111.  
  2112.     $(document).on("click", "#send", function () {
  2113.         message_text = $("#msg").val();
  2114.         $.fn.sendMessage();
  2115.     });
  2116.  
  2117.     $(document).on("click", "#allparticipants", function () {
  2118.         $.fn.showParticipants(this.id);
  2119.     });
  2120.  
  2121.     $(document).on("click", ".participants", function () {
  2122.         $.fn.showParticipants("participants");
  2123.     });
  2124.  
  2125.     $(document).on("click", "#thirdParyApps", function () {
  2126.         $("#features_disp,#detail_grid,#users,#chat_user,#chat_window,#touch_pad,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info,.file_transfer_options").hide();
  2127.         $("#third_party_apps").show();
  2128.         myApp.getThirdPartyApps();
  2129.     })
  2130.     $(document).on("click", ".open_third_party", function () {
  2131.         var data = stringToArrayBuffer(this.id + "~" + myApp.jid + "~fromClient" + "~OpenThirdParty");
  2132.         myApp.socketId.send(JSON.stringify({
  2133.             "request": "openThirdParty", "id": this.id, "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2134.         }));
  2135.         $.fn.collaboration();
  2136.         /*chrome.sockets.tcp.send(myApp.socketId, data, function (resultCode) {
  2137.          //////console.log("Send Third Party Request.");
  2138.          })*/
  2139.     })
  2140.     $(document).on("click", "#crossButton1", function () {
  2141.         $.fn.logout();
  2142.         chrome.app.window.current().close();
  2143.     })
  2144.  
  2145.     $(document).on("click", ".allow_share_cross", function () {
  2146.         if ($('.allow_share_cross').length <= 1) {
  2147.             $(".allow_present_screen").hide();
  2148.         }
  2149.         $(this).closest("div").remove();
  2150.     })
  2151.  
  2152.     $(document).on("click", ".allow_dual_share_cross", function () {
  2153.         if ($('.allow_dual_share_cross').length <= 1) {
  2154.             $(".allow_present_screen").hide();
  2155.         }
  2156.         $(this).closest("div").remove();
  2157.     })
  2158.  
  2159.     $(document).on("click", ".display", function () {
  2160.         var userDisplayId = this.id;
  2161.         var displayImg = $("#" + userDisplayId).find("img").attr("src").split("/");
  2162.         var allowUser = this.id.split("_display")[0] + "@" + myApp.domain;
  2163.         if (myApp.moderatorName != "" && myApp.currentLoginMode != "") {
  2164.             if (myApp.moderatorName == myApp.jid) {
  2165.                 myApp.socketId.send(JSON.stringify({
  2166.                     "request": "grantDisplay", "message": "GrantDisplay", "jid": myApp.jid, "presentReqFrom": allowUser, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2167.                 }));
  2168.             }
  2169.         } else if (myApp.moderatorNames.length > 0) {
  2170.             if (myApp.moderatorNames.indexOf(allowUser) == -1) {
  2171.                 myApp.socketId.send(JSON.stringify({
  2172.                     "request": "grantDisplay", "message": "GrantDisplay", "jid": myApp.jid, "presentReqFrom": allowUser, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2173.                 }));
  2174.             } else {
  2175.                 myApp.customNotification("This user is a moderator. Starting their presentation is not allowed.");
  2176.             }
  2177.         }
  2178.     })
  2179.  
  2180.     $(document).on("click", "#minimizebutton", function () {
  2181.         chrome.app.window.current().minimize();
  2182.     })
  2183.  
  2184.     $(document).on("click", ".features", function () {
  2185.         /*if (!peerConns[myApp.xmppExeReqKey]) {
  2186.          createCollaborationPeerConn();
  2187.          }*/
  2188.  
  2189.         //peerConns[myApp.xmppExeReqKey].createOffer(setLocalPCOffer, errorCallback);
  2190.         if ($(window).height() > 200 && $("#features_disp").is(":visible")) {
  2191.             window.resizeTo(585, 130);
  2192.             $("#features_disp,.always-at-bottom,.file_transfer_options").hide();
  2193.         } else {
  2194.             window.resizeTo(585, 650);
  2195.             $("#features_disp,.always-at-bottom").show();
  2196.             $("#mirror_band,#mirror_users,#touch_pad,#detail_grid,#third_party_apps,#chat_window,#chat_user,#myFooter,.file_receive_prompt,#file_transfer_disp,#view_file_info,#file_download_info,.file_transfer_options,#open_on_via_div").hide();
  2197.         }
  2198.  
  2199.     })
  2200.  
  2201.     $(document).on("click", "#e_examimg,#eexamtext", function () {
  2202.         var role = myApp.moderatorName != "" ? "4" : "9";
  2203.         chrome.windows.create({'url': 'http://' + myApp.domain + '/pexam.php?uname=' + myApp.encodeUsernameForUrl(myApp.loginUserId) + '&role=' + role, 'type': 'popup', 'width': screen.width, 'height': screen.height}, function (window) {
  2204.         });
  2205.     })
  2206.  
  2207.     $(document).on("click", ".new_user", function () {
  2208.         //$(this).css("background", "#707070");
  2209.     })
  2210.  
  2211.     $(document).on("click", "#epoll", function () {
  2212.         chrome.windows.create({'url': 'http://' + myApp.domain + '/polling/index.php?uname=' + myApp.encodeUsernameForUrl(myApp.loginUserId), 'type': 'popup', 'width': 800, 'height': 600}, function (window) {
  2213.         });
  2214.     })
  2215.  
  2216.     $(document).on("click", "#moderator", function () {
  2217.         var modText = $(this).html();
  2218.         $("#mod_pass").val("");
  2219.         if (modText == "Become Moderator") {
  2220.             if (myApp.modPwdReq == 1) {
  2221.                 $(".mod").show();
  2222.                 $("#mod_pass").focus();
  2223.             } else if (myApp.modPwdReq == 0) {
  2224.                 $.fn.sendModeratorReq();
  2225.             }
  2226.         } else if (modText == "Leave Moderation") {
  2227.             $("#mirror_users,#mirror_band").hide();
  2228.             $.fn.sendLeaveModerationReq();
  2229.             $("#moderation_chat").prop("checked", false);
  2230.             $("#mod_chat_disp").hide();
  2231.             myApp.moderatorName = "";
  2232.             $(this).html("Become Moderator");
  2233.             myApp.isMirrorUsers = "No";
  2234.             $("#dnd_toggle").attr('src', 'icons/dnd_dis.png');
  2235.             if (myApp.modToggleDnd == 1) {
  2236.                 if ($("#dnd_toggle").attr("src") == "icons/dnd_ena.png") {
  2237.                     $.fn.disableDnd();
  2238.                 }
  2239.             }
  2240.             $("#dnd_toggle").hide();
  2241.             $(".mod,#mod_error").hide();
  2242.             $("#mod_pass").val("");
  2243.         }
  2244.     })
  2245.     $(document).on("click", "#mod_cancel", function () {
  2246.         $(".mod,#mod_error").hide();
  2247.         $("#mod_pass").val("");
  2248.     })
  2249.  
  2250.     $(document).on("click", "#mod_submit", function () {
  2251.         $.fn.authenticateModerator();
  2252.     })
  2253.  
  2254.     $(document).on("click", "#moderation_chat", function () {
  2255.         if (this.checked == true) {
  2256.             //$("#user_listing,#allparticipants").addClass("inactiveLink");
  2257.             myApp.socketId.send(JSON.stringify({
  2258.                 "request": "manageModChat", "message": "ChatEnabled", "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2259.             }));
  2260.         } else {
  2261.             myApp.socketId.send(JSON.stringify({
  2262.                 "request": "manageModChat", "message": "ChatDisabled", "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2263.             }));
  2264.             //$("#user_listing,#allparticipants").removeClass("inactiveLink");
  2265.         }
  2266.     });
  2267.     $(document).on("click", "#accept_present,#reject_present", function () {
  2268.         $(this).closest("div").remove();
  2269.         if (this.id == "accept_present") {
  2270.             publishPresenting();
  2271.         }
  2272.         $(".allow_present_screen").hide();
  2273.     })
  2274.  
  2275.     $(document).on("click", ".allow_dual_first", function () {
  2276.         //Dual display
  2277.         var presentReqFrom = $(this).attr('data-allowto');
  2278.         myApp.socketId.send(JSON.stringify({
  2279.             "request": "allowDualScreen", "message": "GDAllowedOne", "jid": myApp.jid, "presentReqFrom": presentReqFrom, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2280.         }));
  2281.         $(this).closest("div").remove();
  2282.         if ($('.allow_dual_share_cross').length == 0) {
  2283.             $(".allow_present_screen").hide();
  2284.         } else {
  2285.             $(".allow_dual_share_cross").last().closest("div").show();
  2286.         }
  2287.     })
  2288.  
  2289.     $(document).on("click", ".allow_dual_second", function () {
  2290.         //Dual display
  2291.         var presentReqFrom = $(this).attr('data-allowto');
  2292.         myApp.socketId.send(JSON.stringify({
  2293.             "request": "allowDualScreen", "message": "GDAllowedTwo", "jid": myApp.jid, "presentReqFrom": presentReqFrom, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2294.         }));
  2295.         $(this).closest("div").remove();
  2296.         if ($('.allow_dual_share_cross').length == 0) {
  2297.             $(".allow_present_screen").hide();
  2298.         } else {
  2299.             $(".allow_dual_share_cross").last().closest("div").show();
  2300.         }
  2301.     })
  2302.  
  2303.  
  2304.     $(document).on("click", ".allow_dual_auto_position", function () {
  2305.         //Dual display
  2306.         var presentReqFrom = $(this).attr('data-allowto');
  2307.         myApp.socketId.send(JSON.stringify({
  2308.             "request": "allowDualScreen", "message": "GDAllowedShare", "jid": myApp.jid, "presentReqFrom": presentReqFrom, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2309.         }));
  2310.         $(this).closest("div").remove();
  2311.         if ($('.allow_dual_share_cross').length == 0) {
  2312.             $(".allow_present_screen").hide();
  2313.         } else {
  2314.             $(".allow_dual_share_cross").last().closest("div").show();
  2315.         }
  2316.     })
  2317.  
  2318.     $(document).on("click", ".deny_access_dual", function () {
  2319.         //Dual display
  2320.         //var userDeleteClass = $(this).closest("div").attr("class").split(" ")[0];
  2321.         //displayUserWaiting.splice(displayUserWaiting.indexOf(userDeleteClass), 1);
  2322.         $(this).closest('.allow_dual').remove();
  2323.         var denyUser = $(this).attr('data-denyto');
  2324.         myApp.socketId.send(JSON.stringify({
  2325.             "request": "denyDualPresentRequest", "message": "GDADeny", "jid": myApp.jid, "presentReqFrom": denyUser, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2326.         }));
  2327.         //$("#" + this.id).closest("div").remove();
  2328.         if ($(".allow_dual_share_cross .allow_dual").length == 0) {
  2329.             $(".allow_present_screen").hide();
  2330.         }
  2331.         if ($("#users").is(":visible") == false) {
  2332.             window.resizeTo(585, 145);
  2333.         }
  2334.     })
  2335.  
  2336.     $(document).on("click", ".allow_share_cross", function () {
  2337.         /*displayUserWaiting.push(classNameAllow + "~" + startTime);
  2338.          var elemsArray = displayUserWaiting[i].split("~");*/
  2339.         var userDeleteClass = $(this).closest("div").attr("class").split(" ")[0];
  2340.         displayUserWaiting.splice(displayUserWaiting.indexOf(userDeleteClass), 1);
  2341.         if ($('.allow_share_cross').length == 0) {
  2342.             $(".allow_present_screen").hide();
  2343.         }
  2344.         $(this).closest("div").remove();
  2345.     })
  2346.  
  2347.     $(document).on("click", ".allow_full_screen", function () {
  2348.         var presentReqFrom = $(this).closest("div").attr("class").split("_allow");
  2349.         var userDeleteClass = $(this).closest("div").attr("class").split(" ")[0];
  2350.         displayUserWaiting.splice(displayUserWaiting.indexOf(userDeleteClass), 1);
  2351.         //stopPresenting();
  2352.         myApp.socketId.send(JSON.stringify({
  2353.             "request": "allowFullScreen", "message": "GDAllowedOne", "jid": myApp.jid, "presentReqFrom": presentReqFrom[0] + "@" + myApp.domain, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2354.         }));
  2355.         //////console.log("IpAddress", myApp.domain);
  2356.         /*$(".allow").remove();
  2357.          $(".allow_present_screen").empty();
  2358.          $(".allow_present_screen").hide();
  2359.          */
  2360.         $(this).closest("div").remove();
  2361.         if ($('.allow_share_cross').length == 0) {
  2362.             $(".allow_present_screen").hide();
  2363.         } else {
  2364.             $(".allow_share_cross").last().closest("div").show();
  2365.         }
  2366.     })
  2367.  
  2368.     $(document).on("click", ".mirror_full_screen", function () {
  2369.         var uniqueClassName = $(this).attr('data-from');
  2370.         stopPresenting();
  2371.         myApp.socketId.send(JSON.stringify({
  2372.             "request": "allowFullScreen", "message": "GDAllowedOne", "jid": myApp.jid,
  2373.             "presentReqFrom": myApp.mirrorUsers[uniqueClassName].fullName,
  2374.             "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2375.         }));
  2376.         $("." + myApp.mirrorUsers[uniqueClassName].time).remove();
  2377.         delete myApp.mirrorUsers[uniqueClassName];
  2378.         if ($('.allow_share_cross').length == 0) {
  2379.             $(".allow_present_screen").hide();
  2380.         } else {
  2381.             $(".allow_share_cross").last().closest("div").show();
  2382.         }
  2383.     })
  2384.  
  2385.  
  2386.     $(document).on("click", ".allow_auto_position", function () {
  2387.         var presentReqFrom = $(this).closest("div").attr("class").split("_allow");
  2388.         var userDeleteClass = $(this).closest("div").attr("class").split(" ")[0];
  2389.         displayUserWaiting.splice(displayUserWaiting.indexOf(userDeleteClass), 1);
  2390.         myApp.socketId.send(JSON.stringify({
  2391.             "request": "allowDualAutoPosition", "message": "GDAllowedShare", "jid": myApp.jid, "presentReqFrom": presentReqFrom[0] + "@" + myApp.domain, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2392.         }));
  2393.         $(this).closest("div").remove();
  2394.         if ($('.allow_share_cross').length == 0) {
  2395.             $(".allow_present_screen").hide();
  2396.         } else {
  2397.             $(".allow_share_cross").last().closest("div").show();
  2398.         }
  2399.     })
  2400.  
  2401.     $(document).on("click", ".mirror_auto_position", function () {
  2402.         var uniqueClassName = $(this).attr('data-from');
  2403.         myApp.socketId.send(JSON.stringify({
  2404.             "request": "allowAutoPosition", "message": "GDAllowedShare", "jid": myApp.jid,
  2405.             "presentReqFrom": myApp.mirrorUsers[uniqueClassName].fullName,
  2406.             "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2407.         }));
  2408.         $("." + myApp.mirrorUsers[uniqueClassName].time).remove();
  2409.         delete myApp.mirrorUsers[uniqueClassName];
  2410.         if ($('.allow_share_cross').length == 0) {
  2411.             $(".allow_present_screen").hide();
  2412.         } else {
  2413.             $(".allow_share_cross").last().closest("div").show();
  2414.         }
  2415.     })
  2416.  
  2417.     $(document).on("click", ".deny_access", function () {
  2418.         var userDeleteClass = $(this).closest("div").attr("class").split(" ")[0];
  2419.         displayUserWaiting.splice(displayUserWaiting.indexOf(userDeleteClass), 1);
  2420.         var denyUser = this.id.split("_deny")[0] + "@" + myApp.domain;
  2421.         myApp.socketId.send(JSON.stringify({
  2422.             "request": "denyPresentRequest", "message": "GDADeny", "jid": myApp.jid, "presentReqFrom": denyUser, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2423.         }));
  2424.         $("#" + this.id).closest("div").remove();
  2425.         if ($(".allow_present_screen .allow").length == 0) {
  2426.             $(".allow_present_screen").hide();
  2427.         }
  2428.         if ($("#users").is(":visible") == false) {
  2429.             window.resizeTo(585, 145);
  2430.         }
  2431.     })
  2432.  
  2433.     $(document).on("click", ".deny_mirror", function () {
  2434.         var uniqueClassName = $(this).attr('data-from');
  2435.         myApp.socketId.send(JSON.stringify({
  2436.             "request": "denyPresentRequest", "message": "GDADeny", "jid": myApp.jid,
  2437.             "presentReqFrom": myApp.mirrorUsers[uniqueClassName].fullName, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2438.         }));
  2439.         $("." + myApp.mirrorUsers[uniqueClassName].time).remove();
  2440.         delete myApp.mirrorUsers[uniqueClassName];
  2441.         if ($(".allow_present_screen .allow").length == 0) {
  2442.             $(".allow_present_screen").hide();
  2443.         }
  2444.         if ($("#users").is(":visible") == false) {
  2445.             window.resizeTo(585, 145);
  2446.         }
  2447.     })
  2448.  
  2449.  
  2450.     $(document).on("click", "#dnd_toggle", function () {
  2451.         var imgaePath = this.src;
  2452.         var pathArray = this.src.split("/");
  2453.         var imageName = pathArray[pathArray.length - 1];
  2454.         if (imageName == "dnd_dis.png") {
  2455.             $.fn.enableDnd();
  2456.         } else {
  2457.             $.fn.disableDnd();
  2458.         }
  2459.  
  2460.     })
  2461.  
  2462.     $(document).on("click", "#btnpause", function (e) {
  2463.         if (pauseFlag === false) {
  2464.             pauseFlag = true;
  2465.             myApp.socketId.send(JSON.stringify({
  2466.                 "boxPeerId": peerId,
  2467.                 "request": "makePause",
  2468.                 "type": "client"
  2469.             }));
  2470.             //////console.log("pause clicked");
  2471.             $("#btnpause").attr('src', 'icons/play25.png');
  2472.         } else {
  2473.             myApp.socketId.send(JSON.stringify({
  2474.                 "boxPeerId": peerId,
  2475.                 "request": "makePlay",
  2476.                 "type": "client"
  2477.             }));
  2478.             //////console.log("resume clicked", shareStream);
  2479.             $("#btnpause").attr('src', 'icons/pause25.png');
  2480.             pauseFlag = false;
  2481.         }
  2482.     });
  2483.     $(document).on("click", "#btnfullscreen", function (e) {
  2484.         myApp.socketId.send(JSON.stringify({
  2485.             "boxPeerId": peerId,
  2486.             "request": "makeFullScreen",
  2487.             "type": "client"
  2488.         }));
  2489.         $("#btnpause").attr('src', 'icons/pause25.png');
  2490.         ////// dnd need to be added////
  2491.  
  2492.     });
  2493.     presentmeimg
  2494.     var isAskingPermission = "No";
  2495.     $(document).on("click", "#presentmeimg,#presentmetext", function () {
  2496.         if ($('#presentmeimg').attr("src") == "icons/present_waiting.png") {
  2497.             $(".prompt_present_screen").hide();
  2498.             stopPresenting();
  2499.         } else {
  2500.             $(".file_transfer_options").hide();
  2501.             if (myApp.currentLoginMode != "") {
  2502.                 if (myApp.currentLoginMode == 3) {
  2503.                     if (myApp.moderatorName != "") {
  2504.                         if (myApp.moderatorName != myApp.jid) {
  2505.                             $("#presentmeimg").attr("src", "icons/present_waiting.png");
  2506.                             if (isPresentor == false) {
  2507.                                 $('.present_type_radio').prop('checked', false);
  2508.                                 isAskingPermission = "Yes";
  2509.                                 $(".prompt_present_screen").show();
  2510.                                 window.resizeTo(585, 650);
  2511.                                 $("#chat_window,#chat_user,#features_disp,#third_party_apps,#touch_pad,#myfooter,.file_receive_prompt,#file_transfer_disp").hide();
  2512.                                 $("#users,#detail_grid,.always-at-bottom").show();
  2513.                             } else if (isPresentor == true) {
  2514.                                 publishPresenting();
  2515.                             }
  2516.  
  2517.                         } else {
  2518.                             publishPresenting();
  2519.                         }
  2520.                     } else {
  2521.                         publishPresenting();
  2522.                     }
  2523.  
  2524.                 } else if (myApp.currentLoginMode == 4 || myApp.currentLoginMode == 9) {
  2525.                     console.log(myApp.moderatorNames);
  2526.                     if (myApp.moderatorNames.indexOf(myApp.jid) != -1) {
  2527.                         publishPresenting();
  2528.                     } else {
  2529.                         $("#presentmeimg").attr("src", "icons/present_waiting.png");
  2530.                         if (isPresentor == false) {
  2531.                             $('.present_type_radio').prop('checked', false);
  2532.                             isAskingPermission = "Yes";
  2533.                             $(".prompt_present_screen").show();
  2534.                             window.resizeTo(585, 650);
  2535.                             $("#chat_window,#chat_user,#features_disp,#third_party_apps,#touch_pad,#myfooter,.file_receive_prompt,#file_transfer_disp").hide();
  2536.                             $("#users,#detail_grid,.always-at-bottom").show();
  2537.                         } else if (isPresentor == true) {
  2538.                             publishPresenting();
  2539.                         }
  2540.                     }
  2541.                 }
  2542.  
  2543.             } else {
  2544.                 publishPresenting();
  2545.             }
  2546.         }
  2547.     });
  2548.     document.querySelector('#minwowpng').addEventListener('click', function (e) {
  2549.         //////console.log("minimize app");
  2550.         var window = chrome.app.window.current();
  2551.         window.minimize();
  2552.     });
  2553.     $("#domain").on("input", function () {
  2554.         $(this).removeClass("text_error");
  2555.         //////console.log(this.value);
  2556.         if (this.value != "") {
  2557.             if (this.value in myApp.chromeIpAddressKeyValue) {
  2558.                 checkUiMode(myApp.chromeIpAddressKeyValue[this.value].logintype);
  2559.             } else {
  2560.                 $(".db,.rc").hide();
  2561.                 $(".basic").show();
  2562.                 $("#loginBtnTd").css({"padding-top": "90px"});
  2563.                 $("#myfooter").css({"padding-top": "30px"});
  2564.             }
  2565.         }
  2566.     });
  2567.     $("#username").on("input", function () {
  2568.         $(this).removeClass("text_error");
  2569.     });
  2570.     $("#db_name").on("input", function () {
  2571.         $(this).removeClass("text_error");
  2572.     });
  2573.     $("#db_pass").on("input", function () {
  2574.         $(this).removeClass("text_error");
  2575.     });
  2576.     $("#roomCode").on("input", function () {
  2577.         $(this).removeClass("text_error");
  2578.     });
  2579.     $(document).on("click", "#files_transfer,.files_transfer", function () {
  2580.         $(".file_transfer_options").show();
  2581.         $("#media_support_err").hide();
  2582.         $(".download_from_via,.download_from_via_files").show();
  2583.     })
  2584.     $(document).on("click", ".delete_tranfer", function () {
  2585.         var deleteSendTo = $(this).parents().eq("2").find(".transfer_file_send").attr("data-sendto");
  2586.         var deleteFile = $(this).parents().eq("2").find(".transfer_file_send").text().split(":")[1].trim();
  2587.         $(this).parents().eq("2").remove();
  2588.         if (myApp.fileTransferQue[0].name.trim() == deleteFile) {
  2589.             myApp.stopFileTransfer = true;
  2590.             myApp.sendFileTo = "";
  2591.             myApp.socketId.send(JSON.stringify({
  2592.                 "request": "deleteTransferFile", "fileName": deleteFile, "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2593.             }));
  2594.             for (var i = 0; i < myApp.fileTransferQue.length; i++) {
  2595.                 if (myApp.fileTransferQue[i].name.trim() == deleteFile) {
  2596.                     delete myApp.filesTransferNameWithUser[deleteSendTo + "~" + deleteFile];
  2597.                     if (i != 0) {
  2598.                         if (i == 1) {
  2599.                             myApp.fileTransferQue.splice(1, 1);
  2600.                         } else {
  2601.                             myApp.fileTransferQue.splice((i - 1), 1);
  2602.                         }
  2603.                     } else {
  2604.                         myApp.fileTransferQue.shift();
  2605.                     }
  2606.                     setTimeout(function () {
  2607.                         myApp.stopFileTransfer = false;
  2608.                         //myApp.fileTransferQue.shift();
  2609.                         myApp.shareFileWith = "";
  2610.                         if (myApp.fileTransferQue.length > 0) {
  2611.                             var reader = new window.FileReader();
  2612.                             reader.readAsBinaryString(myApp.fileTransferQue[0]);
  2613.                             reader.onload = onReadAsDataURL;
  2614.                         } else {
  2615.                             myApp.isTransferMode = "yes";
  2616.                             $(".file_receive_prompt,.always-at-bottom").hide();
  2617.                             window.resizeTo(585, 130);
  2618.                         }
  2619.                     }, 500);
  2620.                 }
  2621.  
  2622.             }
  2623.  
  2624.         } else {
  2625.             //console.log("Waiting");
  2626.             for (var i = 0; i < myApp.fileTransferQue.length; i++) {
  2627.                 // console.log(myApp.fileTransferQue);
  2628.                 //console.log(myApp.fileTransferQue[i].name.trim(), deleteFile);
  2629.                 if (myApp.fileTransferQue[i].name.trim() == deleteFile) {
  2630.                     if (i != 0) {
  2631.                         if (i == 1) {
  2632.                             myApp.fileTransferQue.splice(1, 1);
  2633.                         } else {
  2634.                             myApp.fileTransferQue.splice((i - 1), 1);
  2635.                         }
  2636.  
  2637.                     } else {
  2638.                         myApp.isTransferMode = "yes";
  2639.                         myApp.fileTransferQue.shift();
  2640.                     }
  2641.  
  2642.                 }
  2643.                 //console.log(myApp.fileTransferQue);
  2644.             }
  2645.         }
  2646.         //$("#file_transfer_disp").hide();
  2647.         //$.fn.showParticipants("participants");
  2648.  
  2649.  
  2650.     })
  2651.  
  2652.     $(document).on("click", ".delete_openvia", function () {
  2653.         var deleteFile = $(this).parents().eq("2").find(".openvia_file_class").text().split(":")[1].trim();
  2654.         $(this).parents().eq("2").remove();
  2655.         myApp.stopFileTransfer = true;
  2656.         myApp.socketId.send(JSON.stringify({
  2657.             "request": "deleteTransferFile", "fileName": deleteFile, "jid": myApp.jid, "type": "client", "xmppExeReqKey": myApp.xmppExeReqKey
  2658.         }));
  2659.         $("#file_transfer_disp").hide();
  2660.         myApp.sendFileOpenOnVia = true;
  2661.         $.fn.showParticipants("participants");
  2662.         setTimeout(function () {
  2663.             myApp.stopFileTransfer = false;
  2664.         }, 250);
  2665.     })
  2666.  
  2667.     // stop the connection on button click
  2668.     function disconnect() {
  2669.         //////console.log("disconnect()");
  2670.         if (myApp.socketId != null) {
  2671.             myApp.socketId.send(JSON.stringify({
  2672.                 "boxPeerId": peerId,
  2673.                 "request": "byeUser",
  2674.                 "gatewayUniqueId": myApp.uniqueGatewayId,
  2675.                 "type": "client"
  2676.             }));
  2677.         }
  2678.         stop();
  2679.         shareStream = null;
  2680.         videoStream = null;
  2681.         pendingPresentId = null;
  2682.         rtcInfo = {};
  2683.         peerId = null;
  2684.         //if (myApp.socketId != null) {
  2685.         //    myApp.socketId.close();
  2686.         //    myApp.socketId = null;
  2687.         // }
  2688.         ///////////////////////////////////
  2689.         // myApp.socketId = null;
  2690.  
  2691.     }
  2692.  
  2693.     function stopPresenting() {
  2694.         if (shareStream) {
  2695.             shareStream.getTracks().forEach(function (track) {
  2696.                 track.stop();
  2697.             });
  2698.         }
  2699.  
  2700.         isPresentor = false;
  2701.         joinReceived = false;
  2702.         pauseclickflag = false;
  2703.         if (myApp.currentLoginMode == "") {
  2704.             var isModSending = "Yes";
  2705.         } else if (myApp.currentLoginMode == 3) {
  2706.             var isModSending = myApp.moderatorName == myApp.jid ? "Yes" : "No";
  2707.         } else if (myApp.currentLoginMode == 4 || myApp.currentLoginMode == 9) {
  2708.             var isModSending = myApp.moderatorNames.indexOf(myApp.jid) != -1 ? "Yes" : "No";
  2709.         }
  2710.  
  2711.         ////////////////////////todo code for Stop Presenting////////////////////////////////////
  2712.         // turn off audio \ video on attendee
  2713.         if (myApp.socketId != null) {
  2714.             myApp.socketId.send(JSON.stringify({
  2715.                 "boxPeerId": peerId,
  2716.                 "request": "stopSharing",
  2717.                 "gatewayUniqueId": myApp.uniqueGatewayId,
  2718.                 "type": "client",
  2719.                 "jid": myApp.jid,
  2720.                 "isModerator": isModSending,
  2721.                 "xmppExeReqKey": myApp.xmppExeReqKey
  2722.             }));
  2723.             if (myApp.modToggleDnd == 1) {
  2724.                 if ($("#dnd_toggle").attr("src") == "icons/dnd_ena.png") {
  2725.                     $.fn.disableDnd();
  2726.                 }
  2727.             }
  2728.         }
  2729.         stop();
  2730.         //document.getElementById("strMsg-label").innerHTML = "Sharing Stopped";
  2731.         //document.getElementById("btnStartShare").innerHTML="Present";
  2732.         document.getElementById("btnfullscreen").style.display = "none";
  2733.         //document.getElementById("btnpause").style.display="none";
  2734.         setupUILogin(2);
  2735.     }
  2736. //onsuccess of desktop sharing
  2737.     function publishPresenting() {
  2738.         if (isPresentor == false) {
  2739.             isPresentor = true;
  2740.             joinReceived = false;
  2741.             myApp.socketId.send(JSON.stringify({
  2742.                 "request": "publish",
  2743.                 "boxId": myApp.domain,
  2744.                 "gatewayUniqueId": myApp.uniqueGatewayId,
  2745.                 "username": myApp.loginUserId,
  2746.                 "clientReqKey": myApp.clientReqKey,
  2747.                 "type": "client"
  2748.             }));
  2749.         } else {
  2750.             stopPresenting();
  2751.         }
  2752.     }
  2753.  
  2754.     function onAccessApproved(id) {
  2755.         if (myApp.currentLoginMode == "") {
  2756.             var isModSending = "Yes";
  2757.         } else if (myApp.currentLoginMode == 3) {
  2758.             var isModSending = myApp.moderatorName == myApp.jid ? "Yes" : "No";
  2759.         } else if (myApp.currentLoginMode == 4 || myApp.currentLoginMode == 9) {
  2760.             var isModSending = myApp.moderatorNames.indexOf(myApp.jid) != -1 ? "Yes" : "No";
  2761.         }
  2762.         isPresentor = true;
  2763.         if (!id) {
  2764.             isPresentor = false;
  2765.             joinReceived = false;
  2766.             //window.resizeTo(585, 145);
  2767.             $.fn.screenAfterPresentation();
  2768.             ////console.log("Anuj Bhargava");
  2769.             // send message on cancel screen sharing
  2770.             myApp.socketId.send(JSON.stringify({
  2771.                 "boxPeerId": peerId,
  2772.                 "request": "stopPresentStatus",
  2773.                 "isModerator": isModSending,
  2774.                 "jid": myApp.jid,
  2775.                 "type": "client",
  2776.                 "xmppExeReqKey": myApp.xmppExeReqKey
  2777.             }));
  2778.             return;
  2779.         }
  2780.         //sending actual window
  2781.  
  2782.         $("#btnpause").attr('src', 'icons/pause25.png');
  2783.         $("#btnpause").show();
  2784.         var numDispRun = myApp.totalDisplayRunning == 0 ? 1 : myApp.totalDisplayRunning;
  2785.         myApp.socketId.send(JSON.stringify({
  2786.             "boxPeerId": peerId,
  2787.             "request": "showScreen",
  2788.             "username": myApp.loginUserId,
  2789.             "extwidth": screen.width,
  2790.             "extheight": screen.height,
  2791.             "type": "client",
  2792.             "jid": myApp.jid,
  2793.             "isModerator": isModSending,
  2794.             "numDispRun": numDispRun,
  2795.             "xmppExeReqKey": myApp.xmppExeReqKey,
  2796.             "clientReqKey": myApp.clientReqKey,
  2797.         }));
  2798.         navigator.webkitGetUserMedia({
  2799.             audio: {
  2800.                 mandatory: {
  2801.                     chromeMediaSource: "system",
  2802.                     chromeMediaSourceId: id,
  2803.                 }
  2804.             },
  2805.             video: {
  2806.                 mandatory: {
  2807.                     chromeMediaSource: "desktop",
  2808.                     chromeMediaSourceId: id,
  2809.                     maxWidth: screen.width,
  2810.                     maxHeight: screen.height,
  2811.                     minFrameRate: 5,
  2812.                     maxFrameRate: 20
  2813.                 }
  2814.             }
  2815.         }, gotShareStream, errorCallback);
  2816.     }
  2817.  
  2818.  
  2819. ////////////////////////////////////////////////////////////////////shikha////////////////////////////////////////////
  2820.     function gotShareStream(stream) {
  2821.         //console.log(stream);
  2822.         shareStream = stream;
  2823.         seltabid = null;
  2824.         share();
  2825.         $.fn.screenAfterPresentation();
  2826.         //window.resizeTo(585, 145);
  2827.         setupUILogin(3);
  2828.         if ("WebSocket" in window) {
  2829.             myApp.socketId.onopen = function () {
  2830.                 //////console.log("WebSocket connection open");
  2831.             };
  2832.         } else {
  2833.             //////console.log("No web socket connection");
  2834.         }
  2835.         if (seltabid == null)
  2836.         {
  2837.             chrome.tabs.query({active: true, highlighted: true}, function (tab) {
  2838.                 //////console.log("captureinfo",tab.length,tab);
  2839.                 if (tab.length > 0) {
  2840.                     seltabid = tab[0].id;
  2841.                     //////console.log("seltabid", seltabid);
  2842.                     chrome.tabs.update(seltabid, {muted: true}, function (seltab) {
  2843.                         //////console.log("captureinfo", seltab);
  2844.                     });
  2845.                 }
  2846.             });
  2847.         }
  2848.         stream.oninactive = function () {
  2849.             //////console.log("new code to catch stop event");
  2850.             stopPresenting();
  2851.         };
  2852.     }
  2853.  
  2854.     function share() {
  2855.         if (shareStream) {
  2856.  
  2857.             if (!rtcInfo[peerId]) {
  2858.                 createPeerConnection(peerId);
  2859.             }
  2860.             //////console.log('function share Adding local stream...');
  2861.             rtcInfo[peerId].addStream(shareStream);
  2862.             shareFlowing = true;
  2863.             //////console.log("peer " + peerId + " share ", shareStream);
  2864.             rtcInfo[peerId].createOffer(setLocalDescAndSendMessagePCOffer, errorCallback, mediaConstraints);
  2865.             //startVideo();
  2866.  
  2867.         } else {
  2868.             //////console.log("Local share stream not running.");
  2869.         }
  2870.     }
  2871.  
  2872.  
  2873.     function createPeerConnection(pcID) {
  2874.         //////console.log("Creating peer connection");
  2875.         RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
  2876.         var pc_config = {
  2877.             "iceServers": myApp.pcConfig
  2878.         };
  2879.         try {
  2880.             rtcInfo[pcID] = new RTCPeerConnection(pc_config);
  2881.             //////console.log(pc_config);
  2882.         } catch (e) {
  2883.             //////console.log("Failed to create PeerConnection, exception: " + e.message);
  2884.         }
  2885.  
  2886.         // send any ice candidates to the other peer
  2887.         rtcInfo[pcID].onicecandidate = function (evt) {
  2888.             if (evt.candidate) {
  2889.                 //////console.log('Sending ICE candidate...');
  2890.                 myApp.socketId.send(JSON.stringify({
  2891.                     "boxPeerId": peerId,
  2892.                     "request": "iceCandidate",
  2893.                     "candidate": evt.candidate,
  2894.                     "type": "client"
  2895.                 }));
  2896.             } else {
  2897.                 //////console.log("End of candidates.");
  2898.             }
  2899.         };
  2900.         //////console.log('Adding local stream...');
  2901.         if (!isPresentor) {
  2902.             rtcInfo[pcID].addStream(videoStream);
  2903.         }
  2904.  
  2905.         rtcInfo[pcID].addEventListener("addstream", onRemoteStreamAdded, false);
  2906.         rtcInfo[pcID].addEventListener("removestream", onRemoteStreamRemoved, false)
  2907.  
  2908.     }
  2909.     function onRemoteStreamAdded(event) {
  2910.         //////console.log("Added remote stream");
  2911.         if (!shareVideoActive && !isPresentor) {
  2912.             shareVideo.src = window.URL.createObjectURL(event.stream);
  2913.             shareVideo.play();
  2914.             shareVideoActive = true;
  2915.             return;
  2916.         }
  2917.     }
  2918.  
  2919.     function onRemoteStreamRemoved(event) {
  2920.         //////console.log("Remove remote stream");
  2921.     }
  2922.  
  2923.  
  2924. //login to ui of screen share ///////////////////////////////////////////////////////////////////////////
  2925.     function setupUILogin(caller) {
  2926.         if (caller == 1) { // called in case of login is success.
  2927.             //////console.log("coming to set start");
  2928.             document.getElementById("present-div").style.display = "block";
  2929.             document.getElementById("presentmetext").innerHTML = "Present";
  2930.             window.resizeTo(585, 145);
  2931.             document.getElementById("boxAddress").setAttribute("class", "server-box-before");
  2932.             document.getElementById("usernickname").setAttribute("class", "server-box-before");
  2933.             document.getElementById("roomCode").setAttribute("class", "server-box-before");
  2934.         } else if (caller == 2) {
  2935.             //////console.log("coming to set stop");
  2936.             document.getElementById("presentmeimg").src = "icons/PRESENT-OFF.png";
  2937.             document.getElementById("presentmetext").innerHTML = "Present";
  2938.             $("#dnd_toggle").hide();
  2939.             //////////////////b13//////////////////////////
  2940.             document.getElementById("btnfullscreen").style.display = "none";
  2941.             //window.resizeTo(585,86);
  2942.         } else if (caller == 3) {
  2943.             document.getElementById("presentmetext").innerHTML = "Stop Presenting";
  2944.             document.getElementById("presentmeimg").src = "icons/PRESENT-ON.png";
  2945.         } else if (caller == 4) { // on socket error.          
  2946.             $.fn.reboot();
  2947.             //window.resizeTo(397, 450);
  2948.             document.getElementById("outer-div").style.display = "block";
  2949.             document.getElementById("myfooter").style.display = "block";
  2950.             //document.getElementById("present-div").style.display = "none";
  2951.         }
  2952.  
  2953.     }
  2954.  
  2955. //////////////////////////////////////Stop screen shring and reinitialize all elements/////////////////////////////////////
  2956.  
  2957.     function stop() {
  2958.         if (shareStream) {
  2959.             var track = shareStream.getTracks()[0];
  2960.             track.stop();
  2961.             shareStream = null;
  2962.         }
  2963.  
  2964.         if (rtcInfo[peerId] != null) {
  2965.             //////console.log("coming to close connection");
  2966.             rtcInfo[peerId].close();
  2967.             rtcInfo[peerId] = null;
  2968.         }
  2969.  
  2970.         shareFlowing = false;
  2971.         videoFlowing = false;
  2972.         isPresentor = false;
  2973.         shareVideoActive = false;
  2974.         remoteVideoActive = false;
  2975.         joinReceived = false;
  2976.         document.getElementById("btnpause").style.display = "none";
  2977.         pauseclickflag = false;
  2978.         if (seltabid != null) {
  2979.             //////console.log("seltabid", seltabid);
  2980.             chrome.tabs.update(seltabid, {muted: false}, function (seltab) {
  2981.                 //////console.log("captureinfo", seltab);
  2982.             });
  2983.         }
  2984.     }
  2985.  
  2986.     function downloadDataHtml() {
  2987.         var htmlData = '<div class="view_file_bar" style="background-color: #707070; height: 25px; margin-right: 1px;margin-top: 1px; margin-bottom: 10px;color: #FFFFFF; text-align: center; padding-top: 10px; font-size: 13px;">VIA Cloud</div>';
  2988.         htmlData += '<div style="padding-top: 5px; margin-left: 5px;margin-top: 5px;padding-bottom: 10px;" class="download_file_class"></div>';
  2989.         htmlData += '<div style="margin-left: 5px;" class="basic_download">0%</div>';
  2990.         htmlData += '<div style="margin-left: 5px;" class="color_download"></div>';
  2991.         htmlData += '<div class="download_operation">&nbsp;&nbsp; &nbsp;&nbsp;<input type="button" style="width:75px; height:30px; vertical-align: bottom; margin-top:5px; " class="logout cancel_download" value="cancel"/></div>';
  2992.         htmlData += '<div style="margin-top: 15px;padding-bottom: 10px;margin-left: 5px;" class="transfer_length">Total Size: <span class="total_download_length"></span> MB <span style="padding-right: 180px;" >&nbsp;</span> Current Size: <span class="remaining_download_length"></span></div>';
  2993.         $("#file_download_info").append(htmlData);
  2994.     }
  2995.  
  2996.  
  2997.     function showErrorState(calledfrom) {
  2998.         if (calledfrom == 1 && networkErrorCounter == 0) {
  2999.             networkErrorCounter = 1;
  3000.             myNotifications("Login unsuccessful. Unable to reach chrome at this address");
  3001.             //document.getElementById("strMsg-label").innerHTML = "Network error occurred, please try after later.";
  3002.         }
  3003.         $.fn.reboot();
  3004.     }
  3005.  
  3006.     //////////////////////////////////////TODO/////////////////////////////////////
  3007.     // Chrome can do share and video using one PeerConnection .
  3008.     var bandwidth = {
  3009.         screen: 512, // 300kbits minimum
  3010.         audio: 80, // 50kbits  minimum
  3011.         video: 1500   // 256kbits (both min-max)
  3012.     };
  3013.     //////////////////////////////////////TODO/////////////////////////////////////
  3014.     // Chrome can do share and video using one PeerConnection .
  3015.     function setLocalDescAndSendMessagePCOffer(sessionDescription) {
  3016.         //sessionDescription.sdp = setBandwidth(sessionDescription.sdp);
  3017.         sessionDescription.sdp = BandwidthHandler.setApplicationSpecificBandwidth(sessionDescription.sdp, bandwidth, shareFlowing);
  3018.         sessionDescription.sdp = BandwidthHandler.setVideoBitrates(sessionDescription.sdp, {min: bandwidth.video, max: bandwidth.video});
  3019.         sessionDescription.sdp = BandwidthHandler.setOpusAttributes(sessionDescription.sdp, {
  3020.             'stereo': 0, // to disable stereo (to force mono audio)
  3021.             'sprop-stereo': 1,
  3022.             'maxaveragebitrate': 128 * 1024 * 8, // 500 kbits
  3023.             'maxplaybackrate': 128 * 1024 * 8, // 500 kbits
  3024.             'cbr': 1, // disable cbr
  3025.             'useinbandfec': 1, // use inband fec
  3026.             'usedtx': 1, // use dtx
  3027.             'maxptime': 3
  3028.         });
  3029.         //sessionDescription.sdp = BandwidthHandler.setOpusAttributes(sessionDescription.sdp);
  3030.         // //console.log("peer " + peerId + " offrsdp ", sessionDescription);
  3031.         rtcInfo[peerId].setLocalDescription(sessionDescription);
  3032.         //////console.log("Sending: SDP");
  3033.         //////console.log(sessionDescription);
  3034.         //////console.log("peer " + peerId + " offrsdp ", sessionDescription);
  3035.         myApp.socketId.send(JSON.stringify({
  3036.             "boxPeerId": peerId,
  3037.             "request": "offer",
  3038.             "peerDescription": sessionDescription,
  3039.             "type": "client"
  3040.         }));
  3041.     }
  3042.  
  3043.     function roomnotavilable() {
  3044.         $("#login").html("Login");
  3045.         if (pendingPresentId != null) {
  3046.             chrome.desktopCapture.cancelChooseDesktopMedia(pendingPresentId);
  3047.         }
  3048.         disconnect();
  3049.         document.getElementById("login").innerHTML = 'Login';
  3050.         document.getElementById("username").disabled = false;
  3051.         document.getElementById("domain").disabled = false;
  3052.     }
  3053.  
  3054.     function errorCallback(error) {
  3055.         //console.error('An error occurred: [CODE ' + error + ']');
  3056.         return;
  3057.     }
  3058.  
  3059.     function showMirroringTimer(counter, mirrorIpAddr) {
  3060.         var timerClass = myApp.mirrorUsers[mirrorIpAddr].time + "_timer";
  3061.         var mainClass = myApp.mirrorUsers[mirrorIpAddr].time;
  3062.         var timer = setInterval(function () {
  3063.             $("." + timerClass).text(counter);
  3064.             if (counter == 1) {
  3065.                 delete myApp.mirrorUsers[mirrorIpAddr];
  3066.                 $("." + mainClass).remove();
  3067.                 if ($(".allow_present_screen .allow").length == 0) {
  3068.                     $(".allow_present_screen").hide();
  3069.                 }
  3070.                 clearInterval(timer);
  3071.             }
  3072.             counter--;
  3073.         }, 1000);
  3074.     }
  3075.  
  3076. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement