if (!("Notification" in window)) { console.log("Trình duyệt không hỗ trợ desktop notification"); } else if (Notification.permission === "granted") { console.log("Cho phép VOVLive gửi thông báo"); } // Otherwise, we need to ask the user for permission else if (Notification.permission !== "denied") { Notification.requestPermission().then(function (permission) { // If the user accepts, let's create a notification if (permission === "granted") { var notification = new Notification("Bạn đã cho phép VOVLive gửi thông báo!"); } }); } if ('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/firebase-messaging-sw.js'); }); } $(document).on("click", "#toast-container", function () { var url = $(this).attr("data-url"); if (url != '') { $(this).addClass("hidden"); $.pjax({ url: url, fragment: '#main', container: '#main' }); } return false; }); $(document).on("click", "#toast-container .toast-close-button", function () { $("#toast-container").addClass("hidden"); return false; }); function loadUI() { var title = $("#hdfTitle").val(); var channel = $("#hdfChannel").val(); $("#dp_box_audio .c-audio-box").addClass("is-on-top"); //check box display var boxChk = $("#hdfLiveBoxDisplay").val(); if (boxChk == "1") { $("#boxLive").css("display", "block"); $("#boxFile").css("display", "none"); $("#boxLive .c-audio-box__name").html(title); } else { $("#boxLive").css("display", "none"); $("#boxFile").css("display", "block"); $("#boxFile .c-audio-box__name").html(title); $("#boxFile .c-audio-box__desc").html(channel); } //set volume live player $("#boxLive .volume-bar").val($("#hdfVolumeLive").val()); $("#boxFile .volume-bar").val($("#hdfFileVolume").val()); //check state live player var liveState = $("#hdfStateLive").val(); if (liveState == "1") { $("#boxLive .is-play").css("display", "none"); $("#boxLive .is-pause").css("display", "block"); } else { $("#boxLive .is-play").css("display", "block"); $("#boxLive .is-pause").css("display", "none"); } //check live speed var p = $("#hdfPlaybackRateLive").val(); if (p == "10") { $("#boxLive .is-1x").css("display", "block"); $("#boxLive .is-15x").css("display", "none"); $("#boxLive .is-2x").css("display", "none"); } else if (p == "15") { $("#boxLive .is-1x").css("display", "none"); $("#boxLive .is-15x").css("display", "block"); $("#boxLive .is-2x").css("display", "none"); } else { $("#boxLive .is-1x").css("display", "none"); $("#boxLive .is-15x").css("display", "none"); $("#boxLive .is-2x").css("display", "block"); } //check file state var fileState = $("#hdfFileState").val(); if (fileState == "1") { $("#boxFile .is-play").css("display", "none"); $("#boxFile .is-pause").css("display", "block"); } else { $("#boxFile .is-play").css("display", "block"); $("#boxFile .is-pause").css("display", "none"); } //check file speed var fs = $("#hdfFileSpeed").val(); if (fs == "10") { $("#boxFile .is-1x").css("display", "block"); $("#boxFile .is-15x").css("display", "none"); $("#boxFile .is-2x").css("display", "none"); } else if (fs == "15") { $("#boxFile .is-1x").css("display", "none"); $("#boxFile .is-15x").css("display", "block"); $("#boxFile .is-2x").css("display", "none"); } else { $("#boxFile .is-1x").css("display", "none"); $("#boxFile .is-15x").css("display", "none"); $("#boxFile .is-2x").css("display", "block"); } //set file duration $("#file-duration").text($("#hdfFileDuration").val()); datepickerLoad(); } function getTimeString(second) { var ms = ""; var m = Math.floor(second / 60); if (m < 10) { ms = "0" + m.toString(); } else { ms = m.toString(); } var ss = ""; var sc = Math.floor(second % 60); if (sc < 10) { ss = "0" + sc.toString(); } else { ss = sc.toString();; } return ms + ":" + ss; } var appStr = window.location.href.includes("/app/") if (!appStr) { //var MD5 = function (d) { var r = M(V(Y(X(d), 8 * d.length))); return r.toLowerCase() }; function M(d) { for (var _, m = "0123456789ABCDEF", f = "", r = 0; r < d.length; r++)_ = d.charCodeAt(r), f += m.charAt(_ >>> 4 & 15) + m.charAt(15 & _); return f } function X(d) { for (var _ = Array(d.length >> 2), m = 0; m < _.length; m++)_[m] = 0; for (m = 0; m < 8 * d.length; m += 8)_[m >> 5] |= (255 & d.charCodeAt(m / 8)) << m % 32; return _ } function V(d) { for (var _ = "", m = 0; m < 32 * d.length; m += 8)_ += String.fromCharCode(d[m >> 5] >>> m % 32 & 255); return _ } function Y(d, _) { d[_ >> 5] |= 128 << _ % 32, d[14 + (_ + 64 >>> 9 << 4)] = _; for (var m = 1732584193, f = -271733879, r = -1732584194, i = 271733878, n = 0; n < d.length; n += 16) { var h = m, t = f, g = r, e = i; f = md5_ii(f = md5_ii(f = md5_ii(f = md5_ii(f = md5_hh(f = md5_hh(f = md5_hh(f = md5_hh(f = md5_gg(f = md5_gg(f = md5_gg(f = md5_gg(f = md5_ff(f = md5_ff(f = md5_ff(f = md5_ff(f, r = md5_ff(r, i = md5_ff(i, m = md5_ff(m, f, r, i, d[n + 0], 7, -680876936), f, r, d[n + 1], 12, -389564586), m, f, d[n + 2], 17, 606105819), i, m, d[n + 3], 22, -1044525330), r = md5_ff(r, i = md5_ff(i, m = md5_ff(m, f, r, i, d[n + 4], 7, -176418897), f, r, d[n + 5], 12, 1200080426), m, f, d[n + 6], 17, -1473231341), i, m, d[n + 7], 22, -45705983), r = md5_ff(r, i = md5_ff(i, m = md5_ff(m, f, r, i, d[n + 8], 7, 1770035416), f, r, d[n + 9], 12, -1958414417), m, f, d[n + 10], 17, -42063), i, m, d[n + 11], 22, -1990404162), r = md5_ff(r, i = md5_ff(i, m = md5_ff(m, f, r, i, d[n + 12], 7, 1804603682), f, r, d[n + 13], 12, -40341101), m, f, d[n + 14], 17, -1502002290), i, m, d[n + 15], 22, 1236535329), r = md5_gg(r, i = md5_gg(i, m = md5_gg(m, f, r, i, d[n + 1], 5, -165796510), f, r, d[n + 6], 9, -1069501632), m, f, d[n + 11], 14, 643717713), i, m, d[n + 0], 20, -373897302), r = md5_gg(r, i = md5_gg(i, m = md5_gg(m, f, r, i, d[n + 5], 5, -701558691), f, r, d[n + 10], 9, 38016083), m, f, d[n + 15], 14, -660478335), i, m, d[n + 4], 20, -405537848), r = md5_gg(r, i = md5_gg(i, m = md5_gg(m, f, r, i, d[n + 9], 5, 568446438), f, r, d[n + 14], 9, -1019803690), m, f, d[n + 3], 14, -187363961), i, m, d[n + 8], 20, 1163531501), r = md5_gg(r, i = md5_gg(i, m = md5_gg(m, f, r, i, d[n + 13], 5, -1444681467), f, r, d[n + 2], 9, -51403784), m, f, d[n + 7], 14, 1735328473), i, m, d[n + 12], 20, -1926607734), r = md5_hh(r, i = md5_hh(i, m = md5_hh(m, f, r, i, d[n + 5], 4, -378558), f, r, d[n + 8], 11, -2022574463), m, f, d[n + 11], 16, 1839030562), i, m, d[n + 14], 23, -35309556), r = md5_hh(r, i = md5_hh(i, m = md5_hh(m, f, r, i, d[n + 1], 4, -1530992060), f, r, d[n + 4], 11, 1272893353), m, f, d[n + 7], 16, -155497632), i, m, d[n + 10], 23, -1094730640), r = md5_hh(r, i = md5_hh(i, m = md5_hh(m, f, r, i, d[n + 13], 4, 681279174), f, r, d[n + 0], 11, -358537222), m, f, d[n + 3], 16, -722521979), i, m, d[n + 6], 23, 76029189), r = md5_hh(r, i = md5_hh(i, m = md5_hh(m, f, r, i, d[n + 9], 4, -640364487), f, r, d[n + 12], 11, -421815835), m, f, d[n + 15], 16, 530742520), i, m, d[n + 2], 23, -995338651), r = md5_ii(r, i = md5_ii(i, m = md5_ii(m, f, r, i, d[n + 0], 6, -198630844), f, r, d[n + 7], 10, 1126891415), m, f, d[n + 14], 15, -1416354905), i, m, d[n + 5], 21, -57434055), r = md5_ii(r, i = md5_ii(i, m = md5_ii(m, f, r, i, d[n + 12], 6, 1700485571), f, r, d[n + 3], 10, -1894986606), m, f, d[n + 10], 15, -1051523), i, m, d[n + 1], 21, -2054922799), r = md5_ii(r, i = md5_ii(i, m = md5_ii(m, f, r, i, d[n + 8], 6, 1873313359), f, r, d[n + 15], 10, -30611744), m, f, d[n + 6], 15, -1560198380), i, m, d[n + 13], 21, 1309151649), r = md5_ii(r, i = md5_ii(i, m = md5_ii(m, f, r, i, d[n + 4], 6, -145523070), f, r, d[n + 11], 10, -1120210379), m, f, d[n + 2], 15, 718787259), i, m, d[n + 9], 21, -343485551), m = safe_add(m, h), f = safe_add(f, t), r = safe_add(r, g), i = safe_add(i, e) } return Array(m, f, r, i) } function md5_cmn(d, _, m, f, r, i) { return safe_add(bit_rol(safe_add(safe_add(_, d), safe_add(f, i)), r), m) } function md5_ff(d, _, m, f, r, i, n) { return md5_cmn(_ & m | ~_ & f, d, _, r, i, n) } function md5_gg(d, _, m, f, r, i, n) { return md5_cmn(_ & f | m & ~f, d, _, r, i, n) } function md5_hh(d, _, m, f, r, i, n) { return md5_cmn(_ ^ m ^ f, d, _, r, i, n) } function md5_ii(d, _, m, f, r, i, n) { return md5_cmn(m ^ (_ | ~f), d, _, r, i, n) } function safe_add(d, _) { var m = (65535 & d) + (65535 & _); return (d >> 16) + (_ >> 16) + (m >> 16) << 16 | 65535 & m } function bit_rol(d, _) { return d << _ | d >>> 32 - _ } //var ts = Math.round((new Date()).getTime() / 1000) + 3600; //var token = MD5(":vovlivestream:" + ts + ":/vovlive/vov1vov5Vietnamese.sdp_aac").toString(); //var vov1 = "https://stream.vovlive.vn/" + token + ts + "/vovlive/vov1vov5Vietnamese.sdp_aac/playlist.m3u8"; var vov1 = "https://str.vov.gov.vn/vovlive/vov1vov5Vietnamese.sdp_aac/playlist.m3u8"; var audioElement = videojs('liveAudio'); audioElement.src({ type: 'application/x-mpegURL', src: vov1 }); var audioFile = document.getElementById('fileAudio'); //live player event $(document).on("click", "#boxLive .is-play", function () { audioElement.play(); $("#hdfStateLive").val("1"); $(this).css("display", "none"); $("#boxLive .is-pause").css("display", "block"); }); $(document).on("click", "#boxLive .is-pause", function () { audioElement.pause(); $("#hdfStateLive").val("0"); $(this).css("display", "none"); $("#boxLive .is-play").css("display", "block"); }); $(document).on("click", ".live_link", function () { $("#hdfLiveBoxDisplay").val("1"); //ẩn box play file audioFile.setAttribute('src', ''); $("#boxLive").css("display", "block"); $("#boxFile").css("display", "none"); var link = $(this).attr("data-source"); var audioElement = videojs("liveAudio"); audioElement.src({ type: 'application/x-mpegURL', src: link }); audioElement.volume(0.5); audioElement.play(); $("#boxLive .is-play").css("display", "none"); $("#boxLive .is-pause").css("display", "block"); $("#boxLive .is-1x").css("display", "block"); $("#boxLive .is-15x").css("display", "none"); $("#boxLive .is-2x").css("display", "none"); $("#hdfStateLive").val("1"); $("#hdfPlaybackRateLive").val("10"); $("#hdfVolumeLive").val("0.5"); $("#boxLive .volume-bar").val("0.5"); var title = $(this).attr("data-title"); $("#boxLive .c-audio-box__name").html(title); $("#hdfTitle").val(title); }); $(document).on("click", "#boxLive .is-1x", function () { audioElement.playbackRate(1.5); $(this).css("display", "none"); $("#boxLive .is-15x").css("display", "block"); $("#boxLive .is-2x").css("display", "none"); $("#hdfPlaybackRateLive").val("15"); }); $(document).on("click", "#boxLive .is-15x", function () { audioElement.playbackRate(2.0); $(this).css("display", "none"); $("#boxLive .is-2x").css("display", "block"); $("#boxLive .is-1x").css("display", "none"); $("#hdfPlaybackRateLive").val("20"); }); $(document).on("click", "#boxLive .is-2x", function () { audioElement.playbackRate(1.0); $(this).css("display", "none"); $("#boxLive .is-1x").css("display", "block"); $("#boxLive .is-1.5x").css("display", "none"); $("#hdfPlaybackRateLive").val("10"); }) $(document).on("change", "#boxLive .volume-bar", function () { audioElement.volume($(this).val()); $("#hdfVolumeLive").val($(this).val()); }); //file audio event $(document).on("click", ".audio-file", function () { $("#hdfLiveBoxDisplay").val("0"); audioElement.pause(); $("#boxLive").css("display", "none"); $("#boxFile").css("display", "block"); var link = $(this).attr("data-source"); audioFile.setAttribute('src', link); audioFile.volume = 0.5; audioFile.play(); $("#hdfFileState").val("1"); $("#hdfFileSpeed").val("10"); $("#boxFile .is-1x").css("display", "block"); $("#boxFile .is-15x").css("display", "none"); $("#boxFile .is-2x").css("display", "none"); $("#boxFile .is-play").css("display", "none"); $("#boxFile .is-pause").css("display", "block"); $("#hdfFileVolume").val("0.5"); $("#boxFile .volume-bar").val("0.5"); var title = $(this).attr("data-title"); $("#boxFile .c-audio-box__name").html(title); $("#hdfTitle").val(title); var channel = $(this).attr("data-channel"); $("#boxFile .c-audio-box__desc").html(channel); $("#hdfChannel").val(channel); var track = $(this).attr("data-track"); $("#hdfTrack").val(track); var time = (new Date().getMonth() + 1).toString() + "/" + new Date().getDate().toString() + "/" + new Date().getFullYear().toString() + " " + new Date().getHours().toString() + ":" + new Date().getMinutes().toString() + ":" + new Date().getSeconds().toString(); $("#hdfFileViewCountSet").val($(this).attr("data-id") + "," + time + "," + "0"); }); audioFile.addEventListener("canplay", function () { var duration = getTimeString(audioFile.duration) $("#file-duration").text(duration); $("#hdfFileDuration").val(duration); }); audioFile.addEventListener("timeupdate", function () { $("#file-currentime").text(getTimeString(audioFile.currentTime)); var percentage = Math.floor(100 / audioFile.duration * audioFile.currentTime).toString(); var myBar = $("#myBar"); myBar.css("width", percentage + "%"); var timePlay = $("#hdfTimePlay").val(); if (timePlay == "") { $("#hdfTimePlay").val("0," + audioFile.currentTime); } else { var timeArr = timePlay.split(","); from = timeArr[0]; to = timeArr[1]; if (to == "0") { $("#hdfTimePlay").val(audioFile.currentTime + "," + audioFile.currentTime); } else { $("#hdfTimePlay").val(from + "," + audioFile.currentTime); var timeTotal = 0; var curTime = parseFloat(to) - parseFloat(from); if ($("#hdfTimeTotal").val() != "") { timeTotal = parseFloat($("#hdfTimeTotal").val()) + curTime; } else { timeTotal = curTime; } if (timeTotal > 30) { if ($("#hdfFileViewCountSet").val() != "") { var countSetArr = $("#hdfFileViewCountSet").val().split(","); if (countSetArr[2] == "0") { //lưu viewcout file, gửi lên server var device = "A"; if (isMobile()) { device = "B"; } $.get('/scriptfile/ui-' + device + countSetArr[0] + '.js'); //cập nhật trạng thái đã lưu viewcount file $("#hdfFileViewCountSet").val(countSetArr[0] + "," + countSetArr[1] + "," + "1"); } } } //console.log(timeTotal); } //console.log($("#hdfFileViewCountSet").val()); } }); audioFile.addEventListener('ended', function () { $("#hdfTimePlay").val(""); $("#hdfTimeTotal").val(""); $("#hdfFileViewCountSet").val(""); if ($("#hdfTrack").val() == "") { $("#hdfTrack").val("0"); $("#boxFile .is-pause").css("display", "none"); $("#boxFile .is-play").css("display", "block"); $("#hdfFileState").val("0"); } else { var track = parseInt($("#hdfTrack").val()); track += 1; var item = $(document).find("a[data-track=" + track.toString() + "]"); var link = item.attr("data-source"); if (link != undefined) { $("#hdfTrack").val(track.toString()); audioFile.setAttribute('src', link); audioFile.volume = 0.5; audioFile.play(); var title = item.attr("data-title"); $("#boxFile .c-audio-box__name").html(title); $("#hdfTitle").val(title); var channel = item.attr("data-channel"); $("#boxFile .c-audio-box__desc").html(channel); $("#hdfChannel").val(channel); $("#hdfFileState").val("1"); $("#hdfFileSpeed").val("10"); $("#boxFile .is-1x").css("display", "block"); $("#boxFile .is-15x").css("display", "none"); $("#boxFile .is-2x").css("display", "none"); $("#boxFile .is-play").css("display", "none"); $("#boxFile .is-pause").css("display", "block"); $("#hdfFileVolume").val("0.5"); $("#boxFile .volume-bar").val("0.5"); var time = (new Date().getMonth() + 1).toString() + "/" + new Date().getDate().toString() + "/" + new Date().getFullYear().toString() + " " + new Date().getHours().toString() + ":" + new Date().getMinutes().toString() + ":" + new Date().getSeconds().toString(); $("#hdfFileViewCountSet").val(item.attr("data-id") + "," + time + "," + "0"); } else { $("#hdfTrack").val("0"); $("#boxFile .is-pause").css("display", "none"); $("#boxFile .is-play").css("display", "block"); $("#hdfFileState").val("0"); } } }, false); $(document).on("click", "#boxFile .is-play", function () { audioFile.play(); $("#hdfFileState").val("1"); $(this).css("display", "none"); $("#boxFile .is-pause").css("display", "block"); }); $(document).on("click", "#boxFile .is-pause", function () { audioFile.pause(); $("#hdfFileState").val("0"); $(this).css("display", "none"); $("#boxFile .is-play").css("display", "block"); }); $(document).on("click", "#boxFile .is-1x", function () { audioFile.playbackRate = 1.5; $(this).css("display", "none"); $("#boxFile .is-15x").css("display", "block"); $("#boxFile .is-2x").css("display", "none"); $("#hdfFileSpeed").val("15"); }); $(document).on("click", "#boxFile .is-15x", function () { audioFile.playbackRate = 2.0; $(this).css("display", "none"); $("#boxFile .is-2x").css("display", "block"); $("#boxFile .is-1x").css("display", "none"); $("#hdfFileSpeed").val("20"); }); $(document).on("click", "#boxFile .is-2x", function () { audioFile.playbackRate = 1.0; $(this).css("display", "none"); $("#boxFile .is-1x").css("display", "block"); $("#boxFile .is-1.5x").css("display", "none"); $("#hdfFileSpeed").val("10"); }); $(document).on("change", "#boxFile .volume-bar", function () { audioFile.volume = $(this).val(); $("#hdfFileVolume").val($(this).val()); }); $(document).on("click", "#myProgress", function () { var x = event.clientX; var position = $(this).offset().left; var cur = x - position; var percentage = (100 / $(this).width() * cur); var myBar = $("#myBar"); myBar.css("width", percentage.toString() + "%"); var curTime; var totalTime = audioFile.duration; curTime = percentage * totalTime / 100; audioFile.currentTime = curTime; var timeTotal = 0; if ($("#hdfTimeTotal").val() != "") { timeTotal = parseFloat($("#hdfTimeTotal").val()); } var countTime = 0; if ($("#hdfTimePlay").val() != "") { var curTime = $("#hdfTimePlay").val().split(","); countTime = parseFloat(curTime[1]) - parseFloat(curTime[0]); $("#hdfTimePlay").val("0,0"); } timeTotal += countTime; $("#hdfTimeTotal").val(timeTotal.toString()); console.log($("#hdfTimePlay").val()); console.log($("#hdfTimeTotal").val()); }); $(document).on("click", "#back15", function () { audioFile.currentTime = audioFile.currentTime - 15; }); $(document).on("click", "#playAlbum", function () { var item = $(document).find("a[data-track=1]"); var link = item.attr("data-source"); if (link != undefined) { $("#hdfLiveBoxDisplay").val("0"); audioElement.pause(); $("#boxLive").css("display", "none"); $("#boxFile").css("display", "block"); $("#hdfTrack").val("1"); audioFile.setAttribute('src', link); audioFile.volume = 0.5; audioFile.play(); var title = item.attr("data-title"); $("#boxFile .c-audio-box__name").html(title); $("#hdfTitle").val(title); var channel = item.attr("data-channel"); $("#boxFile .c-audio-box__desc").html(channel); $("#hdfChannel").val(channel); $("#hdfFileState").val("1"); $("#hdfFileSpeed").val("10"); $("#boxFile .is-1x").css("display", "block"); $("#boxFile .is-15x").css("display", "none"); $("#boxFile .is-2x").css("display", "none"); $("#boxFile .is-play").css("display", "none"); $("#boxFile .is-pause").css("display", "block"); $("#hdfFileVolume").val("0.5"); $("#boxFile .volume-bar").val("0.5"); var time = (new Date().getMonth() + 1).toString() + "/" + new Date().getDate().toString() + "/" + new Date().getFullYear().toString() + " " + new Date().getHours().toString() + ":" + new Date().getMinutes().toString() + ":" + new Date().getSeconds().toString(); $("#hdfFileViewCountSet").val(item.attr("data-id") + "," + time + "," + "0"); } }); } (function () { //console.log('Start file login with firebase'); // Initialize Firebase var firebaseConfig = { apiKey: "AIzaSyBzyMvNkqxckpYdujb637YTDNA7q3JYi_I", authDomain: "vovlive-b37c3.firebaseapp.com", databaseURL: "https://vovlive-b37c3.firebaseio.com", projectId: "vovlive-b37c3", storageBucket: "vovlive-b37c3.appspot.com", messagingSenderId: "218035704514", appId: "1:218035704514:web:dd81fe376b4426d4be215b" }; // Initialize Firebase firebase.initializeApp(firebaseConfig); firebase.auth().languageCode = 'vi'; //Google singin provider var ggProvider = new firebase.auth.GoogleAuthProvider(); //Facebook singin provider var fbProvider = new firebase.auth.FacebookAuthProvider(); fbProvider.addScope('email'); //Login in variables const btnGoogle = document.getElementById('btnGoogle'); const btnFaceBook = document.getElementById('btnFacebook'); //Sing in with Google btnGoogle.addEventListener('click', e => { firebase.auth().signInWithPopup(ggProvider).then(function (result) { var ggToken = result.credential.idToken; window.localStorage.setItem("ggToken", ggToken); window.localStorage.setItem("loginType", "1"); var user = result.user; //console.log(user); $("#modalLogin").modal("hide"); $(".logedin").removeClass("hidden"); $(".logedout").addClass("hidden"); $("#m_userPodcast").removeClass("hidden"); $("#m_logout").removeClass("hidden"); firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function (idToken) { //console.log(idToken); window.localStorage.setItem("idToken", idToken); messaging.getToken().then((currentToken) => { window.localStorage.setItem("TokenPush", currentToken); console.log(currentToken); $.ajax({ url: "/api/userAuthen", type: "post", data: { idToken: idToken, type: 1, TokenPush: currentToken, OSType: 'web' }, success: function (data) { if (data.result_code == 0) { console.log("Đăng nhập google: Xác thực idToken thành công!"); window.localStorage.setItem("userId", data.result_detail); window.localStorage.setItem("userEmail", data.result_email); var chk = $("#BoxFollow").attr("class"); if (chk != undefined) { userAlbumList(); } } else { console.log(data); } }, }); }); }).catch(function (error) { console.error('Error idToken: hande error here>>>', error.code) }); }).catch(function (error) { console.error('Error auth: hande error here>>>', error.code) }) }, false) //Sing in with Facebook btnFaceBook.addEventListener('click', e => { firebase.auth().signInWithPopup(fbProvider).then(function (result) { var ggToken = result.credential.idToken; window.localStorage.setItem("ggToken", ggToken); window.localStorage.setItem("loginType", "2"); var user = result.user; //console.log(user); $("#modalLogin").modal("hide"); $(".logedin").removeClass("hidden"); $(".logedout").addClass("hidden"); $("#m_userPodcast").removeClass("hidden"); $("#m_logout").removeClass("hidden"); //var idToken = result.user.u.src.xa; firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function (idToken) { window.localStorage.setItem("idToken", idToken); messaging.getToken().then((currentToken) => { window.localStorage.setItem("TokenPush", currentToken); console.log(currentToken); $.ajax({ url: "/api/userAuthen", type: "post", data: { idToken: idToken, type: 2, TokenPush: currentToken, OSType: 'web' }, success: function (data) { if (data.result_code == 0) { console.log("Đăng nhập facebook: Xác thực idToken thành công!"); window.localStorage.setItem("userId", data.result_detail); window.localStorage.setItem("userEmail", data.result_email); var chk = $("#BoxFollow").attr("class"); if (chk != undefined) { userAlbumList(); } } else { console.log(data); } }, }); }); }).catch(function (error) { console.error('Error idToken: hande error here>>>', error.code) }); }).catch(function (error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; // The email of the user's account used. var email = error.email; // The firebase.auth.AuthCredential type that was used. var credential = error.credential; // ... console.error('Error auth: hande error here>Facebook>>', error.code) }); }, false) //jquery $(document).on("click", "#logout", function () { LogOut() }); $(document).on("click", "#m_logout > a", function () { LogOut() }); $(document).on("click", "#followAlbum", function () { var userId = window.localStorage.getItem("userId"); if (userId != null) { var albumId = $("#playAlbum").attr("data-album"); $.ajax({ url: "/api/loadfrontendusermapping", type: "post", data: { Email: window.localStorage.getItem("userEmail"), UserId: userId, Reference: 'MediaAlbum', ReferenceId: albumId }, success: function (data) { var rsCode = data.result_detail; if (rsCode == 1) { $("#followAlbum").html("Bỏ Theo dõi"); } else { $("#followAlbum").html("Theo dõi"); } }, }); } else { $("#modalLogin").modal("show"); } }); }()) function SetFormLogedIn(user) { var displayName = user.displayName var photoURL = user.photoURL; $(".logedin").removeClass("hidden"); $(".logedout").addClass("hidden"); $("#m_userPodcast").removeClass("hidden"); $("#m_logout").removeClass("hidden"); $("#dropdownUser > img").attr("src", photoURL); $(".c-mobile-user__avatar > img").attr("src", photoURL); $(".c-mobile-user__name").html(displayName); var albumId = $("#playAlbum").attr("data-album"); if (albumId != undefined) { $.ajax({ url: "/api/getfrontendusermapping", type: "post", data: { Email: window.localStorage.getItem("userEmail"), UserId: window.localStorage.getItem("userId"), Reference: 'MediaAlbum', ReferenceId: albumId }, success: function (data) { var id = data.result_detail; if (id > 0) { $("#followAlbum").html("Bỏ Theo dõi"); } else { $("#followAlbum").html("Theo dõi"); } }, }); } } function SetFormLogedOut() { window.localStorage.removeItem('ggToken'); window.localStorage.removeItem('idToken'); window.localStorage.removeItem('loginType'); window.localStorage.removeItem('userId'); $(".logedin").addClass("hidden"); $(".logedout").removeClass("hidden"); $("#m_logout").addClass("hidden"); $("#m_userPodcast").addClass("hidden"); $("#dropdownUser > img").attr("src", "https://vovlive.vn/Assets/images/icons/icon50-user.png"); $(".c-mobile-user__avatar > img").attr("src", "https://vovlive.vn/Assets/images/icons/icon50-user.png"); $(".c-mobile-user__name").html("Đăng nhập"); $("#BoxFollow").html(""); $("#NoRs").text("Vui lòng đăng nhập để xem danh sách album yêu thích!"); $("#followAlbum").html("Theo dõi"); } function SetLoginUser(user) { if (user) { var idToken = window.localStorage.getItem("idToken"); if (idToken != null) { var type = window.localStorage.getItem("loginType"); var TokenPush = window.localStorage.getItem("TokenPush"); if (TokenPush == null) { messaging.getToken().then((currentToken) => { window.localStorage.setItem("TokenPush", currentToken); console.log(currentToken); $.ajax({ url: "/api/userAuthen", type: "post", data: { idToken: idToken, type: type, TokenPush: currentToken, OSType: 'web' }, success: function (data) { if (data.result_code == 0) { SetFormLogedIn(user); } else if (data.result_code == 2) { var ggToken = window.localStorage.getItem("ggToken"); if (ggToken != null) { //var credential = firebase.auth.GoogleAuthProvider.credential(ggToken); //firebase.auth().signInWithCredential(credential).catch(function (error) { // console.log(error); //}); firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function (idToken) { window.localStorage.setItem("idToken", idToken); $.ajax({ url: "/api/userAuthen", type: "post", data: { idToken: idToken, type: type, TokenPush: currentToken, OSType: 'web' }, success: function (data) { if (data.result_code == 0) { console.log("Refresh idToken: Xác thực idToken thành công!"); window.localStorage.setItem("userId", data.result_detail); SetFormLogedIn(user); } else { console.log(data); } }, }); }).catch(function (error) { console.error('Error idToken: hande error here>>>', error.code) }); } else { SetFormLogedOut(); console.log("idToken hết hạn"); } } else if (data.result_code == 3) { SetFormLogedOut(); console.log("idToken không hợp lệ"); } }, }); }); } else { $.ajax({ url: "/api/userAuthen", type: "post", data: { idToken: idToken, type: type }, success: function (data) { if (data.result_code == 0) { SetFormLogedIn(user); } else if (data.result_code == 2) { var ggToken = window.localStorage.getItem("ggToken"); if (ggToken != null) { //var credential = firebase.auth.GoogleAuthProvider.credential(ggToken); //firebase.auth().signInWithCredential(credential).catch(function (error) { // console.log(error); //}); firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function (idToken) { window.localStorage.setItem("idToken", idToken); var currentToken = window.localStorage.getItem("TokenPush"); $.ajax({ url: "/api/userAuthen", type: "post", data: { idToken: idToken, type: type, TokenPush: currentToken, OSType: 'web' }, success: function (data) { if (data.result_code == 0) { console.log("Refresh idToken: Xác thực idToken thành công!"); window.localStorage.setItem("userId", data.result_detail); SetFormLogedIn(user); } else { console.log(data); } }, }); }).catch(function (error) { console.error('Error idToken: hande error here>>>', error) }); } else { SetFormLogedOut(); console.log("idToken hết hạn"); } } else if (data.result_code == 3) { SetFormLogedOut(); console.log("idToken không hợp lệ"); } }, }); } } else { SetFormLogedIn(user); } } else { SetFormLogedOut(); } } function userAlbumList() { var userId = window.localStorage.getItem("userId"); if (userId != null) { $.ajax({ url: "/api/userAlbumList", type: "post", data: { Email: window.localStorage.getItem("userEmail"), userId: userId }, success: function (data) { if (data.length > 0) { var s = ""; for (var i = 0; i < data.length; i++) { s += "
  • "; s += "
    \"image\"
    "; s += "
    "; s += ""; s += "
  • "; } $("#BoxFollow").html(s); $("#NoRs").text(""); } else { $("#NoRs").text("Chưa có Playlist yêu thích!"); } }, }); } else { $("#NoRs").text("Vui lòng đăng nhập để xem danh sách album yêu thích!"); } } function LogOut() { firebase.auth().signOut().then(function () { messaging.getToken().then((currentToken) => { messaging.deleteToken(currentToken).then(() => { console.log('Token deleted: ' + currentToken); //api delete token on server $.ajax({ url: "/api/deleteTokenPush", type: "post", data: { TokenPush: currentToken, DeviceId: '', OSType: 'web' }, success: function (data) { window.localStorage.removeItem("TokenPush"); console.log(data); }, }); }).catch((err) => { console.log('Unable to delete token. ', err); }); // [END delete_token] }).catch((err) => { console.log('Error retrieving Instance ID token. ', err); }); SetFormLogedOut(); }).catch(function (error) { console.error('Error: hande error here>>>', error.code) }); } function decode64(input) { var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/" + "="; var output = ""; var chr1, chr2, chr3 = ""; var enc1, enc2, enc3, enc4 = ""; var i = 0; var base64test = /[^A-Za-z0-9\+\/\=]/g; if (base64test.exec(input)) { alert("There were invalid base64 characters in the input text.\n" + "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" + "Expect errors in decoding."); } input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); do { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } chr1 = chr2 = chr3 = ""; enc1 = enc2 = enc3 = enc4 = ""; } while (i < input.length); return unescape(output); } function RunLichPhatSong1(title, link) { $("#hdfLiveBoxDisplay").val("1"); //ẩn box play file audioFile.setAttribute('src', ''); $("#boxLive").css("display", "block"); $("#boxFile").css("display", "none"); var audioElement = videojs("liveAudio"); audioElement.src({ type: 'application/x-mpegURL', src: link }); audioElement.volume(0.5); audioElement.play(); $("#boxLive .is-play").css("display", "none"); $("#boxLive .is-pause").css("display", "block"); $("#boxLive .is-1x").css("display", "block"); $("#boxLive .is-15x").css("display", "none"); $("#boxLive .is-2x").css("display", "none"); $("#hdfStateLive").val("1"); $("#hdfPlaybackRateLive").val("10"); $("#hdfVolumeLive").val("0.5"); $("#boxLive .volume-bar").val("0.5"); $("#boxLive .c-audio-box__name").html(title); $("#hdfTitle").val(title); } function RunLichPhatSong(link, name) { $("#hdfLiveBoxDisplay").val("0"); audioElement.pause(); $("#boxLive").css("display", "none"); $("#boxFile").css("display", "block"); audioFile.setAttribute('src', link); audioFile.volume = 0.5; audioFile.play(); $("#hdfFileState").val("1"); $("#hdfFileSpeed").val("10"); $("#boxFile .is-1x").css("display", "block"); $("#boxFile .is-15x").css("display", "none"); $("#boxFile .is-2x").css("display", "none"); $("#boxFile .is-play").css("display", "none"); $("#boxFile .is-pause").css("display", "block"); $("#hdfFileVolume").val("0.5"); $("#boxFile .volume-bar").val("0.5"); var title = name; $("#boxFile .c-audio-box__name").html(title); $("#hdfTitle").val(title); var channel = "VOV1"; $("#boxFile .c-audio-box__desc").html(channel); $("#hdfChannel").val(channel); } $(document).on("change", "#ddlVov", function () { GetVovSchedule(); }); $(document).on("change", "#txtDateSchedule", function () { if ($("#txtDateSchedule").val() == "") { var strDay = ""; var strMonth = ""; var day = new Date().getDate(); var month = new Date().getMonth() + 1; var strCurDate = ""; if (day < 10) { strDay = "0" + day.toString(); } else { strDay = day.toString(); } if (month < 10) { strMonth = "0" + month.toString(); } else { strMonth = month.toString(); } strCurDate = strDay + "/" + strMonth + "/" + new Date().getFullYear().toString(); $("#txtDateSchedule").val(strCurDate); } GetVovSchedule(); }); function GetVovSchedule() { $.ajax({ url: "/api/getvovschedule", type: "post", data: { vov: $("#ddlVov").val(), date: $("#txtDateSchedule").val() }, success: function (data) { //console.log(data.strKey); $("#vovSchedule").html(data.result_detail); //$("#vovSchedule img").remove(); }, }); } $(document).on("click", "#alfLoadMore", function () { var albumId = $("#hdfAlbumId").val(); var lastId = $(".alfAjax ul li:last-child").attr("data-id"); var albumName = $("h1.b-grid__title").text(); $.ajax({ url: "/api/mediaAlbumFilePaging", type: "post", data: { AlbumId: albumId, LastMediaAlbumFileId: lastId }, success: function (data) { if (data.length <= 15) { $("#alfLoadMore").addClass("hidden"); } var s = ""; for (var i = 0; i < data.length; i++) { var date = new Date(parseInt(data[0].PublishedTime.toString().replace("/Date(", "").replace(")/", ""))).toLocaleDateString("vi-VN"); s += "
  • "; s += "
    "; s += "
    "; s += "
    "; s += ""; s += "
    " + date + ""; s += "" + getTimeString(data[i].Length) + ""; s += "
    "; s += ""; s += ""; s += ""; s += "
    "; s += "
    " + data[i].Content + "
  • "; } $(".alfAjax ul").append(s); }, }); }); $(document).on("click", "#alfLoadMore1", function () { var albumId = $("#hdfAlbumId").val(); var lastId = $(".alfAjax ul li:last-child").attr("data-id"); var fileId = $("#hdfFileId").val(); $.ajax({ url: "/api/mediaAlbumFilePaging", type: "post", data: { AlbumId: albumId, LastMediaAlbumFileId: lastId }, success: function (data) { data = data.filter(o => o.FileId != fileId); if (data.length <= 14) { $("#alfLoadMore1").addClass("hidden"); } var s = ""; for (var i = 0; i < data.length; i++) { var date = new Date(parseInt(data[0].PublishedTime.toString().replace("/Date(", "").replace(")/", ""))).toLocaleDateString("vi-VN"); s += "
  • "; s += "
    "; s += ""; s += "
    " + date + ""; s += "" + getTimeString(data[i].Length) + "
    "; s += "
    " + data[i].Content + "
  • "; } $(".alfAjax ul").append(s); }, }); }); $(document).on("click", "#albumLoadMore", function () { var channelId = $("#hdfChannelId").val(); var lastId = $(".alAjax ul li:last-child").attr("data-id"); $.ajax({ url: "/api/mediaAlbumPaging", type: "post", data: { AlbumId: lastId, ChannelId: channelId }, success: function (data) { if (data.length <= 16) { $("#albumLoadMore").addClass("hidden"); } //console.log(data); var s = ""; var count = 0; if (data.length < 17) { count = data.length; } else { count = data.length - 1 } for (var i = 0; i < count; i++) { s += "
  • "; s += "
    "; s += "
    \"@item.Title\"
    "; s += "
    "; s += ""; s += "
  • "; } $(".alAjax ul").append(s); }, }); }); $(document).on("click", ".c-search-podcast .btnSearch", function () { var keyword = $('#txtPodcastKeyword').val(); if ($.trim(keyword) != '') { $.pjax({ url: '/media/search?q=' + keyword.replace(/\s/gi, "+"), fragment: '#main', container: '#main' }); } return false; }); $(document).on("keyup", ".c-search-podcast #txtPodcastKeyword", function (evt) { if (evt.keyCode == 13 || evt.which == 13) { $('.btnSearch').trigger('click'); return false; } return true; }); $(document).on("click", ".searchMediaPaging", function () { var keyword = $(this).attr("data-keyword"); var type = $(this).attr("data-type") var lastId = $(".pAjax li:last-child").attr("data-id"); $.ajax({ url: "/api/searchPodcastPaging", type: "post", data: { keyword: keyword, type: type, lastId: lastId }, success: function (data) { if (data.length <= 12) { $(".searchMediaPaging").addClass("hidden"); } var s = ""; var count = 0; if (data.length < 13) { count = data.length; } else { count = data.length - 1 } for (var i = 0; i < count; i++) { s += "
  • "; s += "
    "; s += "
    \"@item.Title\"
    "; s += "
    "; s += ""; s += "
  • "; } $(".pAjax").append(s); }, }); }); $(document).on("click", ".searchFilePaging", function () { var keyword = $(this).attr("data-keyword"); var lastId = $(".fAjax li:last-child").attr("data-id"); $.ajax({ url: "/api/searchFilePaging", type: "post", data: { keyword: keyword, lastId: lastId }, success: function (data) { if (data.length <= 10) { $(".searchFilePaging").addClass("hidden"); } //console.log(data); var s = ""; var count = 0; if (data.length < 11) { count = data.length; } else { count = data.length - 1 } for (var i = 0; i < data.length; i++) { var s = ""; for (var i = 0; i < data.length; i++) { var date = new Date(parseInt(data[0].PublishedTime.toString().replace("/Date(", "").replace(")/", ""))).toLocaleDateString("vi-VN"); s += "
  • "; s += "
    "; s += "
    "; s += "
    "; s += ""; s += "
    " + date + ""; s += "" + getTimeString(data[i].Length) + ""; s += "
    "; s += ""; s += ""; s += ""; s += "
    "; s += "
  • "; } } $(".fAjax").append(s); }, }); }); const messaging = firebase.messaging(); messaging.onMessage((payload) => { console.log('Message received. ', payload); var data = payload.data; var notification = payload.notification; console.log(data); console.log(data['url']); $("#toast-container").removeClass("hidden"); $("#toast-container").attr("data-url", data['url']); $("#toast-container .toast-title").html(notification['title']); $("#toast-container .toast-message").html(notification['body']); setTimeout(function () { $("#toast-container").addClass("hidden"); }, 5000); }); messaging.onTokenRefresh(() => { messaging.getToken().then((refreshedToken) => { var oldTokenPush = window.localStorage.getItem("TokenPush"); //api send ollToken, newToken to server $.ajax({ url: "/api/insertTokenRefresh", type: "post", data: { OldTokenPush: oldTokenPush, TokenRefresh: refreshedToken, DeviceId: '', OSType: 'web' }, success: function (data) { window.localStorage.setItem("TokenPush", refreshedToken); console.log(data); }, }); }).catch((err) => { console.log('Unable to retrieve refreshed token ', err); showToken('Unable to retrieve refreshed token ', err); }); });