$(document).ready(()=>{
const baseUrl = `http://${window.location.hostname}`;
const canVibrate = "vibrate" in navigator || "mozVibrate" in navigator;
if (canVibrate && !("vibrate" in navigator)){navigator.vibrate = navigator.mozVibrate;}
const content = $('.content');
const urlString = window.location.href;
const url = new URL(urlString);
const sid = url.searchParams.get("sid");
$.getJSON( baseUrl + "/apis/getMessages.php", {
sid: sid
}).done( (session)=> {
console.log(session);
if(session.enabled){
$.each(session.messages, (index,item)=>{
if(item.timer != session.start){
const now = Date.now() / 1000;
const timer = Date.parse(item.timer) / 1000;
const start = Date.parse(session.start) / 1000;
if(now > timer){
showCloud(item.title, [item.short_text, item.long_text], item.image, item.actions, session.messages);
} else {
const delay = (timer - now);
setTimeout( ()=>{
showCloud(item.title, [item.short_text, item.long_text], item.image, item.actions, session.messages);
},1000*delay);
}
}
});
}
});
function showCloud(title, text, img, actions, messages){
const image = img ? `