'use strict'; //open link function myhref(web) { let corWeb; let index = web.indexOf(','); if (index !== -1) { corWeb = web.slice(0, index); } else { corWeb = web; } let tab; let https = corWeb.startsWith('https'); let http = corWeb.startsWith('http'); let HTTP = corWeb.startsWith('HTTP'); let HTTPS = corWeb.startsWith('HTTPS'); let ftp = corWeb.startsWith('ftp'); let FTP = corWeb.startsWith('FTP'); let sftp = corWeb.startsWith('sftp'); let SFTP = corWeb.startsWith('SFTP'); let tel = corWeb.startsWith('tel'); let TEL = corWeb.startsWith('TEL'); let mailto = corWeb.startsWith('mailto'); let MAILTO = corWeb.startsWith('MAILTO'); if ( https === false && http === false && HTTP === false && HTTPS === false && ftp === false && FTP === false && sftp === false && SFTP === false && tel === false && TEL === false && mailto === false && MAILTO === false ) { corWeb = 'https://' + corWeb; } if (web.slice(-1) === '1' || web.slice(-1) === '2') { tab = web.slice(-1); } else { tab = web.slice(-2); } if (tel || TEL) { openSameWindow(corWeb); } else if (mailto || MAILTO) { openMailTo(corWeb); } else { if (parseInt(tab) === 2) { openNewTab(corWeb); } else { openSameWindow(corWeb); } } } const openSameWindow = (web) => { window.location.href = web; }; const openNewTab = (web) => { window.open(web, '_blank'); }; const openMailTo = (web) => { window.open(web, '_top'); }; //get cookie function function getCookie(cname) { var name = cname + '='; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ''; } //add svgIcon class to every svg tag function setSVGclass() { let svgs = document.getElementsByTagName('svg'); for (let x = 0; x < svgs.length; x++) { svgs[x].classList.add('svgIcon'); } } //give the length og an object Object.size = function (obj) { var size = 0, key; for (key in obj) { if (obj.hasOwnProperty(key)) size++; } return size; }; /** HARDCODED */ //Check OS -> serve the right download link function seteraDownload() { if (navigator.userAgent.indexOf('Mac OS X') != -1) { myhref('https://apps.apple.com/de/app/bria-enterprise/id523269027'); } else { myhref( 'https://play.google.com/store/apps/details?id=com.briaccs.voip&hl=en&gl=US' ); } } //remove all child nodes function removeAllChildNodes(parent) { while (parent.firstChild) { parent.removeChild(parent.firstChild); } } //WEBRTC SECTION function checkAvailableDevices() { if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) return Promise.reject('WebRTC is not supported'); let cam = false, mic = false, spkr = false; return navigator.mediaDevices.enumerateDevices().then((deviceInfos) => { devices = deviceInfos; deviceInfos.forEach(function (d) { // console.log(d); // print device info for debugging switch (d.kind) { case 'videoinput': cam = true; break; case 'audioinput': mic = true; break; case 'audiooutput': spkr = true; break; } }); // Chrome supports 'audiooutput', Firefox and Safari do not support. if (navigator.webkitGetUserMedia === undefined) { // Not Chrome spkr = true; } if (!spkr) return Promise.reject('Missing a speaker! Please connect one and reload'); if (!mic) return Promise.reject( 'Missing a microphone! Please connect one and reload' ); return Promise.resolve(cam); }); } //Statistics function userStats(lang, customer) { //avoid counting from CM if (window.location === window.parent.location) { setTimeout(() => { const d = new Date(); let dateCollection = `${('0' + d.getDate()).slice(-2)}${( '0' + (d.getMonth() + 1) ).slice(-2)}${d.getFullYear()}`; const u = getCookie('uid'); //on first visit console.log('first visit'); if (u == '' && u != undefined) { fetch( 'https://us-central1-hotensifycloud.cloudfunctions.net/userUsage', { method: 'POST', mode: 'cors', body: JSON.stringify({ language: lang, customer: customer, uid: undefined, platform: navigator.platform, hours: d.getHours(), date: dateCollection, }), } ).then((resp) => { resp.text().then((res) => { var now = new Date(); var expire = new Date(); expire.setFullYear(now.getFullYear()); expire.setMonth(now.getMonth()); expire.setDate(now.getDate() + 1); expire.setHours(0); expire.setMinutes(0); var expires = 'expires=' + expire.toString(); document.cookie = 'uid=' + res + '; ' + expires + '; path=/'; //document.cookie = `uid=${res}`; }); }); } else { fetch( 'https://us-central1-hotensifycloud.cloudfunctions.net/userUsage', { method: 'POST', mode: 'cors', body: JSON.stringify({ language: lang, customer: customer, uid: u, platform: navigator.platform, hours: d.getHours(), date: dateCollection, }), } ); } }, 3000); } } function btnClick(lang, customer, buttonID, buttonName) { if (window.location === window.parent.location) { fetch( 'https://us-central1-hotensifycloud.cloudfunctions.net/buttonClicks', { method: 'POST', mode: 'cors', body: JSON.stringify({ languages: lang, customer: customer, buttonID: buttonID, buttonName: buttonName, }), } ); } } function showErrorMessage(text) { let alertDiv = document.createElement('div'); alertDiv.classList.add( 'alert', 'alert-danger', 'alert-dismissible', 'fade', 'show' ); alertDiv.role = 'alert'; alertDiv.textContent = text; alertDiv.style.position = 'fixed'; alertDiv.style.width = '100%'; alertDiv.style.top = '0px'; alertDiv.style.textAlign = 'center'; alertDiv.style.zIndex = '1000'; document.body.append(alertDiv); setTimeout(() => { alertDiv.remove(); }, 4000); }